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.

68 lines
1.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. /*
  2. Copyright 2018 0KIMS association.
  3. This file is part of circom (Zero Knowledge Circuit Compiler).
  4. circom is a free software: you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. circom is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with circom. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. include "xor3.circom";
  16. include "rotate.circom";
  17. include "shift.circom";
  18. template SmallSigma(ra, rb, rc) {
  19. signal input in[32];
  20. signal output out[32];
  21. component xor3 = Xor3(32);
  22. component rota = RotR(32, ra);
  23. component rotb = RotR(32, rb);
  24. component shrc = ShR(32, rc);
  25. for (var k=0; k<32; k++) {
  26. rota.in[k] <== in[k];
  27. rotb.in[k] <== in[k];
  28. shrc.in[k] <== in[k];
  29. xor3.a[k] <== rota.out[k];
  30. xor3.b[k] <== rotb.out[k];
  31. xor3.c[k] <== shrc.out[k];
  32. out[k] <== xor3.out[k];
  33. }
  34. }
  35. template BigSigma(ra, rb, rc) {
  36. signal input in[32];
  37. signal output out[32];
  38. component xor3 = Xor3(32);
  39. component rota = RotR(32, ra);
  40. component rotb = RotR(32, rb);
  41. component rotc = RotR(32, rc);
  42. for (var k=0; k<32; k++) {
  43. rota.in[k] <== in[k];
  44. rotb.in[k] <== in[k];
  45. rotc.in[k] <== in[k];
  46. xor3.a[k] <== rota.out[k];
  47. xor3.b[k] <== rotb.out[k];
  48. xor3.c[k] <== rotc.out[k];
  49. out[k] <== xor3.out[k];
  50. }
  51. }