OKlibrary  0.2.1.6
KeySchedule.mac
Go to the documentation of this file.
00001 /* Oliver Kullmann, 20.3.2011 (Swansea) */
00002 /* Copyright 2011 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00022 oklib_include("OKlib/ComputerAlgebra/DataStructures/Lisp/Lists.mac")$
00023 oklib_include("OKlib/ComputerAlgebra/DataStructures/Lisp/HashMaps.mac")$
00024 
00025 des_key_initial_selection : [
00026 57,49,41,33,25,17,9,1,58,50,42,34,26,18,
00027 10,2,59,51,43,35,27,19,11,3,60,52,44,36,
00028 63,55,47,39,31,23,15,7,62,54,46,38,30,22,
00029 14,6,61,53,45,37,29,21,13,5,28,20,12,4]$
00030 
00031 des_key_left_shifts : [
00032 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1]$
00033 
00034 des_key_compression : [
00035 14,17,11,24,1,5,3,28,15,6,21,10,
00036 23,19,12,4,26,8,16,7,27,20,13,2,
00037 41,52,31,37,47,55,30,40,51,45,33,48,
00038 44,49,39,56,34,53,46,42,50,36,29,32]$
00039 
00040 /* Produces a list of 16 boolean vectors of length 48, containing the indices
00041    of the bits in the original key to be used in the 16 rounds:
00042 */
00043 des_round_keys_template() := block(
00044  [key1 : take_l(28,des_key_initial_selection),
00045   key2 : rest(des_key_initial_selection,28),
00046   keylist : []],
00047   for s in des_key_left_shifts do block([key],
00048     key1 : rotate(key1,-s), key2 : rotate(key2,-s),
00049     key : append(key1,key2),
00050     key : map(lambda([x],key[x]), des_key_compression),
00051     keylist : cons(key, keylist)
00052   ),
00053   reverse(keylist))$
00054 
00055 /* key is a boolean vector of length 64: */
00056 des_round_keys(key) := block([keya : il2ary(key)],
00057  map(lambda([K], map(lambda([x],keya[x]), K)), des_round_keys_template()))$
00058