OKlibrary  0.2.1.6
Block.mac
Go to the documentation of this file.
00001 /* Matthew Gwynne, 21.1.2010 (Swansea) */
00002 /* Copyright 2010, 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/Cryptology/Lisp/CryptoSystems/Rijndael/ByteField.mac")$
00023 oklib_include("OKlib/ComputerAlgebra/Cryptology/Lisp/CryptoSystems/Rijndael/SmallScaleWordFields.mac")$
00024 
00025 kill(f)$
00026 
00027 
00028 okltest_rijn_m2l(f) := (
00029   assert(f(diagmatrix(4,0)) = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),
00030   assert(f(diagmatrix(4,1)) = [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),
00031   assert(f(matrixmap(nat2polybin,
00032         matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]))) =
00033     map(nat2polybin,[1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16])),
00034   true)$
00035 
00036 okltest_rijn_l2m(f) := (
00037   assert(f([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) = diagmatrix(4,0)),
00038   assert(f([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]) = diagmatrix(4,1)),
00039   assert(f(map(nat2polybin,[1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16])) = matrixmap(nat2polybin,
00040         matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]))),
00041   true)$
00042 
00043 okltest_ss_m2l(f) := (
00044   assert(okltest_rijn_m2l(f)),
00045   true)$
00046 
00047 okltest_ss_l2m(f) := (
00048   assert(okltest_rijn_l2m(buildq([f], lambda([L], f(L,4))))),
00049   true)$
00050 
00051 okltest_rijn_natl2m(f) := (
00052   assert(f(create_list(0,i,1,16)) = diagmatrix(4,0)),
00053   assert(f(create_list(1,i,1,16)) = genmatrix(lambda([a,b],1),4,4)),
00054   assert(f([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]) = matrix(
00055       [1,x^2+1,x^3+1,x^3+x^2+1],
00056       [x,x^2+x,x^3+x,x^3+x^2+x],
00057       [x+1,x^2+x+1,x^3+x+1,x^3+x^2+x+1],
00058       [x^2,x^3,x^3+x^2,x^4])),
00059   true)$
00060 
00061 
00062 okltest_rijn_m2natl(f) := (
00063     assert(f(diagmatrix(4,0)) = create_list(0,i,1,16)),
00064   assert(f(genmatrix(lambda([a,b],1),4,4)) = create_list(1,i,1,16)),
00065   assert(f(matrix(
00066       [1,x^2+1,x^3+1,x^3+x^2+1],
00067       [x,x^2+x,x^3+x,x^3+x^2+x],
00068       [x+1,x^2+x+1,x^3+x+1,x^3+x^2+x+1],
00069       [x^2,x^3,x^3+x^2,x^4])) = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]),
00070   true)$
00071 
00072 okltest_ss_natl2m(f) := (
00073   assert(okltest_rijn_natl2m(buildq([f], lambda([L], f(L,2,4))))),
00074   true)$
00075 
00076 okltest_ss_m2natl(f) := (
00077   assert(okltest_rijn_m2natl(buildq([f], lambda([L], f(L,2))))),
00078   true)$
00079 
00080 okltest_ss_matrix2hex(f) := block(
00081   assert(f(matrix([1]), 2, 4, ss_polynomial_2_4) = "1"),
00082   assert(f(matrix([1],[0]), 2, 4, ss_polynomial_2_4) = "10"),
00083   assert(f(matrix([1,x],[0,x^3]), 2, 4, ss_polynomial_2_4) = "1028"),
00084   assert(f(matrix([x^6+x^5+x^2+x,x^7+x^6+x^5+x^3+x^2+x+1,x^7+x^3,x^7+x^6+x^3+x],
00085         [x^7+x^6+x^5+x^3+1,x^7+x^3+x,x^6+x^3+x^2,x^5+x^4+x^2],
00086         [x^6+x^3+x+1,x^5+x^3+x^2,x^7+x^6+x^5+x^4+x^3+x,x^5+x^3+x+1],
00087         [x^7+x^6+x^4+x^2,x^5+x^4+x^3+x+1,x^6+x^4+x^3+1,x^5+x^3+x^2+x]),2,8,
00088     ss_polynomial_2_8) = "66E94BD4EF8A2C3B884CFA59CA342B2E"),
00089   true)$
00090 
00091 okltest_ss_hex2matrix(f) := block(
00092   assert(f("1", 2, 4, ss_polynomial_2_4, 1) = matrix([1])),
00093   assert(f("10",  2, 4, ss_polynomial_2_4, 2) = matrix([1],[0])),
00094   true)$
00095