Skip to content

Commit

Permalink
sha256 tests updated to c
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaylina committed Dec 12, 2019
1 parent 8bd0fac commit d5bca9f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 62,374 deletions.
3 changes: 3 additions & 0 deletions circuits/sha256/sha256compression.circom
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ template Sha256compression() {
sigmaPlus[t-16].in7[k] <== w[t-7][k];
sigmaPlus[t-16].in15[k] <== w[t-15][k];
sigmaPlus[t-16].in16[k] <== w[t-16][k];
}

for (k=0; k<32; k++) {
w[t][k] <== sigmaPlus[t-16].out[k];
}
}
Expand Down
22 changes: 15 additions & 7 deletions circuits/sha256/sigma.circom
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,53 @@ include "shift.circom";
template SmallSigma(ra, rb, rc) {
signal input in[32];
signal output out[32];

component xor3 = Xor3(32);
var k;

component rota = RotR(32, ra);
component rotb = RotR(32, rb);
component shrc = ShR(32, rc);

for (var k=0; k<32; k++) {
for (k=0; k<32; k++) {
rota.in[k] <== in[k];
rotb.in[k] <== in[k];
shrc.in[k] <== in[k];
}

component xor3 = Xor3(32);
for (k=0; k<32; k++) {
xor3.a[k] <== rota.out[k];
xor3.b[k] <== rotb.out[k];
xor3.c[k] <== shrc.out[k];
}

for (k=0; k<32; k++) {
out[k] <== xor3.out[k];
}
}

template BigSigma(ra, rb, rc) {
signal input in[32];
signal output out[32];

component xor3 = Xor3(32);
var k;

component rota = RotR(32, ra);
component rotb = RotR(32, rb);
component rotc = RotR(32, rc);

for (var k=0; k<32; k++) {
for (k=0; k<32; k++) {
rota.in[k] <== in[k];
rotb.in[k] <== in[k];
rotc.in[k] <== in[k];
}

component xor3 = Xor3(32);

for (k=0; k<32; k++) {
xor3.a[k] <== rota.out[k];
xor3.b[k] <== rotb.out[k];
xor3.c[k] <== rotc.out[k];
}

for (k=0; k<32; k++) {
out[k] <== xor3.out[k];
}
}
10 changes: 7 additions & 3 deletions circuits/sha256/sigmaplus.circom
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ template SigmaPlus() {
signal input in15[32];
signal input in16[32];
signal output out[32];
var k;

component sum = BinSum(32, 4);
component sigma1 = SmallSigma(17,19,10);
component sigma0 = SmallSigma(7, 18, 3);

for (var k=0; k<32; k++) {
for (k=0; k<32; k++) {
sigma1.in[k] <== in2[k];
sigma0.in[k] <== in15[k];
}

component sum = BinSum(32, 4);
for (k=0; k<32; k++) {
sum.in[0][k] <== sigma1.out[k];
sum.in[1][k] <== in7[k];
sum.in[2][k] <== sigma0.out[k];
sum.in[3][k] <== in16[k];
}

for (k=0; k<32; k++) {
out[k] <== sum.out[k];
}
}
13 changes: 9 additions & 4 deletions circuits/sha256/t1.circom
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,28 @@ template T1() {
signal input w[32];
signal output out[32];

component sum = BinSum(32, 5);
component ch = Ch(32);
var ki;

component ch = Ch(32);
component bigsigma1 = BigSigma(6, 11, 25);

for (var ki=0; ki<32; ki++) {
for (ki=0; ki<32; ki++) {
bigsigma1.in[ki] <== e[ki];
ch.a[ki] <== e[ki];
ch.b[ki] <== f[ki];
ch.c[ki] <== g[ki]
ch.c[ki] <== g[ki];
}

component sum = BinSum(32, 5);
for (ki=0; ki<32; ki++) {
sum.in[0][ki] <== h[ki];
sum.in[1][ki] <== bigsigma1.out[ki];
sum.in[2][ki] <== ch.out[ki];
sum.in[3][ki] <== k[ki];
sum.in[4][ki] <== w[ki];
}

for (ki=0; ki<32; ki++) {
out[ki] <== sum.out[ki];
}
}
13 changes: 8 additions & 5 deletions circuits/sha256/t2.circom
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@ template T2() {
signal input b[32];
signal input c[32];
signal output out[32];

component sum = BinSum(32, 2);
var k;

component bigsigma0 = BigSigma(2, 13, 22);
component maj = Maj(32);

for (var k=0; k<32; k++) {

for (k=0; k<32; k++) {
bigsigma0.in[k] <== a[k];
maj.a[k] <== a[k];
maj.b[k] <== b[k];
maj.c[k] <== c[k];
}

component sum = BinSum(32, 2);

for (k=0; k<32; k++) {
sum.in[0][k] <== bigsigma0.out[k];
sum.in[1][k] <== maj.out[k];
}

for (k=0; k<32; k++) {
out[k] <== sum.out[k];
}
}
Loading

0 comments on commit d5bca9f

Please sign in to comment.