Skip to content

Commit a0768df

Browse files
working in EncCstrnts
1 parent ad542f4 commit a0768df

File tree

1 file changed

+51
-16
lines changed

1 file changed

+51
-16
lines changed

faest_aes.c

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static void aes_key_schedule_constraints_Mkey_0_128(const uint8_t* w, const bf12
760760
}
761761

762762

763-
static void aes_inverse_affine(uint8_t* y, bf128_t* y_tag, uint8_t x, bf128_t* x_tag, bool isprover, bf128_t delta) {
763+
static void aes_128_inverse_affine(uint8_t* y, bf128_t* y_tag, uint8_t x, bf128_t* x_tag, bool isprover, bf128_t delta) {
764764

765765
if (isprover) {
766766
y[0] = (rotr8(x, 7) ^ rotr8(x, 5) ^ rotr8(x, 2)) ^ 0x05; // the compressed form
@@ -778,8 +778,7 @@ static void aes_inverse_affine(uint8_t* y, bf128_t* y_tag, uint8_t x, bf128_t* x
778778
}
779779
}
780780

781-
782-
static void aes_keyexp_backward(uint8_t* y, bf128_t* y_tag, const uint8_t* x, const bf128_t* x_tag, uint8_t* key, bf128_t* key_tag,
781+
static void aes_128_keyexp_backward(uint8_t* y, bf128_t* y_tag, const uint8_t* x, const bf128_t* x_tag, uint8_t* key, bf128_t* key_tag,
783782
const faest_paramset_t* params, bool isprover, bf128_t delta) {
784783

785784
const unsigned int lambda = params->faest_param.lambda;
@@ -837,7 +836,7 @@ static void aes_keyexp_backward(uint8_t* y, bf128_t* y_tag, const uint8_t* x, co
837836
}
838837
}
839838

840-
static void aes_keyexp_forward(uint8_t* y, bf128_t* y_tag, const uint8_t* w, const bf128_t* w_tag,
839+
static void aes_128_keyexp_forward(uint8_t* y, bf128_t* y_tag, const uint8_t* w, const bf128_t* w_tag,
841840
const faest_paramset_t* params, bool isprover, bf128_t delta) {
842841

843842
unsigned int lambda = params->faest_param.lambda;
@@ -888,8 +887,7 @@ static void aes_keyexp_forward(uint8_t* y, bf128_t* y_tag, const uint8_t* w, con
888887
}
889888
}
890889

891-
892-
static void aes_expkey_constraints(bf128_t* z0, bf128_t* z1, const uint8_t* w, const bf128_t* w_tag,
890+
static void aes_128_expkey_constraints(bf128_t* z0, bf128_t* z1, uint8_t* k, bf128_t* k_tag, const uint8_t* w, const bf128_t* w_tag,
893891
const faest_paramset_t* params, bool isprover, bf128_t delta) {
894892

895893

@@ -899,13 +897,11 @@ static void aes_expkey_constraints(bf128_t* z0, bf128_t* z1, const uint8_t* w, c
899897
unsigned int Nk = lambda/32;
900898

901899
// ::1
902-
uint8_t k[(R+1)*lambda/8];
903-
bf128_t k_tag[(R+1)*lambda];
904-
aes_keyexp_forward(k, k_tag, w, w_tag, params, isprover, delta);
900+
aes_128_keyexp_forward(k, k_tag, w, w_tag, params, isprover, delta);
905901
// ::2
906902
uint8_t w_flat[Ske];
907903
bf128_t w_flat_tag[8*Ske];
908-
aes_keyexp_backward(w_flat, w_flat_tag, w, w_tag, k, k_tag, params, isprover, delta);
904+
aes_128_keyexp_backward(w_flat, w_flat_tag, w, w_tag, k, k_tag, params, isprover, delta);
909905

910906
// ::3-5
911907
unsigned int iwd = 32*(Nk - 1); // as 1 unit8 has 8 bits
@@ -959,13 +955,20 @@ static void aes_expkey_constraints(bf128_t* z0, bf128_t* z1, const uint8_t* w, c
959955

960956
}
961957

962-
static void aes_deg2to3(bf128_t* z0, bf128_t* z1, uint8_t val, bf128_t tag, bool isprover, bf128_t delta) {
958+
static aes_128_enc_constraints(bf128_t* z0, bf128_t* z1, uint8_t* owf_in, bf128_t* owf_in_tag,
959+
uint8_t* owf_out, bf128_t* owf_out_tag, uint8_t* w,
960+
bf128_t* w_tag, uint8_t* k, bf128_t* k_tag,
961+
const faest_paramset_t* params, bool isprover, bf128_t delta) {
962+
963+
964+
}
965+
966+
static void aes_128_deg2to3(bf128_t* z0, bf128_t* z1, bf128_t val, bf128_t tag, bool isprover, bf128_t delta) {
963967
if(isprover) {
964-
// TODO: do we lift here with generator, most likely yes, better confirm later
965-
z0[0] = bf128_byte_combine_bits(val);
966-
z1[1] = tag;
968+
z0[0] = val;
969+
z1[0] = tag;
967970
} else {
968-
z0[0] = bf128_mul(bf128_byte_combine_bits(val), delta);
971+
// verifier does not have tag
969972
z1[0] = bf128_mul(tag, delta);
970973
}
971974
}
@@ -986,6 +989,12 @@ static void constant_to_vole_128(bf128_t* tag, const uint8_t* val, bool isprover
986989

987990
static void aes_constraints_128(bf128_t* z0, bf128_t* z1, const uint8_t* w, const bf128_t* w_tag, const uint8_t* owf_in, const uint8_t* owf_out, const faest_paramset_t* params, bool isprover, bf128_t delta) {
988991

992+
unsigned int lambda = params->faest_param.lambda;
993+
unsigned int R = params->faest_param.R;
994+
unsigned int Ske = params->faest_param.Ske;
995+
unsigned int Lke = lambda + 8*Ske;
996+
unsigned int Lenc = params->faest_param.Lenc;
997+
unsigned int Senc = params->faest_param.Senc;
989998
// ::1-3 owf_in, owf_out, z and z_tag
990999

9911000
// ::4-5
@@ -1000,9 +1009,35 @@ static void aes_constraints_128(bf128_t* z0, bf128_t* z1, const uint8_t* w, cons
10001009
constant_to_vole_128(owf_out_tag, owf_out, true, bf128_one());
10011010

10021011
// ::15 skiped as B = 1
1003-
10041012
// ::16
1013+
bf128_t z_tilde_0_expkey[FAEST_128F_Ske / 4 + 2*4];
1014+
bf128_t z_tilde_1_expkey[FAEST_128F_Ske / 4 + 2*4];
1015+
uint8_t k[(R+1)*lambda/8];
1016+
bf128_t k_tag[(R+1)*lambda];
1017+
// if isprover == true, z_tilde_0 will be empty after aes_128_expkey_constraints() returns
1018+
aes_128_expkey_constraints(z_tilde_0_expkey, z_tilde_1_expkey, k, k_tag, w, w_tag, params, isprover, delta);
10051019

1020+
// ::17
1021+
for (unsigned int i = 0; i < FAEST_128F_Ske / 4 + 2*4; i++) {
1022+
aes_128_deg2to3(z0 + 1+i, z1 + 1+i, z_tilde_0_expkey[i], z_tilde_1_expkey[i], isprover, delta);
1023+
}
1024+
1025+
// ::18 b = 0
1026+
// ::19
1027+
uint8_t w_tilde[Lenc/8];
1028+
bf128_t w_tilde_tag[Lenc];
1029+
for (unsigned int i = 0; i < Lenc/8; i++) { // can also do a memcpy
1030+
w_tilde[i] = w[Lke/8 + i]; // copying 8 bits at a time
1031+
}
1032+
for (unsigned int i = 0; i < Lenc; i++) {
1033+
w_tilde_tag[i] = w_tag[Lke + i]; // copying 1 bit's tag at a time
1034+
}
1035+
// ::20 not needed for aes128
1036+
// ::21
1037+
bf128_t z_tilde_0[Senc];
1038+
1039+
aes_128_enc_constraints();
1040+
10061041

10071042

10081043
// TODO: From where we call the key contrainst and the enc constraints

0 commit comments

Comments
 (0)