circomlib/circuits/sha256/sigma.circom
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*/
19
20include "xor3.circom";
21include "rotate.circom";
22include "shift.circom";
23
24template SmallSigma(ra, rb, rc) {
25 signal input in[32];
26 signal output out[32];
27
28 component xor3 = Xor3(32);
29
30 component rota = RotR(32, ra);
31 component rotb = RotR(32, rb);
32 component shrc = ShR(32, rc);
33
34 for (var 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 xor3.a[k] <== rota.out[k];
40 xor3.b[k] <== rotb.out[k];
41 xor3.c[k] <== shrc.out[k];
42
43 out[k] <== xor3.out[k];
44 }
45}
46
47template BigSigma(ra, rb, rc) {
48 signal input in[32];
49 signal output out[32];
50
51 component xor3 = Xor3(32);
52
53 component rota = RotR(32, ra);
54 component rotb = RotR(32, rb);
55 component rotc = RotR(32, rc);
56
57 for (var k=0; k<32; k++) {
58 rota.in[k] <== in[k];
59 rotb.in[k] <== in[k];
60 rotc.in[k] <== in[k];
61
62 xor3.a[k] <== rota.out[k];
63 xor3.b[k] <== rotb.out[k];
64 xor3.c[k] <== rotc.out[k];
65
66 out[k] <== xor3.out[k];
67 }
68}