KeccakP-1600-unrolling.macros 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
  3. Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
  4. denoted as "the implementer".
  5. For more information, feedback or questions, please refer to our websites:
  6. http://keccak.noekeon.org/
  7. http://keyak.noekeon.org/
  8. http://ketje.noekeon.org/
  9. To the extent possible under law, the implementer has waived all copyright
  10. and related or neighboring rights to the source code in this file.
  11. http://creativecommons.org/publicdomain/zero/1.0/
  12. */
  13. #if (defined(FullUnrolling))
  14. #define rounds24 \
  15. prepareTheta \
  16. thetaRhoPiChiIotaPrepareTheta( 0, A, E) \
  17. thetaRhoPiChiIotaPrepareTheta( 1, E, A) \
  18. thetaRhoPiChiIotaPrepareTheta( 2, A, E) \
  19. thetaRhoPiChiIotaPrepareTheta( 3, E, A) \
  20. thetaRhoPiChiIotaPrepareTheta( 4, A, E) \
  21. thetaRhoPiChiIotaPrepareTheta( 5, E, A) \
  22. thetaRhoPiChiIotaPrepareTheta( 6, A, E) \
  23. thetaRhoPiChiIotaPrepareTheta( 7, E, A) \
  24. thetaRhoPiChiIotaPrepareTheta( 8, A, E) \
  25. thetaRhoPiChiIotaPrepareTheta( 9, E, A) \
  26. thetaRhoPiChiIotaPrepareTheta(10, A, E) \
  27. thetaRhoPiChiIotaPrepareTheta(11, E, A) \
  28. thetaRhoPiChiIotaPrepareTheta(12, A, E) \
  29. thetaRhoPiChiIotaPrepareTheta(13, E, A) \
  30. thetaRhoPiChiIotaPrepareTheta(14, A, E) \
  31. thetaRhoPiChiIotaPrepareTheta(15, E, A) \
  32. thetaRhoPiChiIotaPrepareTheta(16, A, E) \
  33. thetaRhoPiChiIotaPrepareTheta(17, E, A) \
  34. thetaRhoPiChiIotaPrepareTheta(18, A, E) \
  35. thetaRhoPiChiIotaPrepareTheta(19, E, A) \
  36. thetaRhoPiChiIotaPrepareTheta(20, A, E) \
  37. thetaRhoPiChiIotaPrepareTheta(21, E, A) \
  38. thetaRhoPiChiIotaPrepareTheta(22, A, E) \
  39. thetaRhoPiChiIota(23, E, A) \
  40. #define rounds12 \
  41. prepareTheta \
  42. thetaRhoPiChiIotaPrepareTheta(12, A, E) \
  43. thetaRhoPiChiIotaPrepareTheta(13, E, A) \
  44. thetaRhoPiChiIotaPrepareTheta(14, A, E) \
  45. thetaRhoPiChiIotaPrepareTheta(15, E, A) \
  46. thetaRhoPiChiIotaPrepareTheta(16, A, E) \
  47. thetaRhoPiChiIotaPrepareTheta(17, E, A) \
  48. thetaRhoPiChiIotaPrepareTheta(18, A, E) \
  49. thetaRhoPiChiIotaPrepareTheta(19, E, A) \
  50. thetaRhoPiChiIotaPrepareTheta(20, A, E) \
  51. thetaRhoPiChiIotaPrepareTheta(21, E, A) \
  52. thetaRhoPiChiIotaPrepareTheta(22, A, E) \
  53. thetaRhoPiChiIota(23, E, A) \
  54. #elif (Unrolling == 12)
  55. #define rounds24 \
  56. prepareTheta \
  57. for(i=0; i<24; i+=12) { \
  58. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  59. thetaRhoPiChiIotaPrepareTheta(i+ 1, E, A) \
  60. thetaRhoPiChiIotaPrepareTheta(i+ 2, A, E) \
  61. thetaRhoPiChiIotaPrepareTheta(i+ 3, E, A) \
  62. thetaRhoPiChiIotaPrepareTheta(i+ 4, A, E) \
  63. thetaRhoPiChiIotaPrepareTheta(i+ 5, E, A) \
  64. thetaRhoPiChiIotaPrepareTheta(i+ 6, A, E) \
  65. thetaRhoPiChiIotaPrepareTheta(i+ 7, E, A) \
  66. thetaRhoPiChiIotaPrepareTheta(i+ 8, A, E) \
  67. thetaRhoPiChiIotaPrepareTheta(i+ 9, E, A) \
  68. thetaRhoPiChiIotaPrepareTheta(i+10, A, E) \
  69. thetaRhoPiChiIotaPrepareTheta(i+11, E, A) \
  70. } \
  71. #define rounds12 \
  72. prepareTheta \
  73. thetaRhoPiChiIotaPrepareTheta(12, A, E) \
  74. thetaRhoPiChiIotaPrepareTheta(13, E, A) \
  75. thetaRhoPiChiIotaPrepareTheta(14, A, E) \
  76. thetaRhoPiChiIotaPrepareTheta(15, E, A) \
  77. thetaRhoPiChiIotaPrepareTheta(16, A, E) \
  78. thetaRhoPiChiIotaPrepareTheta(17, E, A) \
  79. thetaRhoPiChiIotaPrepareTheta(18, A, E) \
  80. thetaRhoPiChiIotaPrepareTheta(19, E, A) \
  81. thetaRhoPiChiIotaPrepareTheta(20, A, E) \
  82. thetaRhoPiChiIotaPrepareTheta(21, E, A) \
  83. thetaRhoPiChiIotaPrepareTheta(22, A, E) \
  84. thetaRhoPiChiIota(23, E, A) \
  85. #elif (Unrolling == 6)
  86. #define rounds24 \
  87. prepareTheta \
  88. for(i=0; i<24; i+=6) { \
  89. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  90. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  91. thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
  92. thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
  93. thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \
  94. thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \
  95. } \
  96. #define rounds12 \
  97. prepareTheta \
  98. for(i=12; i<24; i+=6) { \
  99. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  100. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  101. thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
  102. thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
  103. thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \
  104. thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \
  105. } \
  106. #elif (Unrolling == 4)
  107. #define rounds24 \
  108. prepareTheta \
  109. for(i=0; i<24; i+=4) { \
  110. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  111. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  112. thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
  113. thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
  114. } \
  115. #define rounds12 \
  116. prepareTheta \
  117. for(i=12; i<24; i+=4) { \
  118. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  119. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  120. thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
  121. thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
  122. } \
  123. #elif (Unrolling == 3)
  124. #define rounds24 \
  125. prepareTheta \
  126. for(i=0; i<24; i+=3) { \
  127. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  128. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  129. thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
  130. copyStateVariables(A, E) \
  131. } \
  132. #define rounds12 \
  133. prepareTheta \
  134. for(i=12; i<24; i+=3) { \
  135. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  136. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  137. thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
  138. copyStateVariables(A, E) \
  139. } \
  140. #elif (Unrolling == 2)
  141. #define rounds24 \
  142. prepareTheta \
  143. for(i=0; i<24; i+=2) { \
  144. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  145. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  146. } \
  147. #define rounds12 \
  148. prepareTheta \
  149. for(i=12; i<24; i+=2) { \
  150. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  151. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  152. } \
  153. #elif (Unrolling == 1)
  154. #define rounds24 \
  155. prepareTheta \
  156. for(i=0; i<24; i++) { \
  157. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  158. copyStateVariables(A, E) \
  159. } \
  160. #define rounds12 \
  161. prepareTheta \
  162. for(i=12; i<24; i++) { \
  163. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  164. copyStateVariables(A, E) \
  165. } \
  166. #else
  167. #error "Unrolling is not correctly specified!"
  168. #endif
  169. #define roundsN(__nrounds) \
  170. prepareTheta \
  171. i = 24 - (__nrounds); \
  172. if ((i&1) != 0) { \
  173. thetaRhoPiChiIotaPrepareTheta(i, A, E) \
  174. copyStateVariables(A, E) \
  175. ++i; \
  176. } \
  177. for( /* empty */; i<24; i+=2) { \
  178. thetaRhoPiChiIotaPrepareTheta(i , A, E) \
  179. thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
  180. }