From 57f684c3df0f0d4e877f3a48f368318aad606870 Mon Sep 17 00:00:00 2001 From: Steve Dee Date: Fri, 18 Apr 2014 16:04:00 -0700 Subject: [PATCH] AES decryption jet ++ix remains unjetted. There's no function that directly lines up with it in rijndael.h, and you should almost always be using ++en and ++in rather than touching ++be directly anyway. Also, take the jets live. --- gen164/5/aesc.c | 111 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 104 insertions(+), 7 deletions(-) diff --git a/gen164/5/aesc.c b/gen164/5/aesc.c index 601a99e49..ae5989c2d 100644 --- a/gen164/5/aesc.c +++ b/gen164/5/aesc.c @@ -12,6 +12,10 @@ extern u2_ho_jet j2_mcj(Pt5, aesc, be)[]; extern u2_ho_jet j2_mcj(Pt5, aesc, en)[]; extern u2_ho_jet j2_mcj(Pt5, aesc, ex)[]; + extern u2_ho_jet j2_mcj(Pt5, aesc, in)[]; +#if 0 + extern u2_ho_jet j2_mcj(Pt5, aesc, ix)[]; +#endif /* functions */ @@ -24,8 +28,12 @@ AES_KEY key_u; c3_y c_y[AES_BLOCK_SIZE]; - key_u.rounds = 14; - c3_assert(u2_cr_met(5, b) <= 4 * (AES_MAXNR + 1)); + key_u.rounds = AES_MAXNR; + + if ( u2_cr_met(5, b) > 4 * (AES_MAXNR + 1) ) { + return u2_bl_bail(wir_r, c3__exit); + } + { c3_w i_w; c3_w b_w; @@ -49,7 +57,7 @@ c3_w i_w, j_w, tmp_w; # define rk key_u.rd_key - for ( i_w = 0, j_w = 4 * key_u.rounds; i_w < j_w; i_w += 4, j_w -= 4 ) { + for ( i_w = 0, j_w = 4 * AES_MAXNR; i_w < j_w; i_w += 4, j_w -= 4 ) { tmp_w = rk[i_w ]; rk[i_w ] = rk[j_w ]; rk[j_w ] = tmp_w; tmp_w = rk[i_w + 1]; rk[i_w + 1] = rk[j_w + 1]; rk[j_w + 1] = tmp_w; tmp_w = rk[i_w + 2]; rk[i_w + 2] = rk[j_w + 2]; rk[j_w + 2] = tmp_w; @@ -71,6 +79,8 @@ if ( u2_no == u2_mean(cor, u2_cv_sam_2, &a, u2_cv_sam_6, &b, u2_cv_sam_7, &c, 0) || + u2_no == u2_stud(b) || + u2_no == u2_stud(c) || (a != u2_yes && a != u2_no) ) { return u2_bl_bail(wir_r, c3__exit); @@ -109,7 +119,10 @@ { u2_noun a, b; - if ( u2_no == u2_mean(cor, u2_cv_sam_2, &a, u2_cv_sam_3, &b, 0) ) { + if ( u2_no == u2_mean(cor, u2_cv_sam_2, &a, u2_cv_sam_3, &b, 0) || + u2_no == u2_stud(a) || + u2_no == u2_stud(b) ) + { return u2_bl_bail(wir_r, c3__exit); } else { @@ -161,29 +174,113 @@ } } + u2_weak + j2_mcd(Pt5, aesc, in)(u2_wire wir_r, + u2_atom a, + u2_atom b) + { + AES_KEY key_u; + c3_y buf_y[32]; + + c3_assert(u2_cr_met(3, a) <= 32); + c3_assert(u2_cr_met(3, b) <= 16); + + u2_cr_bytes(0, 32, buf_y, a); + if ( 0 != AES_set_decrypt_key(buf_y, 256, &key_u) ) { + return u2_bl_bail(wir_r, c3__exit); + } + else { + u2_cr_bytes(0, 16, buf_y, b); + AES_decrypt(buf_y, buf_y, &key_u); + } + + return u2_ci_bytes(16, buf_y); + } + + u2_weak + j2_mc(Pt5, aesc, in)(u2_wire wir_r, + u2_noun cor) + { + u2_noun a, b; + + if ( u2_no == u2_mean(cor, u2_cv_sam_2, &a, u2_cv_sam_3, &b, 0) || + u2_no == u2_stud(a) || + u2_no == u2_stud(b) ) + { + return u2_bl_bail(wir_r, c3__exit); + } + else { + return j2_mcd(Pt5, aesc, in)(wir_r, a, b); + } + } + +#if 0 + u2_weak + j2_mcd(Pt5, aesc, ix)(u2_wire wir_r, + u2_atom a) + { + AES_KEY key_u; + c3_w out_w[4 * (AES_MAXNR + 1)]; + + // TODO + } + + u2_weak + j2_mc(Pt5, aesc, ix)(u2_wire wir_r, + u2_noun cor) + { + u2_atom a; + + if ( u2_no == u2_mean(cor, u2_cv_sam, &a, 0) || + u2_no == u2_stud(a) ) + { + return u2_bl_bail(wir_r, c3__exit); + } + else { + return j2_mcd(Pt5, aesc, ix)(wir_r, a); + } + } +#endif + /* structures */ u2_ho_jet j2_mcj(Pt5, aesc, be)[] = { - { ".2", c3__lite, j2_mc(Pt5, aesc, be), u2_jet_test | u2_jet_live, u2_none, u2_none }, + { ".2", c3__lite, j2_mc(Pt5, aesc, be), Tier5, u2_none, u2_none }, { } }; u2_ho_jet j2_mcj(Pt5, aesc, en)[] = { - { ".2", c3__lite, j2_mc(Pt5, aesc, en), u2_jet_test | u2_jet_live, u2_none, u2_none }, + { ".2", c3__lite, j2_mc(Pt5, aesc, en), Tier5, u2_none, u2_none }, { } }; u2_ho_jet j2_mcj(Pt5, aesc, ex)[] = { - { ".2", c3__lite, j2_mc(Pt5, aesc, ex), u2_jet_test | u2_jet_live, u2_none, u2_none }, + { ".2", c3__lite, j2_mc(Pt5, aesc, ex), Tier5, u2_none, u2_none }, { } }; + u2_ho_jet + j2_mcj(Pt5, aesc, in)[] = { + { ".2", c3__lite, j2_mc(Pt5, aesc, in), Tier5, u2_none, u2_none }, + { } + }; +#if 0 + u2_ho_jet + j2_mcj(Pt5, aesc, ix)[] = { + { ".2", c3__lite, j2_mc(Pt5, aesc, ix), Tier5, u2_none, u2_none }, + { } + }; +#endif u2_ho_driver j2_mbd(Pt5, aesc)[] = { { j2_sc(Pt5, aesc, be), j2_mcj(Pt5, aesc, be), 0, 0, u2_none }, { j2_sc(Pt5, aesc, en), j2_mcj(Pt5, aesc, en), 0, 0, u2_none }, { j2_sc(Pt5, aesc, ex), j2_mcj(Pt5, aesc, ex), 0, 0, u2_none }, + { j2_sc(Pt5, aesc, in), j2_mcj(Pt5, aesc, in), 0, 0, u2_none }, +#if 0 + { j2_sc(Pt5, aesc, ix), j2_mcj(Pt5, aesc, ix), 0, 0, u2_none }, +#endif { } };