grapevine-sonobe/circom/node_modules/circomlib/circuits/sha256/sha256_2.circom
circom/node_modules/circomlib/circuits/sha256/sha256_2.circomRaw
1/*
2 Copyright 2018 0KIMS association.
3
4 This file is part of circom (Zero Knowledge Circuit Compiler).
5
6 circom is a free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 circom is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with circom. If not, see <https://www.gnu.org/licenses/>.
18*/
19pragma circom 2.0.0;
20
21include "constants.circom";
22include "sha256compression.circom";
23include "../bitify.circom";
24
25template Sha256_2() {
26 signal input a;
27 signal input b;
28 signal output out;
29
30 var i;
31 var k;
32
33 component bits2num = Bits2Num(216);
34 component num2bits[2];
35
36 num2bits[0] = Num2Bits(216);
37 num2bits[1] = Num2Bits(216);
38
39 num2bits[0].in <== a;
40 num2bits[1].in <== b;
41
42
43 component sha256compression = Sha256compression() ;
44
45 component ha0 = H(0);
46 component hb0 = H(1);
47 component hc0 = H(2);
48 component hd0 = H(3);
49 component he0 = H(4);
50 component hf0 = H(5);
51 component hg0 = H(6);
52 component hh0 = H(7);
53
54 for (k=0; k<32; k++ ) {
55 sha256compression.hin[0*32+k] <== ha0.out[k];
56 sha256compression.hin[1*32+k] <== hb0.out[k];
57 sha256compression.hin[2*32+k] <== hc0.out[k];
58 sha256compression.hin[3*32+k] <== hd0.out[k];
59 sha256compression.hin[4*32+k] <== he0.out[k];
60 sha256compression.hin[5*32+k] <== hf0.out[k];
61 sha256compression.hin[6*32+k] <== hg0.out[k];
62 sha256compression.hin[7*32+k] <== hh0.out[k];
63 }
64
65 for (i=0; i<216; i++) {
66 sha256compression.inp[i] <== num2bits[0].out[215-i];
67 sha256compression.inp[i+216] <== num2bits[1].out[215-i];
68 }
69
70 sha256compression.inp[432] <== 1;
71
72 for (i=433; i<503; i++) {
73 sha256compression.inp[i] <== 0;
74 }
75
76 sha256compression.inp[503] <== 1;
77 sha256compression.inp[504] <== 1;
78 sha256compression.inp[505] <== 0;
79 sha256compression.inp[506] <== 1;
80 sha256compression.inp[507] <== 1;
81 sha256compression.inp[508] <== 0;
82 sha256compression.inp[509] <== 0;
83 sha256compression.inp[510] <== 0;
84 sha256compression.inp[511] <== 0;
85
86 for (i=0; i<216; i++) {
87 bits2num.in[i] <== sha256compression.out[255-i];
88 }
89
90 out <== bits2num.out;
91}