From 4218308d040793021b277717c569a2bc9633f618 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Tue, 4 Aug 2020 13:42:10 -0700 Subject: [PATCH] more unpacks --- pkg/urbit/jets/e/ed_add_double_scalarmult.c | 3 +-- .../e/ed_add_scalarmult_scalarmult_base.c | 25 ++++++------------- pkg/urbit/jets/e/ed_point_add.c | 20 +++++---------- pkg/urbit/jets/e/ed_puck.c | 12 ++++----- pkg/urbit/jets/e/ed_scalarmult.c | 24 +++++------------- 5 files changed, 25 insertions(+), 59 deletions(-) diff --git a/pkg/urbit/jets/e/ed_add_double_scalarmult.c b/pkg/urbit/jets/e/ed_add_double_scalarmult.c index a89ed34d19..58b2a07816 100644 --- a/pkg/urbit/jets/e/ed_add_double_scalarmult.c +++ b/pkg/urbit/jets/e/ed_add_double_scalarmult.c @@ -18,8 +18,7 @@ (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)) ) - { + (0 == urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) ) { return u3i_bytes(32, out_y); } else { 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 4ac8fc1ec1..395fccd8f5 100644 --- a/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c @@ -11,27 +11,16 @@ u3_atom b, u3_atom c) { - c3_w ate_w, bet_w, get_w; + c3_y a_y[32], b_y[32], c_y[32], out_y[32]; - if ( ((ate_w = u3r_met(3, a)) > 32) || - ((bet_w = u3r_met(3, b)) > 32) || - ((get_w = u3r_met(3, c)) > 32) ) { - return u3_none; + 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); } else { - c3_y a_y[32], b_y[32], c_y[32], out_y[32]; - - memset(a_y, 0, 32); - memset(b_y, 0, 32); - memset(c_y, 0, 32); - u3r_bytes(0, ate_w, a_y, a); - u3r_bytes(0, bet_w, b_y, b); - u3r_bytes(0, get_w, c_y, c); - - return - ( 0 == urcrypt_ed_add_scalarmult_scalarmult_base(a_y, b_y, c_y, out_y) ) - ? u3i_bytes(32, out_y) - : u3_none; + return u3_none; } } diff --git a/pkg/urbit/jets/e/ed_point_add.c b/pkg/urbit/jets/e/ed_point_add.c index fe105ac6eb..c21bdab0e4 100644 --- a/pkg/urbit/jets/e/ed_point_add.c +++ b/pkg/urbit/jets/e/ed_point_add.c @@ -11,23 +11,15 @@ _cqee_point_add(u3_atom a, u3_atom b) { - c3_w ate_w, bet_w; + c3_y a_y[32], b_y[32], out_y[32]; - if ( ((ate_w = u3r_met(3, a)) > 32) || - ((bet_w = u3r_met(3, b)) > 32) ) { - return u3_none; + 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); } else { - c3_y a_y[32], b_y[32], out_y[32]; - - memset(a_y, 0, 32); - memset(b_y, 0, 32); - u3r_bytes(0, ate_w, a_y, a); - u3r_bytes(0, bet_w, b_y, b); - - return ( 0 == urcrypt_ed_point_add(a_y, b_y, out_y) ) - ? u3i_bytes(32, out_y) - : u3_none; + return u3_none; } } diff --git a/pkg/urbit/jets/e/ed_puck.c b/pkg/urbit/jets/e/ed_puck.c index 8c6f3760f8..5154df4e59 100644 --- a/pkg/urbit/jets/e/ed_puck.c +++ b/pkg/urbit/jets/e/ed_puck.c @@ -12,16 +12,14 @@ c3_y sed_y[32], pub_y[32]; c3_w met_w; - if ( (met_w = u3r_met(3, sed)) > 32 ) { + if ( 0 == u3r_unpack(32, sed_y, sed) ) { + urcrypt_ed_puck(sed_y, pub_y); + return u3i_bytes(32, pub_y); + } + else { // hoon explicitly crashes on mis-size return u3m_bail(c3__exit); } - - memset(sed_y, 0, 32); - u3r_bytes(0, met_w, sed_y, sed); - - 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 bee52d9585..96e0e757bd 100644 --- a/pkg/urbit/jets/e/ed_scalarmult.c +++ b/pkg/urbit/jets/e/ed_scalarmult.c @@ -10,29 +10,17 @@ _cqee_scalarmult(u3_atom a, u3_atom b) { - c3_w ate_w, bet_w; c3_y a_y[32], b_y[32], out_y[32]; - if ( (ate_w = u3r_met(3, a)) > 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 { // hoon does not check size of inputs return u3_none; } - - if ( (bet_w = u3r_met(3, b)) > 32 ) { - return u3_none; - } - - memset(a_y, 0, 32); - memset(b_y, 0, 32); - u3r_bytes(0, ate_w, a_y, a); - u3r_bytes(0, bet_w, b_y, b); - - if ( 0 != urcrypt_ed_scalarmult(a_y, b_y, out_y) ) { - // this is unlikely to happen, but there is a return code. - return u3_none; - } - - return u3i_bytes(32, out_y); } u3_noun