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.

91 lines
2.6 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 "constants.circom";
  17. include "sha256compression.circom";
  18. include "../bitify.circom";
  19. template Sha256_2() {
  20. signal input a;
  21. signal input b;
  22. signal output out;
  23. var i;
  24. var k;
  25. component bits2num = Bits2Num(216);
  26. component num2bits[2];
  27. num2bits[0] = Num2Bits(216);
  28. num2bits[1] = Num2Bits(216);
  29. num2bits[0].in <== a;
  30. num2bits[1].in <== b;
  31. component sha256compression = Sha256compression() ;
  32. component ha0 = H(0);
  33. component hb0 = H(1);
  34. component hc0 = H(2);
  35. component hd0 = H(3);
  36. component he0 = H(4);
  37. component hf0 = H(5);
  38. component hg0 = H(6);
  39. component hh0 = H(7);
  40. for (k=0; k<32; k++ ) {
  41. sha256compression.hin[0*32+k] <== ha0.out[k];
  42. sha256compression.hin[1*32+k] <== hb0.out[k];
  43. sha256compression.hin[2*32+k] <== hc0.out[k];
  44. sha256compression.hin[3*32+k] <== hd0.out[k];
  45. sha256compression.hin[4*32+k] <== he0.out[k];
  46. sha256compression.hin[5*32+k] <== hf0.out[k];
  47. sha256compression.hin[6*32+k] <== hg0.out[k];
  48. sha256compression.hin[7*32+k] <== hh0.out[k];
  49. }
  50. for (i=0; i<216; i++) {
  51. sha256compression.inp[i] <== num2bits[0].out[215-i];
  52. sha256compression.inp[i+216] <== num2bits[1].out[215-i];
  53. }
  54. sha256compression.inp[432] <== 1;
  55. for (i=433; i<503; i++) {
  56. sha256compression.inp[i] <== 0;
  57. }
  58. sha256compression.inp[503] <== 1;
  59. sha256compression.inp[504] <== 1;
  60. sha256compression.inp[505] <== 0;
  61. sha256compression.inp[506] <== 1;
  62. sha256compression.inp[507] <== 1;
  63. sha256compression.inp[508] <== 0;
  64. sha256compression.inp[509] <== 0;
  65. sha256compression.inp[510] <== 0;
  66. sha256compression.inp[511] <== 0;
  67. for (i=0; i<216; i++) {
  68. bits2num.in[i] <== sha256compression.out[255-i];
  69. }
  70. out <== bits2num.out;
  71. }