PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Experimentation/Investigations/Cryptography/AdvancedEncryptionStandard/plans/KeyDiscovery/general.hpp

https://github.com/MGwynne/oklibrary
C++ Header | 341 lines | 0 code | 1 blank | 340 comment | 0 complexity | b23451da6e4cb23fe132392cb05c199a MD5 | raw file
  1. // Matthew Gwynne, 23.1.2011 (Swansea)
  2. /* Copyright 2011, 2012 Oliver Kullmann
  3. This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
  4. it and/or modify it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation and included in this library; either version 3 of the
  6. License, or any later version. */
  7. /*!
  8. \file Investigations/Cryptography/AdvancedEncryptionStandard/plans/KeyDiscovery/general.hpp
  9. \brief Investigations into AES key discovery
  10. The aim of these experiments is, using translations of the AES and small
  11. scale AES cryptosystems with the translation scheme given in
  12. ComputerAlgebra/Cryptology/Lisp/Cryptanalysis/Rijndael/Translations.mac, to
  13. "break" AES by discovering the key given a plaintext and ciphertext pair.
  14. The key aspects of the investigation are
  15. - the representations for the various "boxes" of the AES
  16. - the reconfiguration of the computational network, to make the boolean
  17. analysis more powerful.
  18. The investigations are arranged into subdirectories based on the bit
  19. size of the key (4,16,32,64,128 and so on), and then by the number of
  20. columns, rows and field size (e.g. 4_4_8 for standard AES). At the
  21. lowest level in this directory structure, we then have files for
  22. experiments on each number of rounds, where we classify rounds as
  23. follows:
  24. <ul>
  25. <li> A number n of rounds with no further qualification means that
  26. the AES consists of n AES rounds (key addition, then SubBytes, then
  27. Shiftrows, then MixColumns) with no final key addition. </li>
  28. <li> A number n of rounds with the addition of 1/3 (e.g. n + 1/3) means
  29. that the AES consists of n AES rounds (key addition, then SubBytes, then
  30. Shiftrows, then MixColumns) with a final key addition (the first third of
  31. the round, ignoring the Shiftrows). </li>
  32. <li> A number n of rounds with the addition of 2/3 (e.g. n + 2/3) means
  33. that the AES consists of n AES rounds (key addition, then SubBytes, then
  34. Shiftrows, then MixColumns) and then another special final round with just
  35. key addition, SubBytes and ShiftRows (i.e. two thirds of a round, ignoring
  36. Shiftrows). </li>
  37. <li> A number n of rounds with the addition of 2/3 and 1/3 (n + 2/3 + 1/3)
  38. means that the AES consists of n AES rounds (key addition, then SubBytes,
  39. then Shiftrows, then MixColumns) and then another special final round with
  40. just key addition, SubBytes and ShiftRows (i.e. two thirds of a round,
  41. ignoring Shiftrows). After this final round, we also have an additional key
  42. addition (the first third of the round, ignoring the Shiftrows). </li>
  43. </ul>
  44. Experiments run over n, n + 1/3, n + 2/3 and n + 2/3 + 1/3 AES rounds are
  45. then in files named n.hpp, n_13.hpp, n_23.hpp and n_23_13.hpp respectively.
  46. As an example, experiments on the standard one round AES (no final round,
  47. with a final key addition), are in 128/4_4_8/1_13.hpp.
  48. \todo Show and explain sizes of minimum-translations
  49. <ul>
  50. <li> To show the "minimum-size" translation, its sizes need to be discussed
  51. everywhere. </li>
  52. <li> This must include explanations of the numbers of different boxes and
  53. their contributions to the overall size (explained, in each case). </li>
  54. </ul>
  55. \todo Patterns
  56. <ul>
  57. <li> We list here any patterns noticed in the behaviour of solvers on
  58. key discovery instances, and suggest further avenues of investigation.
  59. </li>
  60. <li> 4-bit (field size) instances (so far):
  61. <ul>
  62. <li> All translations perform comparably; there is no clear "best"
  63. translation. </li>
  64. </ul>
  65. </li>
  66. <li> 8-bit (field size) instances (so far):
  67. <ul>
  68. <li> The 1-soft translations perform better by a considerable
  69. margin (e.g., 35 times faster; 1000 times less conflicts). </li>
  70. <li> Comparing "time to solve" (or "conflicts") vs
  71. "number of rounds":
  72. <ul>
  73. <li> 1-soft translations: (best) fit (equally well) by either a
  74. quadratic function, or exponential t ~ e^(0.2*r). </li>
  75. <li> minimum translations: (best) fit (equally well) by either a
  76. quintic function, or exponential t ~ e^(0.6*r). </li>
  77. </ul>
  78. That is, the minimum translation gets "harder, faster" as the
  79. number of rounds increases. </li>
  80. <li> We have experiments on instances of the form
  81. AES(r,1,1,8), AES(r,2,1,8) and AES(r,1,2,8). </li>
  82. <li> We should consider AES(r,1,3,8), AES(4,1,8) and AES(2,2,8) next
  83. to see if this pattern persists. </li>
  84. <li> We also need to almalgamate the data from all other
  85. experiments into this todo. </li>
  86. </ul>
  87. </li>
  88. <li> Most experiments so far have been with minisat-2.2.0.
  89. We should run other solvers and see if these patterns persist. </li>
  90. </ul>
  91. \todo Explanations
  92. <ul>
  93. <li> For every set of AES parameters (rows, columns and field size), we
  94. need the following:
  95. <ul>
  96. <li> Problem specification:
  97. <ul>
  98. <li> We need explanations what a "round" etc. is, in elementary terms,
  99. using terms "addition, sub-bytes, shift-rows, mix-columns, round-key".
  100. </li>
  101. <li> This should go to the general.hpp file in the appropriate
  102. directory (e.g., KeyDiscovery/016/2_1_8/general.hpp). </li>
  103. </ul>
  104. </li>
  105. <li> Translations:
  106. <ul>
  107. <li> We need explanation of how to generate each instance, including
  108. which boxes are being used in each case. </li>
  109. <li> This can go to Translations.hpp (e.g.,
  110. KeyDiscovery/016/2_1_8/Translations.hpp). </li>
  111. </ul>
  112. </li>
  113. <li> Statistics:
  114. <ul>
  115. <li> We need statistics and explanations of them, for all
  116. instances. </li>
  117. <li> This can go to Statistics.hpp (e.g.,
  118. KeyDiscovery/016/2_1_8/Statistics.hpp). </li>
  119. </ul>
  120. </li>
  121. </ul>
  122. </li>
  123. <li> The reason for splitting each of these are that it means that:
  124. <ul>
  125. <li> each file doesn't become too large and hard to navigate; </li>
  126. <li> statistics and so on can be provided for all rounds in one file,
  127. allowing easy comparison; </li>
  128. <li> information is not needlessly replicated. </li>
  129. </ul>
  130. </li>
  131. <li> In general, all discussions should be based on the general notions
  132. as introduced in
  133. ComputerAlgebra/Cryptology/Lisp/CryptoSystems/IteratedBlockCipher.mac.
  134. </li>
  135. <li> Also the file-name needs to be explained (in each file). </li>
  136. </ul>
  137. \todo Naming of translations
  138. <ul>
  139. <li> For each experiment on some AES variant with some specific translation
  140. we have a todo. </li>
  141. <li> One must someone specify in the title and content of the todo which
  142. translation is meant. See "Investigating dimensions" in
  143. Cryptography/AdvancedEncryptionStandard/plans/Experimentation.hpp.
  144. </li>
  145. <li> For example "Using the canonical box translation" in
  146. Cryptography/AdvancedEncryptionStandard/plans/KeyDiscovery/032/4_2_4/2_13.hpp
  147. doesn't provide enough information on its own to understand which
  148. translation is meant. </li>
  149. <li> The first thought is for the title of the todo to fully specify the
  150. translation. So for example, one would have "Using the whole Sbox and
  151. encryption-only Mixcolumns with "multiplication-based" decompositions
  152. translated using the canonical translation and Key schedule using the
  153. shared sub-expression translation.". </li>
  154. <li> The full specification is hard to read, however, and isn't appropriate
  155. for a todo heading. </li>
  156. <li> Another solution would be to specify defaults for each aspect of
  157. the translation, and then only specify the non-standard parts of the
  158. translation. The above example would then be
  159. "Using standard translation but with encryption-only MixColumns.". </li>
  160. <li> This is much more succinct but one must constantly refer to
  161. the "standard" translation. </li>
  162. <li> A balance between these two approaches is needed. </li>
  163. <li> One weapon in tackling the large number of dimensions of the AES
  164. translation is to derive overarching named concepts which categorise
  165. several dimensions at once. </li>
  166. </ul>
  167. \todo Links
  168. <ul>
  169. <li> For investigations into the various component/box representations
  170. (CNF and otherwise) of the AES boxes (Sbox, field multiplications etc) see
  171. Cryptography/AdvancedEncryptionStandard/plans/Representations/general.hpp .
  172. </li>
  173. <li> See
  174. Cryptography/AdvancedEncryptionStandard/plans/general.hpp
  175. for the more general investigations.
  176. </li>
  177. </ul>
  178. \todo Boundaries
  179. <ul>
  180. <li> This todo is out of date and must be updated. </li>
  181. <li> At the same time, the order should be changed to
  182. "N rows, N columns"; rows come first in a matrix specification.
  183. </li>
  184. <li> We need to have a good understanding of the boundaries of the
  185. parameters and sizes of AES key discovery instances that we can
  186. solve in a reasonable time (in less than a day or two). </li>
  187. <li> So far, we can solve the following in the listed times for
  188. the n + 1/3 round variants:
  189. <ul>
  190. <li> 128 bit key:
  191. <ul>
  192. <li> Can break standard AES for 2/3 + 1/3 rounds in 18s with picosat913.
  193. </li>
  194. <li> So far can't break standard AES for 1 + 1/3 round after two days
  195. computation with all solvers XXX. </li>
  196. <li> 16 column, 1 row, 8 bits, up to <em> 2 + 1/3 </em> rounds in
  197. <em>40s</em> with minisat-2.2.0 in 128/1_16_8/2_13.hpp. </li>
  198. </ul>
  199. </li>
  200. <li> 64 bit key:
  201. <ul>
  202. <li> 16 column, 1 row, 4 bits, up to <em>5 + 1/3</em> rounds in
  203. <em> 26 </em> seconds with minisat-2.2.0 in 064/1_16_4/4_13.hpp. </li>
  204. <li> 4 column, 4 row, 4 bits up to <em>1+1/3</em> rounds in
  205. <em> 21 </em> seconds with minisat-2.2.0 in 064/4_4_4/1_13.hpp.
  206. </li>
  207. </ul>
  208. </li>
  209. <li> 32 bit key:
  210. <ul>
  211. <li> 2 column, 4 row, 4 bits up to <em>2 + 1/3</em> rounds in
  212. <em> 2718 </em> seconds with glucose in 032/4_2_4/2_13.hpp. </li>
  213. <li> 4 column, 2 row, 4 bits up to <em>5 + 1/3</em> rounds in
  214. <em> 903 </em> seconds with picosat in 032/2_4_4/5_13.hpp. </li>
  215. </ul>
  216. </li>
  217. <li> 16 bit key:
  218. <ul>
  219. <li> 1 column, 2 row, 8 bits up to <em>20 + 1/3</em> rounds in
  220. <em> 268s </em> seconds with minisat-2.2.0 in 016/2_1_8/general.hpp. </li>
  221. <li> 2 column, 2 row, 4 bits up to <em>20 + 1/3</em> rounds in
  222. <em> 40s </em> seconds with minisat-2.2.0 in 016/2_2_4/20_13.hpp. </li>
  223. </ul>
  224. </li>
  225. <li> 8 bit key:
  226. <ul>
  227. <li> 1 column, 1 row, 8 bits up to <em>20 + 1/3</em> rounds in
  228. <em> 0.5 </em> seconds with precosat236 in 008/1_1_8/20_13.hpp. </li>
  229. </ul>
  230. </li>
  231. <li> 4 bit key:
  232. <ul>
  233. <li> 1 column, 1 row, 4 bits up to <em>20 + 1/3</em> rounds in
  234. <em> 0.0 </em> seconds, and with <em> 1 </em> decision, with OKsolver
  235. in 004/1_1_4/20_13.hpp. </li>
  236. </ul>
  237. </li>
  238. </ul>
  239. </li>
  240. </ul>
  241. \todo Fast generation of AES translations
  242. <ul>
  243. <li> At current, the AES translations are incredibly slow, mainly due to
  244. the fact that very large variable names are introduced, which are then
  245. later standardised. </li>
  246. <li> The maxima implementation of hash tables is slow, and so as discussed
  247. in "Using the Maxima "associative arrays" in
  248. ComputerAlgebra/DataStructures/Lisp/plans/HashMaps.hpp, one can get quite a
  249. large speed up in some circumstances by use associative arrays. </li>
  250. <li> The following functions can be redefined after calling
  251. "oklib_load_all" to achieve a speed up:
  252. \verbatim
  253. rename_fcl(FF,VL) := block([count : -1], local(h),
  254. for V in map("[", FF[1], VL) do h[V[1]] : V[2],
  255. return([create_list(i,i,1,length(FF[1])),
  256. map(
  257. lambda([C], (
  258. if oklib_monitor then
  259. (count : count + 1,
  260. if mod(count,1000) = 0 then
  261. print("Renaming ", count, "/",length(FF[2]))),
  262. map(lambda([L], if L > 0 then h[L] else -h[-L]), C))), FF[2])]))$
  263. gen_count : 384;
  264. generate_ss_constraint_vars(n,m,namespace, id) :=
  265. create_list(
  266. if integerp(gen_h[namespace(ss_var(i,id))]) then gen_h[namespace(ss_var(i,id))]
  267. else gen_h[namespace(ss_var(i,id))] : (gen_count : gen_count +1),
  268. i,n,m)$
  269. \endverbatim
  270. </li>
  271. <li> Note that although the standardised translation will be the same,
  272. the file output will be slightly different as the variable mappings will
  273. not be maintained. Therefore, if knowing precisely what variables are what
  274. (excluding the plaintext, key and ciphertext variables, which are always
  275. at 1-3*num_rows*num_columns*exp) is important, then one should exclude
  276. the replacement of "generate_ss_constraint_vars", i.e., only use the
  277. following:
  278. \verbatim
  279. rename_fcl(FF,VL) := block([count : -1], local(h),
  280. for V in map("[", FF[1], VL) do h[V[1]] : V[2],
  281. return([create_list(i,i,1,length(FF[1])),
  282. map(
  283. lambda([C], (
  284. if oklib_monitor then
  285. (count : count + 1,
  286. if mod(count,1000) = 0 then
  287. print("Renaming ", count, "/",length(FF[2]))),
  288. map(lambda([L], if L > 0 then h[L] else -h[-L]), C))), FF[2])]))$
  289. \endverbatim.
  290. </li>
  291. <li> Also note that "gen_h" is global in this example as we want
  292. generate_ss_constraint_vars to yield the same result across calls. </li>
  293. <li> Therefore, a typical AES translation might be:
  294. \verbatim
  295. maxima> oklib_load_all()$
  296. maxima> oklib_monitor : true$
  297. maxima> rename_fcl(FF,VL) := block([count : -1], local(h),
  298. for V in map("[", FF[1], VL) do h[V[1]] : V[2],
  299. return([create_list(i,i,1,length(FF[1])),
  300. map(
  301. lambda([C], (
  302. if oklib_monitor then
  303. (count : count + 1,
  304. if mod(count,1000) = 0 then
  305. print("Renaming ", count, "/",length(FF[2]))),
  306. map(lambda([L], if L > 0 then h[L] else -h[-L]), C))), FF[2])]))$
  307. gen_count : 384;
  308. generate_ss_constraint_vars(n,m,namespace, id) :=
  309. create_list(
  310. if integerp(gen_h[namespace(ss_var(i,id))]) then gen_h[namespace(ss_var(i,id))]
  311. else gen_h[namespace(ss_var(i,id))] : (gen_count : gen_count +1),
  312. i,n,m)$
  313. maxima> output_ss_fcl_std(1,4,4,8,0,aes_ts_box, aes_mc_bidirectional);
  314. \endverbatim
  315. </li>
  316. </ul>
  317. */