arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/circuits/sha256/sha256_2.circom
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*/
19
20include "sha256compression.circom";
21include "../bitify.circom"
22
23template Sha256_2() {
24    signal input a;
25    signal input b;
26    signal output out;
27
28    component bits2num = Bits2Num(216);
29    component num2bits[2];
30
31    num2bits[0] = Num2Bits(216);
32    num2bits[1] = Num2Bits(216);
33
34    num2bits[0].in <== a;
35    num2bits[1].in <== b;
36
37    component sha256compression = Sha256compression() ;
38
39    var i;
40
41    for (i=0; i<216; i++) {
42        sha256compression.inp[i] <== num2bits[0].out[215-i];
43        sha256compression.inp[i+216] <== num2bits[1].out[215-i];
44    }
45
46    sha256compression.inp[432] <== 1;
47
48    for (i=433; i<503; i++) {
49        sha256compression.inp[i] <== 0;
50    }
51
52    sha256compression.inp[503] <== 1;
53    sha256compression.inp[504] <== 1;
54    sha256compression.inp[505] <== 0;
55    sha256compression.inp[506] <== 1;
56    sha256compression.inp[507] <== 1;
57    sha256compression.inp[508] <== 0;
58    sha256compression.inp[509] <== 0;
59    sha256compression.inp[510] <== 0;
60    sha256compression.inp[511] <== 0;
61
62    for (i=0; i<216; i++) {
63        bits2num.in[i] <== sha256compression.out[255-i];
64    }
65
66    out <== bits2num.out;
67}