You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
4.9 KiB

  1. pragma circom 2.0.0;
  2. include "./utils.circom";
  3. template step(shl, shr) {
  4. // out = a<<shl|a>>shr
  5. signal input a[64];
  6. signal output out[64];
  7. var i;
  8. component aux0 = ShR(64, shr);
  9. for (i=0; i<64; i++) {
  10. aux0.in[i] <== a[i];
  11. }
  12. component aux1 = ShL(64, shl);
  13. for (i=0; i<64; i++) {
  14. aux1.in[i] <== a[i];
  15. }
  16. component aux2 = OrArray(64);
  17. for (i=0; i<64; i++) {
  18. aux2.a[i] <== aux0.out[i];
  19. aux2.b[i] <== aux1.out[i];
  20. }
  21. for (i=0; i<64; i++) {
  22. out[i] <== aux2.out[i];
  23. }
  24. }
  25. template RhoPi() {
  26. signal input in[25*64];
  27. signal output out[25*64];
  28. var i;
  29. for (i=0; i<64; i++) {
  30. out[i] <== in[i];
  31. }
  32. // r[10] = a[1]<<1|a[1]>>(64-1)
  33. component s10 = step(1, 64-1);
  34. for (i=0; i<64; i++) {
  35. s10.a[i] <== in[1*64+i];
  36. }
  37. // r[7] = a[10]<<3|a[10]>>(64-3)
  38. component s7 = step(3, 64-3);
  39. for (i=0; i<64; i++) {
  40. s7.a[i] <== in[10*64+i];
  41. }
  42. // r[11] = a[7]<<6|a[7]>>(64-6)
  43. component s11 = step(6, 64-6);
  44. for (i=0; i<64; i++) {
  45. s11.a[i] <== in[7*64+i];
  46. }
  47. // r[17] = a[11]<<10|a[11]>>(64-10)
  48. component s17 = step(10, 64-10);
  49. for (i=0; i<64; i++) {
  50. s17.a[i] <== in[11*64+i];
  51. }
  52. // r[18] = a[17]<<15|a[17]>>(64-15)
  53. component s18 = step(15, 64-15);
  54. for (i=0; i<64; i++) {
  55. s18.a[i] <== in[17*64+i];
  56. }
  57. // r[3] = a[18]<<21|a[18]>>(64-21)
  58. component s3 = step(21, 64-21);
  59. for (i=0; i<64; i++) {
  60. s3.a[i] <== in[18*64+i];
  61. }
  62. // r[5] = a[3]<<28|a[3]>>(64-28)
  63. component s5 = step(28, 64-28);
  64. for (i=0; i<64; i++) {
  65. s5.a[i] <== in[3*64+i];
  66. }
  67. // r[16] = a[5]<<36|a[5]>>(64-36)
  68. component s16 = step(36, 64-36);
  69. for (i=0; i<64; i++) {
  70. s16.a[i] <== in[5*64+i];
  71. }
  72. // r[8] = a[16]<<45|a[16]>>(64-45)
  73. component s8 = step(45, 64-45);
  74. for (i=0; i<64; i++) {
  75. s8.a[i] <== in[16*64+i];
  76. }
  77. // r[21] = a[8]<<55|a[8]>>(64-55)
  78. component s21 = step(55, 64-55);
  79. for (i=0; i<64; i++) {
  80. s21.a[i] <== in[8*64+i];
  81. }
  82. // r[24] = a[21]<<2|a[21]>>(64-2)
  83. component s24 = step(2, 64-2);
  84. for (i=0; i<64; i++) {
  85. s24.a[i] <== in[21*64+i];
  86. }
  87. // r[4] = a[24]<<14|a[24]>>(64-14)
  88. component s4 = step(14, 64-14);
  89. for (i=0; i<64; i++) {
  90. s4.a[i] <== in[24*64+i];
  91. }
  92. // r[15] = a[4]<<27|a[4]>>(64-27)
  93. component s15 = step(27, 64-27);
  94. for (i=0; i<64; i++) {
  95. s15.a[i] <== in[4*64+i];
  96. }
  97. // r[23] = a[15]<<41|a[15]>>(64-41)
  98. component s23 = step(41, 64-41);
  99. for (i=0; i<64; i++) {
  100. s23.a[i] <== in[15*64+i];
  101. }
  102. // r[19] = a[23]<<56|a[23]>>(64-56)
  103. component s19 = step(56, 64-56);
  104. for (i=0; i<64; i++) {
  105. s19.a[i] <== in[23*64+i];
  106. }
  107. // r[13] = a[19]<<8|a[19]>>(64-8)
  108. component s13 = step(8, 64-8);
  109. for (i=0; i<64; i++) {
  110. s13.a[i] <== in[19*64+i];
  111. }
  112. // r[12] = a[13]<<25|a[13]>>(64-25)
  113. component s12 = step(25, 64-25);
  114. for (i=0; i<64; i++) {
  115. s12.a[i] <== in[13*64+i];
  116. }
  117. // r[2] = a[12]<<43|a[12]>>(64-43)
  118. component s2 = step(43, 64-43);
  119. for (i=0; i<64; i++) {
  120. s2.a[i] <== in[12*64+i];
  121. }
  122. // r[20] = a[2]<<62|a[2]>>(64-62)
  123. component s20 = step(62, 64-62);
  124. for (i=0; i<64; i++) {
  125. s20.a[i] <== in[2*64+i];
  126. }
  127. // r[14] = a[20]<<18|a[20]>>(64-18)
  128. component s14 = step(18, 64-18);
  129. for (i=0; i<64; i++) {
  130. s14.a[i] <== in[20*64+i];
  131. }
  132. // r[22] = a[14]<<39|a[14]>>(64-39)
  133. component s22 = step(39, 64-39);
  134. for (i=0; i<64; i++) {
  135. s22.a[i] <== in[14*64+i];
  136. }
  137. // r[9] = a[22]<<61|a[22]>>(64-61)
  138. component s9 = step(61, 64-61);
  139. for (i=0; i<64; i++) {
  140. s9.a[i] <== in[22*64+i];
  141. }
  142. // r[6] = a[9]<<20|a[9]>>(64-20)
  143. component s6 = step(20, 64-20);
  144. for (i=0; i<64; i++) {
  145. s6.a[i] <== in[9*64+i];
  146. }
  147. // r[1] = a[6]<<44|a[6]>>(64-44)
  148. component s1 = step(44, 64-44);
  149. for (i=0; i<64; i++) {
  150. s1.a[i] <== in[6*64+i];
  151. }
  152. for (i=0; i<64; i++) {
  153. out[10*64+i] <== s10.out[i];
  154. out[7*64+i] <== s7.out[i];
  155. out[11*64+i] <== s11.out[i];
  156. out[17*64+i] <== s17.out[i];
  157. out[18*64+i] <== s18.out[i];
  158. out[3*64+i] <== s3.out[i];
  159. out[5*64+i] <== s5.out[i];
  160. out[16*64+i] <== s16.out[i];
  161. out[8*64+i] <== s8.out[i];
  162. out[21*64+i] <== s21.out[i];
  163. out[24*64+i] <== s24.out[i];
  164. out[4*64+i] <== s4.out[i];
  165. out[15*64+i] <== s15.out[i];
  166. out[23*64+i] <== s23.out[i];
  167. out[19*64+i] <== s19.out[i];
  168. out[13*64+i] <== s13.out[i];
  169. out[12*64+i] <== s12.out[i];
  170. out[2*64+i] <== s2.out[i];
  171. out[20*64+i] <== s20.out[i];
  172. out[14*64+i] <== s14.out[i];
  173. out[22*64+i] <== s22.out[i];
  174. out[9*64+i] <== s9.out[i];
  175. out[6*64+i] <== s6.out[i];
  176. out[1*64+i] <== s1.out[i];
  177. }
  178. }