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.

81 lines
1.7 KiB

  1. pragma circom 2.0.0;
  2. include "../node_modules/circomlib/circuits/gates.circom";
  3. include "../node_modules/circomlib/circuits/sha256/xor3.circom";
  4. include "../node_modules/circomlib/circuits/sha256/shift.circom"; // contains ShiftRight
  5. template Xor5(n) {
  6. signal input a[n];
  7. signal input b[n];
  8. signal input c[n];
  9. signal input d[n];
  10. signal input e[n];
  11. signal output out[n];
  12. var i;
  13. component xor3 = Xor3(n);
  14. for (i=0; i<n; i++) {
  15. xor3.a[i] <== a[i];
  16. xor3.b[i] <== b[i];
  17. xor3.c[i] <== c[i];
  18. }
  19. component xor4 = XorArray(n);
  20. for (i=0; i<n; i++) {
  21. xor4.a[i] <== xor3.out[i];
  22. xor4.b[i] <== d[i];
  23. }
  24. component xor5 = XorArray(n);
  25. for (i=0; i<n; i++) {
  26. xor5.a[i] <== xor4.out[i];
  27. xor5.b[i] <== e[i];
  28. }
  29. for (i=0; i<n; i++) {
  30. out[i] <== xor5.out[i];
  31. }
  32. }
  33. template XorArray(n) {
  34. signal input a[n];
  35. signal input b[n];
  36. signal output out[n];
  37. var i;
  38. component aux[n];
  39. for (i=0; i<n; i++) {
  40. aux[i] = XOR();
  41. aux[i].a <== a[i];
  42. aux[i].b <== b[i];
  43. }
  44. for (i=0; i<n; i++) {
  45. out[i] <== aux[i].out;
  46. }
  47. }
  48. template OrArray(n) {
  49. signal input a[n];
  50. signal input b[n];
  51. signal output out[n];
  52. var i;
  53. component aux[n];
  54. for (i=0; i<n; i++) {
  55. aux[i] = OR();
  56. aux[i].a <== a[i];
  57. aux[i].b <== b[i];
  58. }
  59. for (i=0; i<n; i++) {
  60. out[i] <== aux[i].out;
  61. }
  62. }
  63. template ShL(n, r) {
  64. signal input in[n];
  65. signal output out[n];
  66. for (var i=0; i<n; i++) {
  67. if (i < r) {
  68. out[i] <== 0;
  69. } else {
  70. out[i] <== in[ i-r ];
  71. }
  72. }
  73. }