From c8714ebc54fa61fa8ad089baa7fc009ea6511568 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Tue, 4 Aug 2020 16:58:38 -0700 Subject: [PATCH] rest of the unpacks --- pkg/urbit/jets/e/ed_add_double_scalarmult.c | 14 ++++++------ .../e/ed_add_scalarmult_scalarmult_base.c | 12 +++++----- pkg/urbit/jets/e/ed_point_add.c | 10 ++++----- pkg/urbit/jets/e/ed_puck.c | 14 ++++++------ pkg/urbit/jets/e/ed_scalarmult.c | 12 +++++----- pkg/urbit/jets/e/ed_scalarmult_base.c | 10 +++------ pkg/urbit/jets/e/ed_shar.c | 14 ++++-------- pkg/urbit/jets/e/ed_sign.c | 20 ++++++++--------- pkg/urbit/jets/e/ed_veri.c | 22 ++++++++----------- 9 files changed, 56 insertions(+), 72 deletions(-) diff --git a/pkg/urbit/jets/e/ed_add_double_scalarmult.c b/pkg/urbit/jets/e/ed_add_double_scalarmult.c index 58b2a0781..e49a0bf16 100644 --- a/pkg/urbit/jets/e/ed_add_double_scalarmult.c +++ b/pkg/urbit/jets/e/ed_add_double_scalarmult.c @@ -14,15 +14,15 @@ { c3_y a_y[32], b_y[32], c_y[32], d_y[32], out_y[32]; - if ( (0 == u3r_unpack(32, a_y, a)) && - (0 == u3r_unpack(32, b_y, b)) && - (0 == u3r_unpack(32, c_y, c)) && - (0 == u3r_unpack(32, d_y, d)) && - (0 == urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) ) { - return u3i_bytes(32, out_y); + if ( (0 != u3r_unpack(32, a_y, a)) || + (0 != u3r_unpack(32, b_y, b)) || + (0 != u3r_unpack(32, c_y, c)) || + (0 != u3r_unpack(32, d_y, d)) || + (0 != urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) ) { + return u3_none; } else { - return u3_none; + return u3i_bytes(32, out_y); } } diff --git a/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c b/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c index 395fccd8f..0a0e2d2d4 100644 --- a/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c @@ -13,14 +13,14 @@ { c3_y a_y[32], b_y[32], c_y[32], out_y[32]; - if ( (0 == u3r_unpack(32, a_y, a)) && - (0 == u3r_unpack(32, b_y, b)) && - (0 == u3r_unpack(32, c_y, c)) && - (0 == urcrypt_ed_add_scalarmult_scalarmult_base(a_y, b_y, c_y, out_y)) ) { - return u3i_bytes(32, out_y); + if ( (0 != u3r_unpack(32, a_y, a)) || + (0 != u3r_unpack(32, b_y, b)) || + (0 != u3r_unpack(32, c_y, c)) || + (0 != urcrypt_ed_add_scalarmult_scalarmult_base(a_y, b_y, c_y, out_y)) ) { + return u3_none; } else { - return u3_none; + return u3i_bytes(32, out_y); } } diff --git a/pkg/urbit/jets/e/ed_point_add.c b/pkg/urbit/jets/e/ed_point_add.c index c21bdab0e..a93f798b3 100644 --- a/pkg/urbit/jets/e/ed_point_add.c +++ b/pkg/urbit/jets/e/ed_point_add.c @@ -13,13 +13,13 @@ { c3_y a_y[32], b_y[32], out_y[32]; - if ( (0 == u3r_unpack(32, a_y, a)) && - (0 == u3r_unpack(32, b_y, b)) && - (0 == urcrypt_ed_point_add(a_y, b_y, out_y)) ) { - return u3i_bytes(32, out_y); + if ( (0 != u3r_unpack(32, a_y, a)) || + (0 != u3r_unpack(32, b_y, b)) || + (0 != urcrypt_ed_point_add(a_y, b_y, out_y)) ) { + return u3_none; } else { - return u3_none; + return u3i_bytes(32, out_y); } } diff --git a/pkg/urbit/jets/e/ed_puck.c b/pkg/urbit/jets/e/ed_puck.c index 5154df4e5..8257b937e 100644 --- a/pkg/urbit/jets/e/ed_puck.c +++ b/pkg/urbit/jets/e/ed_puck.c @@ -9,17 +9,17 @@ static u3_atom _cqee_puck(u3_atom sed) { - c3_y sed_y[32], pub_y[32]; - c3_w met_w; + c3_y sed_y[32]; - if ( 0 == u3r_unpack(32, sed_y, sed) ) { - urcrypt_ed_puck(sed_y, pub_y); - return u3i_bytes(32, pub_y); - } - else { + if ( 0 != u3r_unpack(32, sed_y, sed) ) { // hoon explicitly crashes on mis-size return u3m_bail(c3__exit); } + else { + c3_y pub_y[32]; + urcrypt_ed_puck(sed_y, pub_y); + return u3i_bytes(32, pub_y); + } } u3_noun diff --git a/pkg/urbit/jets/e/ed_scalarmult.c b/pkg/urbit/jets/e/ed_scalarmult.c index 96e0e757b..224fba3f6 100644 --- a/pkg/urbit/jets/e/ed_scalarmult.c +++ b/pkg/urbit/jets/e/ed_scalarmult.c @@ -12,15 +12,15 @@ { c3_y a_y[32], b_y[32], out_y[32]; - if ( (0 == u3r_unpack(32, a_y, a)) && - (0 == u3r_unpack(32, b_y, b)) && - (0 == urcrypt_ed_scalarmult(a_y, b_y, out_y)) ) { - return u3i_bytes(32, out_y); - } - else { + if ( (0 != u3r_unpack(32, a_y, a)) || + (0 != u3r_unpack(32, b_y, b)) || + (0 != urcrypt_ed_scalarmult(a_y, b_y, out_y)) ) { // hoon does not check size of inputs return u3_none; } + else { + return u3i_bytes(32, out_y); + } } u3_noun diff --git a/pkg/urbit/jets/e/ed_scalarmult_base.c b/pkg/urbit/jets/e/ed_scalarmult_base.c index fb0d2f813..c1b641bd9 100644 --- a/pkg/urbit/jets/e/ed_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_scalarmult_base.c @@ -9,17 +9,13 @@ static u3_atom _cqee_scalarmult_base(u3_atom a) { - c3_w met_w = u3r_met(3, a); + c3_y a_y[32]; - if ( met_w > 32 ) { + if ( 0 != u3r_unpack(32, a_y, a) ) { return u3_none; } else { - c3_y a_y[32], out_y[32]; - - memset(a_y, 0, 32); - u3r_bytes(0, met_w, a_y, a); - + c3_y out_y[32]; urcrypt_ed_scalarmult_base(a_y, out_y); return u3i_bytes(32, out_y); } diff --git a/pkg/urbit/jets/e/ed_shar.c b/pkg/urbit/jets/e/ed_shar.c index 5bf93a645..5ed28df37 100644 --- a/pkg/urbit/jets/e/ed_shar.c +++ b/pkg/urbit/jets/e/ed_shar.c @@ -7,24 +7,18 @@ static u3_atom _cqee_shar(u3_atom pub, u3_atom sek) { - c3_w pet_w, set_w; + c3_y pub_y[32], sek_y[32]; - if ( (pet_w = u3r_met(3, pub)) > 32 ) { + if ( 0 != u3r_unpack(32, pub_y, pub) ) { // pub is not size checked in the hoon return u3_none; } - else if ( (set_w = u3r_met(3, sek)) > 32 ) { + else if ( 0 != u3r_unpack(32, sek_y, sek) ) { // sek explicitly bails through suck return u3m_bail(c3__exit); } else { - c3_y pub_y[32], sek_y[32], shr_y[32]; - - memset(pub_y, 0, 32); - memset(sek_y, 0, 32); - u3r_bytes(0, 32, pub_y, pub); - u3r_bytes(0, 32, sek_y, sek); - + c3_y shr_y[32]; urcrypt_ed_shar(pub_y, sek_y, shr_y); return u3i_bytes(32, shr_y); } diff --git a/pkg/urbit/jets/e/ed_sign.c b/pkg/urbit/jets/e/ed_sign.c index f26c04afd..606282947 100644 --- a/pkg/urbit/jets/e/ed_sign.c +++ b/pkg/urbit/jets/e/ed_sign.c @@ -10,24 +10,22 @@ _cqee_sign(u3_noun a, u3_noun b) { - c3_w b_w = u3r_met(3, b); + c3_y sed_y[32]; - if ( b_w > 32 ) { + if ( 0 != u3r_unpack(32, sed_y, b) ) { // hoon calls suck, which calls puck, which crashes return u3m_bail(c3__exit); } else { - c3_w a_w = u3r_met(3, a); - c3_y* mes_y = u3a_malloc(a_w); - c3_y sed_y[32], sig_y[64]; - - memset(sed_y, 0, 32); - u3r_bytes(0, a_w, mes_y, a); - u3r_bytes(0, b_w, sed_y, b); - - urcrypt_ed_sign(mes_y, a_w, sed_y, sig_y); + c3_y sig_y[64]; + c3_y* mes_y; + c3_w met_w = u3r_met(3, a); + mes_y = u3a_malloc(met_w); + u3r_bytes(0, met_w, mes_y, a); + urcrypt_ed_sign(mes_y, met_w, sed_y, sig_y); u3a_free(mes_y); + return u3i_bytes(64, sig_y); } } diff --git a/pkg/urbit/jets/e/ed_veri.c b/pkg/urbit/jets/e/ed_veri.c index 634c95509..646dd89ca 100644 --- a/pkg/urbit/jets/e/ed_veri.c +++ b/pkg/urbit/jets/e/ed_veri.c @@ -11,28 +11,24 @@ u3_noun m, u3_noun pk) { - c3_w set_w, pek_w; + c3_y sig_y[64], pub_y[32]; - if ( ((set_w = u3r_met(3, s)) > 64) || - ((pek_w = u3r_met(3, pk)) > 32) ) { + if ( (0 != u3r_unpack(64, sig_y, s)) || + (0 != u3r_unpack(32, pub_y, pk)) ) { // hoon checks sizes, but weirdly and without crashes return u3_none; } else { - c3_y sig_y[64], pub_y[32]; + c3_t val_t; + c3_y* mes_y; c3_w met_w = u3r_met(3, m); - c3_y* mes_y = u3a_malloc(met_w); - c3_o ret_o; - memset(sig_y, 0, 64); - memset(pub_y, 0, 32); - u3r_bytes(0, 64, sig_y, s); - u3r_bytes(0, 32, pub_y, pk); + mes_y = u3a_malloc(met_w); u3r_bytes(0, met_w, mes_y, m); - - ret_o = urcrypt_ed_veri(mes_y, met_w, pub_y, sig_y) ? c3y : c3n; + val_t = urcrypt_ed_veri(mes_y, met_w, pub_y, sig_y); u3a_free(mes_y); - return ret_o; + + return val_t ? c3y : c3n; } }