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 var k;
28
29 component rota = RotR(32, ra);
30 component rotb = RotR(32, rb);
31 component shrc = ShR(32, rc);
32
33 for (k=0; k<32; k++) {
34 rota.in[k] <== in[k];
35 rotb.in[k] <== in[k];
36 shrc.in[k] <== in[k];
37 }
38
39 component xor3 = Xor3(32);
40 for (k=0; k<32; k++) {
41 xor3.a[k] <== rota.out[k];
42 xor3.b[k] <== rotb.out[k];
43 xor3.c[k] <== shrc.out[k];
44 }
45
46 for (k=0; k<32; k++) {
47 out[k] <== xor3.out[k];
48 }
49}
50
51template BigSigma(ra, rb, rc) {
52 signal input in[32];
53 signal output out[32];
54 var k;
55
56 component rota = RotR(32, ra);
57 component rotb = RotR(32, rb);
58 component rotc = RotR(32, rc);
59 for (k=0; k<32; k++) {
60 rota.in[k] <== in[k];
61 rotb.in[k] <== in[k];
62 rotc.in[k] <== in[k];
63 }
64
65 component xor3 = Xor3(32);
66
67 for (k=0; k<32; k++) {
68 xor3.a[k] <== rota.out[k];
69 xor3.b[k] <== rotb.out[k];
70 xor3.c[k] <== rotc.out[k];
71 }
72
73 for (k=0; k<32; k++) {
74 out[k] <== xor3.out[k];
75 }
76}