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.

118 lines
2.4 KiB

  1. // Keccak256 hash function (ethereum version).
  2. // For LICENSE check https://github.com/vocdoni/keccak256-circom/blob/master/LICENSE
  3. pragma circom 2.0.0;
  4. include "../node_modules/circomlib/circuits/gates.circom";
  5. include "../node_modules/circomlib/circuits/sha256/xor3.circom";
  6. include "../node_modules/circomlib/circuits/sha256/shift.circom"; // contains ShiftRight
  7. template Xor5(n) {
  8. signal input a[n];
  9. signal input b[n];
  10. signal input c[n];
  11. signal input d[n];
  12. signal input e[n];
  13. signal output out[n];
  14. var i;
  15. component xor3 = Xor3(n);
  16. for (i=0; i<n; i++) {
  17. xor3.a[i] <== a[i];
  18. xor3.b[i] <== b[i];
  19. xor3.c[i] <== c[i];
  20. }
  21. component xor4 = XorArray(n);
  22. for (i=0; i<n; i++) {
  23. xor4.a[i] <== xor3.out[i];
  24. xor4.b[i] <== d[i];
  25. }
  26. component xor5 = XorArray(n);
  27. for (i=0; i<n; i++) {
  28. xor5.a[i] <== xor4.out[i];
  29. xor5.b[i] <== e[i];
  30. }
  31. for (i=0; i<n; i++) {
  32. out[i] <== xor5.out[i];
  33. }
  34. }
  35. template XorArray(n) {
  36. signal input a[n];
  37. signal input b[n];
  38. signal output out[n];
  39. var i;
  40. component aux[n];
  41. for (i=0; i<n; i++) {
  42. aux[i] = XOR();
  43. aux[i].a <== a[i];
  44. aux[i].b <== b[i];
  45. }
  46. for (i=0; i<n; i++) {
  47. out[i] <== aux[i].out;
  48. }
  49. }
  50. template XorArraySingle(n) {
  51. signal input a[n];
  52. signal output out[n];
  53. var i;
  54. component aux[n];
  55. for (i=0; i<n; i++) {
  56. aux[i] = XOR();
  57. aux[i].a <== a[i];
  58. aux[i].b <== 1;
  59. }
  60. for (i=0; i<n; i++) {
  61. out[i] <== aux[i].out;
  62. }
  63. }
  64. template OrArray(n) {
  65. signal input a[n];
  66. signal input b[n];
  67. signal output out[n];
  68. var i;
  69. component aux[n];
  70. for (i=0; i<n; i++) {
  71. aux[i] = OR();
  72. aux[i].a <== a[i];
  73. aux[i].b <== b[i];
  74. }
  75. for (i=0; i<n; i++) {
  76. out[i] <== aux[i].out;
  77. }
  78. }
  79. template AndArray(n) {
  80. signal input a[n];
  81. signal input b[n];
  82. signal output out[n];
  83. var i;
  84. component aux[n];
  85. for (i=0; i<n; i++) {
  86. aux[i] = AND();
  87. aux[i].a <== a[i];
  88. aux[i].b <== b[i];
  89. }
  90. for (i=0; i<n; i++) {
  91. out[i] <== aux[i].out;
  92. }
  93. }
  94. template ShL(n, r) {
  95. signal input in[n];
  96. signal output out[n];
  97. for (var i=0; i<n; i++) {
  98. if (i < r) {
  99. out[i] <== 0;
  100. } else {
  101. out[i] <== in[ i-r ];
  102. }
  103. }
  104. }