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.

77 lines
1.9 KiB

  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. pragma circom 2.0.0;
  16. include "xor3.circom";
  17. include "rotate.circom";
  18. include "shift.circom";
  19. template SmallSigma(ra, rb, rc) {
  20. signal input in[32];
  21. signal output out[32];
  22. var k;
  23. component rota = RotR(32, ra);
  24. component rotb = RotR(32, rb);
  25. component shrc = ShR(32, rc);
  26. for (k=0; k<32; k++) {
  27. rota.in[k] <== in[k];
  28. rotb.in[k] <== in[k];
  29. shrc.in[k] <== in[k];
  30. }
  31. component xor3 = Xor3(32);
  32. for (k=0; k<32; k++) {
  33. xor3.a[k] <== rota.out[k];
  34. xor3.b[k] <== rotb.out[k];
  35. xor3.c[k] <== shrc.out[k];
  36. }
  37. for (k=0; k<32; k++) {
  38. out[k] <== xor3.out[k];
  39. }
  40. }
  41. template BigSigma(ra, rb, rc) {
  42. signal input in[32];
  43. signal output out[32];
  44. var k;
  45. component rota = RotR(32, ra);
  46. component rotb = RotR(32, rb);
  47. component rotc = RotR(32, rc);
  48. for (k=0; k<32; k++) {
  49. rota.in[k] <== in[k];
  50. rotb.in[k] <== in[k];
  51. rotc.in[k] <== in[k];
  52. }
  53. component xor3 = Xor3(32);
  54. for (k=0; k<32; k++) {
  55. xor3.a[k] <== rota.out[k];
  56. xor3.b[k] <== rotb.out[k];
  57. xor3.c[k] <== rotc.out[k];
  58. }
  59. for (k=0; k<32; k++) {
  60. out[k] <== xor3.out[k];
  61. }
  62. }