circom/circuits/sha256/ch.circom
circuits/sha256/ch.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
20/* Ch
21
22000 0
23001 1
24010 0
25011 1
26100 0
27101 0
28110 1
29111 1
30
31out = a&b ^ (!a)&c =>
32
33out = a*(b-c) + c
34
35*/
36
37template Ch(n) {
38 signal input a[n];
39 signal input b[n];
40 signal input c[n];
41 signal output out[n];
42
43 for (var k=0; k<n; k++) {
44 out[k] <== a[k] * (b[k]-c[k]) + c[k];
45 }
46}