OKlibrary  0.2.1.6
Cipher.mac
Go to the documentation of this file.
```00001 /* Matthew Gwynne, 27.2.2012 (Swansea) */
00002 /* Copyright 2012 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
00024 kill(f)\$
00025
00026
00027 /* *****************
00028    * KeeLoq cipher *
00029    *****************
00030 */
00031
00032 okltest_keeloq_nlf(f) := block(
00033   assert(f(0,0,0,0,0) = 0),
00034   assert(f(0,0,0,0,1) = 1),
00035   assert(f(0,0,0,0,0) = 0),
00036   assert(f(0,0,0,0,1) = 1),
00037   assert(f(0,0,0,1,0) = 1),
00038   assert(f(0,0,0,1,1) = 1),
00039   assert(f(0,0,1,0,0) = 0),
00040   assert(f(0,0,1,0,1) = 1),
00041   assert(f(0,0,1,1,0) = 0),
00042   assert(f(0,0,1,1,1) = 0),
00043   assert(f(0,1,0,0,0) = 0),
00044   assert(f(0,1,0,0,1) = 0),
00045   assert(f(0,1,0,1,0) = 1),
00046   assert(f(0,1,0,1,1) = 0),
00047   assert(f(0,1,1,0,0) = 1),
00048   assert(f(0,1,1,0,1) = 1),
00049   assert(f(0,1,1,1,0) = 1),
00050   assert(f(0,1,1,1,1) = 0),
00051   assert(f(1,0,0,0,0) = 0),
00052   assert(f(1,0,0,0,1) = 0),
00053   assert(f(1,0,0,1,0) = 1),
00054   assert(f(1,0,0,1,1) = 1),
00055   assert(f(1,0,1,0,0) = 1),
00056   assert(f(1,0,1,0,1) = 0),
00057   assert(f(1,0,1,1,0) = 1),
00058   assert(f(1,0,1,1,1) = 0),
00059   assert(f(1,1,0,0,0) = 0),
00060   assert(f(1,1,0,0,1) = 1),
00061   assert(f(1,1,0,1,0) = 0),
00062   assert(f(1,1,0,1,1) = 1),
00063   assert(f(1,1,1,0,0) = 1),
00064   assert(f(1,1,1,0,1) = 1),
00065   assert(f(1,1,1,1,0) = 0),
00066   assert(f(1,1,1,1,1) = 0),
00067   true)\$
00068
00069 okltest_keeloq_round(f) := block(
00070   assert(
00071     okltest_keeloq_round_bf(
00072       buildq([f], lambda([V], if f(rest(V,-1)) = V[9] then [1] else [0])))),
00073   true)\$
00074
00075 okltest_keeloq_round_bf(f) := block(
00076   assert(f([0,0,0,0,0,0,0,0,0]) = [1]),
00077   assert(f([0,0,0,0,0,0,0,0,1]) = [0]),
00078   assert(f([0,0,0,0,1,1,0,0,1]) = [1]),
00079   assert(f([0,0,0,0,1,1,0,0,0]) = [0]),
00080   assert(f([0,1,0,1,0,1,0,1,1]) = [1]),
00081   assert(f([0,1,0,1,0,1,0,1,0]) = [0]),
00082   true)\$
00083
00084 okltest_keeloq_encryption_gen(f) := block(
00085   for r : 1 thru 528 step 33 do
00086     assert(f(r,create_list(0,i,1,32),create_list(0,i,1,64)) =
00087       create_list(0,i,1,32)),
00088   assert(
00089     okltest_keeloq_encryption(
00090       buildq([f], lambda([P,K], f(528,P,K))))),
00091   true)\$
00092
00093 okltest_keeloq_encryption(f) := block(
00094   assert(f(create_list(0,i,1,32),create_list(0,i,1,64)) =
00095     create_list(0,i,1,32)),
00096   assert(f(
00097       [1,0,0,1,1,1,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,1,0,0,1,1,0,0],
00098       [0,0,0,0,1,1,1,0,1,1,1,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,0,1,1,0,
00099       0,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,0,0,0,0,1,0,0,0,1,1,1,1,1,1,1]) =
00100     [1,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,0,1,1,1,0,1,1,0,0,1,1,1,0,1,0,1]),
00101   true)\$
00102
```