diff --git a/pkg/urbit/jets/e/ed_scalarmult_base.c b/pkg/urbit/jets/e/ed_scalarmult_base.c index bc3cda7f6..3bdbedaa1 100644 --- a/pkg/urbit/jets/e/ed_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_scalarmult_base.c @@ -2,35 +2,38 @@ ** */ #include "all.h" - -#include -#include +#include /* functions */ + u3_noun + u3qc_scalarmult_base(u3_atom a) + { + c3_w met_w = u3r_met(3, a); + + if ( met_w > 32 ) { + 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); + + urcrypt_ed_scalarmult_base(a_y, out_y); + return u3i_bytes(32, out_y); + } + } + u3_noun u3wee_scalarmult_base(u3_noun cor) { - u3_noun scalar = u3r_at(u3x_sam, cor); + u3_noun a = u3r_at(u3x_sam, cor); - if ( (u3_none == scalar) || (c3n == u3ud(scalar)) ) { + if ( (u3_none == a) || (c3n == u3ud(a)) ) { return u3m_bail(c3__exit); } - - c3_w met_w = u3r_met(3, scalar); - if ( met_w > 32 ) { - return u3m_bail(c3__fail); + else { + return u3qc_scalarmult_base(a); } - - c3_y scalar_y[32]; - memset(scalar_y, 0, 32); - u3r_bytes(0, met_w, scalar_y, scalar); - - ge_p3 R; - ge_scalarmult_base(&R, scalar_y); - - c3_y output_y[32]; - ge_p3_tobytes(output_y, &R); - - return u3i_bytes(32, output_y); } diff --git a/pkg/urcrypt/urcrypt.c b/pkg/urcrypt/urcrypt.c index 96b455ce4..2539e7ee9 100644 --- a/pkg/urcrypt/urcrypt.c +++ b/pkg/urcrypt/urcrypt.c @@ -49,6 +49,14 @@ urcrypt_ed_scalarmult(uint8_t a[32], uint8_t b[32], uint8_t out[32]) return 0; } +void +urcrypt_ed_scalarmult_base(uint8_t a[32], uint8_t out[32]) +{ + ge_p3 R; + ge_scalarmult_base(&R, a); + ge_p3_tobytes(out, &R); +} + void urcrypt_ed_sign(uint8_t *message, size_t length, diff --git a/pkg/urcrypt/urcrypt.h b/pkg/urcrypt/urcrypt.h index 1204cda38..d6019d684 100644 --- a/pkg/urcrypt/urcrypt.h +++ b/pkg/urcrypt/urcrypt.h @@ -8,6 +8,7 @@ int urcrypt_ed_point_add(uint8_t a[32], uint8_t b[32], uint8_t out[32]); int urcrypt_ed_scalarmult(uint8_t a[32], uint8_t b[32], uint8_t out[32]); +void urcrypt_ed_scalarmult_base(uint8_t a[32], uint8_t out[32]); void urcrypt_ed_sign(uint8_t *message, size_t length, uint8_t seed[32],