OKlibrary  0.2.1.6
Cipher.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 
00024 kill(f)$
00025 
00026 okltest_des_template(f) := block(
00027   /* Trivial keys (computed using des_encryption_hex): */
00028   assert(
00029     f(hexstr2binv("0000000000000000"),
00030       des_round_keys(hexstr2binv("0000000000000000"))) =
00031       hexstr2binv("8CA64DE9C1B123A7")),
00032   assert(
00033     f(hexstr2binv("FFFFFFFFFFFFFFFF"),
00034       des_round_keys(hexstr2binv("FFFFFFFFFFFFFFFF"))) =
00035       hexstr2binv("7359B2163E4EDC58")),
00036   /* Test vector from SAT09 desgen benchmark (see "DES generator" in
00037      Buildsystem/ExternalSources/SpecialBuilds/plans/SAT.hpp):
00038   */
00039   assert(
00040     f(hexstr2binv("038E596D4841D03B"),
00041       des_round_keys(hexstr2binv("15FBC08D31B0D521"))) =
00042       hexstr2binv("A2FB6032638EC79D")),
00043   true)$
00044 
00045 okltest_des_encryption(f) := block(
00046   assert(
00047     okltest_des_encryption_hex(
00048       buildq([f],
00049         lambda([plain,key],
00050           binv2hexstr(f(hexstr2binv(plain),hexstr2binv(key))))))),
00051   true)$
00052 
00053 okltest_des_decryption(f) := block(
00054   assert(
00055     okltest_des_decryption_hex(
00056       buildq([f],
00057         lambda([plain,key],
00058           binv2hexstr(f(hexstr2binv(plain),hexstr2binv(key))))))),
00059   true)$
00060 
00061 okltest_des_encryption_gen(f) := block(
00062   assert(
00063     okltest_des_encryption(
00064       buildq([f],lambda([plain,key],f(16,plain,key))))),
00065   true)$
00066 
00067 okltest_des_decryption_gen(f) := block(
00068   assert(
00069     okltest_des_decryption(
00070       buildq([f],lambda([plain,key],f(16,plain,key))))),
00071   true)$
00072 
00073 okltest_des_encryption_hex(f) := block(
00074   /* Trivial keys (computed using des_encryption_hex): */
00075   assert(
00076     f("0000000000000000","0000000000000000") = "8CA64DE9C1B123A7"),
00077   assert(
00078     f("FFFFFFFFFFFFFFFF","FFFFFFFFFFFFFFFF") = "7359B2163E4EDC58"),
00079   /* Test vector from SAT09 desgen benchmark (see "DES generator" in
00080      Buildsystem/ExternalSources/SpecialBuilds/plans/SAT.hpp):
00081   */
00082   assert(
00083     f("038E596D4841D03B","15FBC08D31B0D521") = "A2FB6032638EC79D"),
00084   true)$
00085 
00086 okltest_des_decryption_hex(f) := block(
00087   /* Trivial keys (computed using des_decryption_hex): */
00088   assert(
00089     f("8CA64DE9C1B123A7","0000000000000000") = "0000000000000000"),
00090   assert(
00091     f("7359B2163E4EDC58","FFFFFFFFFFFFFFFF") = "FFFFFFFFFFFFFFFF"),
00092   /* Test vector from SAT09 desgen benchmark (see "DES generator" in
00093      Buildsystem/ExternalSources/SpecialBuilds/plans/SAT.hpp):
00094   */
00095   assert(
00096     f("A2FB6032638EC79D","15FBC08D31B0D521") = "038E596D4841D03B"),
00097   true)$
00098 
00099 okltest_des_encryption_hex_gen(f) := block(
00100   assert(
00101     okltest_des_encryption_hex(
00102       buildq([f],lambda([plain,key],f(16,plain,key))))),
00103   true)$
00104 
00105 okltest_des_decryption_hex_gen(f) := block(
00106   assert(
00107     okltest_des_decryption_hex(
00108       buildq([f],lambda([plain,key],f(16,plain,key))))),
00109   true)$
00110 
00111 
00112 
00113