arnaucube
arnaucube/keccak256-circomPublic Self-hosted repository
keccak256-circom/circuits/utils.circom
circuits/utils.circomRaw
  1pragma circom 2.0.0;
  2
  3include "../node_modules/circomlib/circuits/gates.circom";
  4include "../node_modules/circomlib/circuits/sha256/xor3.circom";
  5include "../node_modules/circomlib/circuits/sha256/shift.circom"; // contains ShiftRight
  6
  7template Xor5(n) {
  8    signal input a[n];
  9    signal input b[n];
 10    signal input c[n];
 11    signal input d[n];
 12    signal input e[n];
 13    signal output out[n];
 14    var i;
 15    
 16    component xor3 = Xor3(n);
 17    for (i=0; i<n; i++) {
 18        xor3.a[i] <== a[i];
 19        xor3.b[i] <== b[i];
 20        xor3.c[i] <== c[i];
 21    }
 22    component xor4 = XorArray(n);
 23    for (i=0; i<n; i++) {
 24        xor4.a[i] <== xor3.out[i];
 25        xor4.b[i] <== d[i];
 26    }
 27    component xor5 = XorArray(n);
 28    for (i=0; i<n; i++) {
 29        xor5.a[i] <== xor4.out[i];
 30        xor5.b[i] <== e[i];
 31    }
 32    for (i=0; i<n; i++) {
 33        out[i] <== xor5.out[i];
 34    }
 35}
 36
 37template XorArray(n) {
 38    signal input a[n];
 39    signal input b[n];
 40    signal output out[n];
 41    var i;
 42
 43    component aux[n];
 44    for (i=0; i<n; i++) {
 45        aux[i] = XOR();
 46        aux[i].a <== a[i];
 47        aux[i].b <== b[i];
 48    }
 49    for (i=0; i<n; i++) {
 50        out[i] <== aux[i].out;
 51    }
 52}
 53
 54template XorArraySingle(n) {
 55    signal input a[n];
 56    signal output out[n];
 57    var i;
 58
 59    component aux[n];
 60    for (i=0; i<n; i++) {
 61        aux[i] = XOR();
 62        aux[i].a <== a[i];
 63        aux[i].b <== 1;
 64    }
 65    for (i=0; i<n; i++) {
 66        out[i] <== aux[i].out;
 67    }
 68}
 69
 70template OrArray(n) {
 71    signal input a[n];
 72    signal input b[n];
 73    signal output out[n];
 74    var i;
 75
 76    component aux[n];
 77    for (i=0; i<n; i++) {
 78        aux[i] = OR();
 79        aux[i].a <== a[i];
 80        aux[i].b <== b[i];
 81    }
 82    for (i=0; i<n; i++) {
 83        out[i] <== aux[i].out;
 84    }
 85}
 86
 87template AndArray(n) {
 88    signal input a[n];
 89    signal input b[n];
 90    signal output out[n];
 91    var i;
 92
 93    component aux[n];
 94    for (i=0; i<n; i++) {
 95        aux[i] = AND();
 96        aux[i].a <== a[i];
 97        aux[i].b <== b[i];
 98    }
 99    for (i=0; i<n; i++) {
100        out[i] <== aux[i].out;
101    }
102}
103
104template ShL(n, r) {
105    signal input in[n];
106    signal output out[n];
107
108    for (var i=0; i<n; i++) {
109        if (i < r) {
110            out[i] <== 0;
111        } else {
112            out[i] <== in[ i-r ];
113        }
114    }
115}