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.

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