arnaucube
arnaucube/grapevine-sonobePublic Self-hosted repository
grapevine-sonobe/circom/node_modules/circomlib/circuits/sha256/sigma.circom
circom/node_modules/circomlib/circuits/sha256/sigma.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 "xor3.circom";
22include "rotate.circom";
23include "shift.circom";
24
25template SmallSigma(ra, rb, rc) {
26    signal input in[32];
27    signal output out[32];
28    var k;
29
30    component rota = RotR(32, ra);
31    component rotb = RotR(32, rb);
32    component shrc = ShR(32, rc);
33
34    for (k=0; k<32; k++) {
35        rota.in[k] <== in[k];
36        rotb.in[k] <== in[k];
37        shrc.in[k] <== in[k];
38    }
39
40    component xor3 = Xor3(32);
41    for (k=0; k<32; k++) {
42        xor3.a[k] <== rota.out[k];
43        xor3.b[k] <== rotb.out[k];
44        xor3.c[k] <== shrc.out[k];
45    }
46
47    for (k=0; k<32; k++) {
48        out[k] <== xor3.out[k];
49    }
50}
51
52template BigSigma(ra, rb, rc) {
53    signal input in[32];
54    signal output out[32];
55    var k;
56
57    component rota = RotR(32, ra);
58    component rotb = RotR(32, rb);
59    component rotc = RotR(32, rc);
60    for (k=0; k<32; k++) {
61        rota.in[k] <== in[k];
62        rotb.in[k] <== in[k];
63        rotc.in[k] <== in[k];
64    }
65
66    component xor3 = Xor3(32);
67
68    for (k=0; k<32; k++) {
69        xor3.a[k] <== rota.out[k];
70        xor3.b[k] <== rotb.out[k];
71        xor3.c[k] <== rotc.out[k];
72    }
73
74    for (k=0; k<32; k++) {
75        out[k] <== xor3.out[k];
76    }
77}