Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BasedOnStyle: LLVM

IndentWidth: 4
TabWidth: 4
UseTab: Never

ColumnLimit: 100
BreakBeforeBraces: Allman
PointerAlignment: Left

SpaceAfterCStyleCast: true
SpacesInParentheses: false
SpaceBeforeParens: ControlStatements

AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CARM = arm-linux-gnueabihf-gcc
COMMON = src/$(MAIN).c -o $(OUT) -std=gnu99 -Ofast -Wno-unused-result -Wno-pointer-sign
MCLPATH = ../mcl
GMPPATH = /usr/local
LIB = $(MCLPATH)/lib/libmclbn384_256.a $(MCLPATH)/lib/libmcl.a -I $(MCLPATH)/include -lgmp -lcunit -lm -lstdc++
LIB = $(MCLPATH)/lib/lishe384_256.a $(MCLPATH)/lib/libmcl.a -I $(MCLPATH)/include -lgmp -lcunit -lm -lstdc++
LIBMAC = /opt/homebrew/lib/libgmp.a /opt/homebrew/opt/libomp/lib/libomp.a /opt/homebrew/opt/cunit/lib/libcunit.a $(MCLPATH)/lib/libmclbn384_256.a $(MCLPATH)/lib/libmcl.a -I /opt/homebrew/opt/libomp/include -I /opt/homebrew/include -I $(MCLPATH)/include -lm -lstdc++
LIBCROSS = $(MCLPATH)/lib/libmclbn384_256.a $(MCLPATH)/lib/libmcl.a $(GMPPATH)/lib/libgmp.a -I $(MCLPATH)/include -I $(GMPPATH)/include -lstdc++
SRC = $(shell pwd)/src/*.c $(shell pwd)/circuits/*.c $(shell pwd)/src/*.h
Expand Down
76 changes: 38 additions & 38 deletions circuits/eddsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,58 @@
#include "mimc.c"
#include "utils.c"

void verify_eddsa(eddsa_signature edsig, point B, point A, char *msg)
void verify_eddsa(eddsa_signature edsig, point B, point A, char* msg)
{
element out[4];
element out[4];

for (int i = 0; i < 4; ++i)
{
init(&out[i]);
}
for (int i = 0; i < 4; ++i)
{
init(&out[i]);
}

element outPrivate[3];
init_array(outPrivate, 3);
element outPrivate[3];
init_array(outPrivate, 3);

element Bx, By;
init(&Bx);
init(&By);
element Bx, By;
init(&Bx);
init(&By);

input(&Bx, B.x);
input(&By, B.y);
input(&Bx, B.x);
input(&By, B.y);

int arraySize = 5;
element ram[arraySize];
init_array(ram, arraySize);

input(&ram[0], edsig.R.x);
input(&ram[1], edsig.R.y);
input(&ram[2], A.x);
input(&ram[3], A.y);
input(&ram[4], msg);
int arraySize = 5;
element ram[arraySize];
init_array(ram, arraySize);

element signature;
init(&signature);
input(&signature, edsig.S);
input(&ram[0], edsig.R.x);
input(&ram[1], edsig.R.y);
input(&ram[2], A.x);
input(&ram[3], A.y);
input(&ram[4], msg);

multi_hash(outPrivate[0], ram, 5);
element signature;
init(&signature);
input(&signature, edsig.S);

int size = 254;
element hBits[size];
element sBits[size];
multi_hash(outPrivate[0], ram, 5);

init_array(hBits, size);
init_array(sBits, size);
int size = 254;
element hBits[size];
element sBits[size];

to_bits(hBits, outPrivate[0], size);
to_bits(sBits, signature, size-1);
init_array(hBits, size);
init_array(sBits, size);

mul_scalar(outPrivate[1], outPrivate[2], ram[2], ram[3], hBits, size);
add(out[0], out[1], outPrivate[1], outPrivate[2], ram[0], ram[1]);
to_bits(hBits, outPrivate[0], size);
to_bits(sBits, signature, size - 1);

mul_scalar(out[2], out[3], Bx, By, sBits, size-1);
mul_scalar(outPrivate[1], outPrivate[2], ram[2], ram[3], hBits, size);
add(out[0], out[1], outPrivate[1], outPrivate[2], ram[0], ram[1]);

assert_equal(&out[2], &out[0]);
assert_equal(&out[3], &out[1]);
mul_scalar(out[2], out[3], Bx, By, sBits, size - 1);

assert_equal(&out[2], &out[0]);
assert_equal(&out[3], &out[1]);
}

#endif
72 changes: 38 additions & 34 deletions circuits/mimc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,54 @@

#define NROUNDS 91

void mimc7(element *h, element *x_in, element *k)
void mimc7(element* h, element* x_in, element* k)
{
element r[NROUNDS];
element f[NROUNDS*3];
element r[NROUNDS];
element f[NROUNDS * 3];

init_array(r, NROUNDS);
init_array(f, NROUNDS*3);
init_array(r, NROUNDS);
init_array(f, NROUNDS * 3);

int it = 0;
int it = 0;

for (int i = 0; i < NROUNDS; i++)
{
if (i == 0) addmuladd(&f[it], k, x_in, k, x_in);
else add3muladd3(&f[it], k, &r[i-1], &c_mimc[i], k, &r[i-1], &c_mimc[i]);
for (int i = 0; i < NROUNDS; i++)
{
if (i == 0)
addmuladd(&f[it], k, x_in, k, x_in);
else
add3muladd3(&f[it], k, &r[i - 1], &c_mimc[i], k, &r[i - 1], &c_mimc[i]);

mul(&f[it+1], &f[it], &f[it]);
mul(&f[it+2], &f[it+1], &f[it]);
if (i == 0) addmul(&r[i], k, x_in, &f[it+2]);
else add3mul(&r[i], k, &r[i-1], &c_mimc[i], &f[it+2]);
mul(&f[it + 1], &f[it], &f[it]);
mul(&f[it + 2], &f[it + 1], &f[it]);
if (i == 0)
addmul(&r[i], k, x_in, &f[it + 2]);
else
add3mul(&r[i], k, &r[i - 1], &c_mimc[i], &f[it + 2]);

it = it + 3;
}
it = it + 3;
}

addmul(h, k, &r[NROUNDS-1], &one);
addmul(h, k, &r[NROUNDS - 1], &one);
}

void multi_hash(element h, element *x_in, int arraySize)
void multi_hash(element h, element* x_in, int arraySize)
{
element k[arraySize];
init_array(k, arraySize);
input(&k[0], "0");

for (int i = 0; i < arraySize-1; i++)
{
element hf;
init(&hf);
mimc7(&hf, &x_in[i], &k[i]);
add3mul(&k[i+1], &x_in[i], &k[i], &hf, &one);
}

element hf;
init(&hf);
mimc7(&hf, &x_in[arraySize-1], &k[arraySize-1]);
add3mul(&h, &x_in[arraySize-1], &k[arraySize-1], &hf, &one);
element k[arraySize];
init_array(k, arraySize);
input(&k[0], "0");

for (int i = 0; i < arraySize - 1; i++)
{
element hf;
init(&hf);
mimc7(&hf, &x_in[i], &k[i]);
add3mul(&k[i + 1], &x_in[i], &k[i], &hf, &one);
}

element hf;
init(&hf);
mimc7(&hf, &x_in[arraySize - 1], &k[arraySize - 1]);
add3mul(&h, &x_in[arraySize - 1], &k[arraySize - 1], &hf, &one);
}

#endif
Loading