OKlibrary  0.2.1.6
KeySchedule.mac
Go to the documentation of this file.
00001 /* Matthew Gwynne, 25.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/TestSystem/Lisp/Asserts.mac")$
00023 oklib_include("OKlib/ComputerAlgebra/Cryptology/Lisp/CryptoSystems/DataEncryptionStandard/Cipher.mac")$
00024 oklib_include("OKlib/ComputerAlgebra/NumberTheory/Lisp/Auxiliary.mac")$
00025 
00026 kill(f)$
00027 
00028 okltest_des_round_keys_template(f) := (
00029   assert(f() =
00030     [[10,51,34,60,49,17,33,57,2,9,19,42,3,35,26,25,44,58,59,1,36,27,18,
00031       41,22,28,39,54,37,4,47,30,5,53,23,29,61,21,38,63,15,20,45,14,13,
00032       62,55,31],
00033      [2,43,26,52,41,9,25,49,59,1,11,34,60,27,18,17,36,50,51,58,57,19,
00034       10,33,14,20,31,46,29,63,39,22,28,45,15,21,53,13,30,55,7,12,37,6,
00035       5,54,47,23],
00036      [51,27,10,36,25,58,9,33,43,50,60,18,44,11,2,1,49,34,35,42,41,3,59,
00037       17,61,4,15,30,13,47,23,6,12,29,62,5,37,28,14,39,54,63,21,53,20,
00038       38,31,7],
00039      [35,11,59,49,9,42,58,17,27,34,44,2,57,60,51,50,33,18,19,26,25,52,
00040       43,1,45,55,62,14,28,31,7,53,63,13,46,20,21,12,61,23,38,47,5,37,
00041       4,22,15,54],
00042      [19,60,43,33,58,26,42,1,11,18,57,51,41,44,35,34,17,2,3,10,9,36,
00043       27,50,29,39,46,61,12,15,54,37,47,28,30,4,5,63,45,7,22,31,20,21,
00044       55,6,62,38],
00045      [3,44,27,17,42,10,26,50,60,2,41,35,25,57,19,18,1,51,52,59,58,49,
00046       11,34,13,23,30,45,63,62,38,21,31,12,14,55,20,47,29,54,6,15,4,5,
00047       39,53,46,22],
00048      [52,57,11,1,26,59,10,34,44,51,25,19,9,41,3,2,50,35,36,43,42,33,
00049       60,18,28,7,14,29,47,46,22,5,15,63,61,39,4,31,13,38,53,62,55,20,
00050       23,37,30,6],
00051      [36,41,60,50,10,43,59,18,57,35,9,3,58,25,52,51,34,19,49,27,26,
00052       17,44,2,12,54,61,13,31,30,6,20,62,47,45,23,55,15,28,22,37,46,
00053       39,4,7,21,14,53],
00054      [57,33,52,42,2,35,51,10,49,27,1,60,50,17,44,43,26,11,41,19,18,
00055       9,36,59,4,46,53,5,23,22,61,12,54,39,37,15,47,7,20,14,29,38,31,
00056       63,62,13,6,45],
00057      [41,17,36,26,51,19,35,59,33,11,50,44,34,1,57,27,10,60,25,3,2,58,
00058       49,43,55,30,37,20,7,6,45,63,38,23,21,62,31,54,4,61,13,22,15,47,
00059       46,28,53,29],
00060      [25,1,49,10,35,3,19,43,17,60,34,57,18,50,41,11,59,44,9,52,51,42,
00061       33,27,39,14,21,4,54,53,29,47,22,7,5,46,15,38,55,45,28,6,62,31,
00062       30,12,37,13],
00063      [9,50,33,59,19,52,3,27,1,44,18,41,2,34,25,60,43,57,58,36,35,26,
00064       17,11,23,61,5,55,38,37,13,31,6,54,20,30,62,22,39,29,12,53,46,15,
00065       14,63,21,28],
00066      [58,34,17,43,3,36,52,11,50,57,2,25,51,18,9,44,27,41,42,49,19,10,
00067       1,60,7,45,20,39,22,21,28,15,53,38,4,14,46,6,23,13,63,37,30,62,
00068       61,47,5,12],
00069      [42,18,1,27,52,49,36,60,34,41,51,9,35,2,58,57,11,25,26,33,3,59,
00070       50,44,54,29,4,23,6,5,12,62,37,22,55,61,30,53,7,28,47,21,14,46,
00071       45,31,20,63],
00072      [26,2,50,11,36,33,49,44,18,25,35,58,19,51,42,41,60,9,10,17,52,
00073       43,34,57,38,13,55,7,53,20,63,46,21,6,39,45,14,37,54,12,31,5,61,
00074       30,29,15,4,47],
00075      [18,59,42,3,57,25,41,36,10,17,27,50,11,43,34,33,52,1,2,9,44,35,
00076       26,49,30,5,47,62,45,12,55,38,13,61,31,37,6,29,46,4,23,28,53,22,
00077       21,7,63,39]]),
00078   true)$
00079 
00080 okltest_des_round_keys(f) := block(
00081   /* Trivial keys showing extreme examples where
00082      round keys are exactly the same: */
00083   assert(map(binv2hexstr,f(create_list(0,i,1,64))) = 
00084     ["000000000000","000000000000","000000000000","000000000000",
00085      "000000000000","000000000000","000000000000","000000000000",
00086      "000000000000","000000000000","000000000000","000000000000",
00087      "000000000000","000000000000","000000000000","000000000000"]),
00088   assert(map(binv2hexstr,f(create_list(1,i,1,64))) = 
00089     ["FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF",
00090      "FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF",
00091      "FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF",
00092      "FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF","FFFFFFFFFFFF"]),
00093   /* Key with non-trivial pattern of zeros and ones to test
00094      the key schedule: */
00095   assert(map(binv2hexstr,f(des_validation_key)) =
00096     ["0B02679B49A5","69A659256A26","45D48AB428D2","7289D2A58257",
00097      "3CE80317A6C2","23251E3C8545","6C04950AE4C6","5788386CE581",
00098      "C0C9E926B839","91E307631D72","211F830D893A","7130E5455C54",
00099      "91C4D04980FC","5443B681DC8D","B691050A16B5","CA3D03B87032"]),
00100   /* Testing the argosat example (see "Transferring the Argosat-desgen
00101      example" in
00102      Investigations/Cryptography/DataEncryptionStandard/plans/KeyDiscovery.hpp):
00103   */
00104   assert(map(binv2hexstr, f(hexstr2binv("15FBC08D31B0D521"))) =
00105     ["8C45AB151088","5FA3C2082654","3ADCAB79C080","F9214E00440B",
00106      "20CE9D8E3004","553936A043E0","A6ACF1108A03","DF6626D60410",
00107      "258F6F819086","E370A34406A1","B98FF01A084D","D4729B02D190",
00108      "379754012521","4E58C7EA0800","3BE17C40431E","C7DC9D848D00"]),
00109   true)$
00110