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.

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