Skip to content

Commit 369bb2b

Browse files
aes128prover patched, working on aes128verifier
1 parent ed89ba9 commit 369bb2b

File tree

1 file changed

+66
-33
lines changed

1 file changed

+66
-33
lines changed

faest_aes.c

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -907,52 +907,85 @@ static void aes_enc_constraints_Mkey_1_128(const uint8_t* in, const uint8_t* out
907907
}
908908
}
909909

910-
static void aes_prove_128(const uint8_t* w, const uint8_t* u, uint8_t** V, const uint8_t* owf_in,
911-
const uint8_t* owf_out, const uint8_t* chall_2, uint8_t* a0_tilde,
912-
uint8_t* a12_tilde, const faest_paramset_t* params) {
910+
911+
static void aes_constraints(bf128_t* z, bf128_t* z_tag, const uint8_t* w, const bf128_t* w_tag, const uint8_t* owf_in, const uint8_t* owf_out, const faest_paramset_t* params) {
912+
913+
// TODO: From where we call the key contrainst and the enc constraints
914+
915+
// TODO: putting all this here for now
916+
// uint8_t* k = malloc((FAEST_128F_R + 1) * 128 / 8);
917+
// bf128_t* vk = faest_aligned_alloc(BF128_ALIGN, sizeof(bf128_t) * ((FAEST_128F_R + 1) * 128));
918+
// zk_hash_128_ctx a0_ctx;
919+
// zk_hash_128_ctx a1_ctx;
920+
// zk_hash_128_init(&a0_ctx, chall_2);
921+
// zk_hash_128_init(&a1_ctx, chall_2);
922+
923+
// aes_key_schedule_constraints_Mkey_0_128(w, bf_v, &a0_ctx, &a1_ctx, k, vk, params);
924+
925+
// Step: Skipping 8 in implementation
926+
// Step: 9
927+
928+
// Step: 10,11
929+
// aes_enc_constraints_Mkey_0_128(in, out, w + FAEST_128F_Lke / 8, bf_v + FAEST_128F_Lke, k, vk, &a0_ctx, &a1_ctx);
930+
// Step: 12 (beta == 1)
931+
// faest_aligned_free(vk);
932+
// free(k);
933+
// faest_aligned_free(bf_v);
934+
935+
}
936+
937+
static void aes_prove_128(bf128_t* a0_tilde, bf128_t* a1_tilde, bf128_t* a2_tilde, const uint8_t* w, const uint8_t* u,
938+
uint8_t** V, const uint8_t* owf_in, const uint8_t* owf_out, const uint8_t* chall_2, const faest_paramset_t* params) {
913939

914940
unsigned int lambda = params->faest_param.lambda;
915941
unsigned int lambda_bytes = lambda / 8;
916-
917-
// ::1-2
942+
unsigned int ske = params->faest_param.Ske;
943+
unsigned int senc = params->faest_param.Senc;
944+
// TODO: CHANGE THIS FOR OTHER SETTING WHEN COPY PASTING!!!!!
945+
unsigned int beta = 1;
946+
unsigned int c = 2*ske + (3/2)*senc + 1;
947+
948+
// ::1-5
949+
// also includes the lifting of V at ::5
918950
bf128_t* bf_v = column_to_row_major_and_shrink_V_128(V, FAEST_128F_ELL); // This is the mac for w
919951
// we have w in its f2 form
920952

921-
// ::3-6 embed VOLE masks
922-
bf128_t bf_u_0 = bf128_load(u);
923-
bf128_t bf_u_1 = bf128_load(u + lambda_bytes);
953+
// ::6-9 embed VOLE masks
954+
bf128_t bf_u_star_0 = bf128_load(u);
955+
bf128_t bf_u_star_1 = bf128_load(u + lambda);
956+
bf128_t bf_v_star_0 = bf128_sum_poly(bf_v);
957+
bf128_t bf_v_star_1 = bf128_sum_poly(bf_v + lambda);
924958

925-
// Step: 1..2
926-
959+
// ::10-12
960+
bf128_t bf_z[c*3];
961+
bf128_t bf_z_tag[c*3];
962+
aes_constraints(bf_z, bf_z_tag, w, bf_v, owf_in, owf_out, params);
927963

928-
// Step: 3..4
929-
// do nothing
930-
// Step: 6
964+
// ::13
965+
bf128_t a0[c];
966+
bf128_t a1[c];
967+
bf128_t a2[c];
968+
// TODO: the magical parsing, asked Peter already
931969

932-
// Step: 7 + 18
933-
uint8_t* k = malloc((FAEST_128F_R + 1) * 128 / 8);
934-
bf128_t* vk = faest_aligned_alloc(BF128_ALIGN, sizeof(bf128_t) * ((FAEST_128F_R + 1) * 128));
970+
// Step: 16..18
935971
zk_hash_128_ctx a0_ctx;
936972
zk_hash_128_ctx a1_ctx;
973+
zk_hash_128_ctx a2_ctx;
974+
zk_hash_128_init(&a0_ctx, chall_2);
975+
zk_hash_128_init(&a1_ctx, chall_2);
976+
zk_hash_128_init(&a2_ctx, chall_2);
977+
978+
// TODO: ugly zk update here
979+
for (unsigned int i = 0; i < c; i++) {
980+
zk_hash_128_update(&a0_ctx, a0[i]);
981+
zk_hash_128_update(&a1_ctx, a1[i]);
982+
zk_hash_128_update(&a2_ctx, a2[i]);
983+
}
937984

938-
zk_hash_128_init(&a0_ctx, chall);
939-
zk_hash_128_init(&a1_ctx, chall);
940-
aes_key_schedule_constraints_Mkey_0_128(w, bf_v, &a0_ctx, &a1_ctx, k, vk, params);
941-
942-
// Step: Skipping 8 in implementation
943-
// Step: 9
944-
945-
// Step: 10,11
946-
aes_enc_constraints_Mkey_0_128(in, out, w + FAEST_128F_Lke / 8, bf_v + FAEST_128F_Lke, k, vk,
947-
&a0_ctx, &a1_ctx);
948-
// Step: 12 (beta == 1)
949-
faest_aligned_free(vk);
950-
free(k);
985+
zk_hash_128_finalize(a0_tilde, &a0_ctx, bf_u_star_0);
986+
zk_hash_128_finalize(a1_tilde, &a1_ctx, bf_v_star_0 + bf_u_star_1);
987+
zk_hash_128_finalize(a2_tilde, &a2_ctx, bf_v_star_1);
951988

952-
// Step: 16..18
953-
zk_hash_128_finalize(a_tilde, &a1_ctx, bf128_load(u + FAEST_128F_ELL / 8));
954-
zk_hash_128_finalize(b_tilde, &a0_ctx, bf128_sum_poly(bf_v + FAEST_128F_ELL));
955-
faest_aligned_free(bf_v);
956989
}
957990

958991

0 commit comments

Comments
 (0)