From bd17aa70ca3a6ce690c373fcfd52a9b11d49afe8 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Fri, 31 Jul 2020 16:31:56 -0700 Subject: [PATCH] urcrypt_ed_puck --- pkg/urbit/jets/e/ed_add_double_scalarmult.c | 6 +-- .../e/ed_add_scalarmult_scalarmult_base.c | 6 +-- pkg/urbit/jets/e/ed_point_add.c | 6 +-- pkg/urbit/jets/e/ed_puck.c | 37 +++++++++++-------- pkg/urbit/jets/e/ed_scalarmult.c | 6 +-- pkg/urbit/jets/e/ed_scalarmult_base.c | 6 +-- pkg/urbit/jets/e/ed_sign.c | 2 +- pkg/urcrypt/urcrypt.c | 7 ++++ pkg/urcrypt/urcrypt.h | 3 +- 9 files changed, 46 insertions(+), 33 deletions(-) diff --git a/pkg/urbit/jets/e/ed_add_double_scalarmult.c b/pkg/urbit/jets/e/ed_add_double_scalarmult.c index 46b9c9515..b177d826d 100644 --- a/pkg/urbit/jets/e/ed_add_double_scalarmult.c +++ b/pkg/urbit/jets/e/ed_add_double_scalarmult.c @@ -6,8 +6,8 @@ /* functions */ - u3_noun - u3qc_add_double_scalarmult(u3_atom a, + static u3_atom + _cqee_add_double_scalarmult(u3_atom a, u3_atom b, u3_atom c, u3_atom d) @@ -53,6 +53,6 @@ { return u3m_bail(c3__exit); } else { - return u3qc_add_double_scalarmult(a, b, c, d); + return _cqee_add_double_scalarmult(a, b, c, d); } } 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 8596ea536..4ac8fc1ec 100644 --- a/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c @@ -6,8 +6,8 @@ /* functions */ - u3_noun - u3qc_add_scalarmult_scalarmult_base(u3_atom a, + static u3_atom + _cqee_add_scalarmult_scalarmult_base(u3_atom a, u3_atom b, u3_atom c) { @@ -49,6 +49,6 @@ { return u3m_bail(c3__exit); } else { - return u3qc_add_scalarmult_scalarmult_base(a, b, c); + return _cqee_add_scalarmult_scalarmult_base(a, b, c); } } diff --git a/pkg/urbit/jets/e/ed_point_add.c b/pkg/urbit/jets/e/ed_point_add.c index a1eff2e58..fe105ac6e 100644 --- a/pkg/urbit/jets/e/ed_point_add.c +++ b/pkg/urbit/jets/e/ed_point_add.c @@ -7,8 +7,8 @@ /* functions */ - u3_noun - u3qc_point_add(u3_atom a, + static u3_atom + _cqee_point_add(u3_atom a, u3_atom b) { c3_w ate_w, bet_w; @@ -43,6 +43,6 @@ { return u3m_bail(c3__exit); } else { - return u3qc_point_add(a, b); + return _cqee_point_add(a, b); } } diff --git a/pkg/urbit/jets/e/ed_puck.c b/pkg/urbit/jets/e/ed_puck.c index 781899784..8c6f3760f 100644 --- a/pkg/urbit/jets/e/ed_puck.c +++ b/pkg/urbit/jets/e/ed_puck.c @@ -2,32 +2,37 @@ ** */ #include "all.h" - - -#include +#include /* functions */ + static u3_atom + _cqee_puck(u3_atom sed) + { + c3_y sed_y[32], pub_y[32]; + c3_w met_w; + + if ( (met_w = u3r_met(3, sed)) > 32 ) { + // 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 u3wee_puck(u3_noun cor) { - c3_y pub_y[32]; - c3_y sec_y[64]; - c3_y sed_y[32]; - c3_w met_w; u3_noun a = u3r_at(u3x_sam, cor); if ( (u3_none == a) || (c3n == u3ud(a)) ) { return u3m_bail(c3__exit); } - - met_w = u3r_met(3, a); - if ( met_w > 32 ) { - return u3m_bail(c3__exit); + else { + return _cqee_puck(a); } - - memset(sed_y, 0, 32); - u3r_bytes(0, met_w, sed_y, a); - ed25519_create_keypair(pub_y, sec_y, sed_y); - return u3i_bytes(32, pub_y); } diff --git a/pkg/urbit/jets/e/ed_scalarmult.c b/pkg/urbit/jets/e/ed_scalarmult.c index 727ba9f7e..bee52d958 100644 --- a/pkg/urbit/jets/e/ed_scalarmult.c +++ b/pkg/urbit/jets/e/ed_scalarmult.c @@ -6,8 +6,8 @@ /* functions */ - u3_noun - u3qc_scalarmult(u3_atom a, + static u3_atom + _cqee_scalarmult(u3_atom a, u3_atom b) { c3_w ate_w, bet_w; @@ -47,6 +47,6 @@ { return u3m_bail(c3__exit); } else { - return u3qc_scalarmult(a, b); + return _cqee_scalarmult(a, b); } } diff --git a/pkg/urbit/jets/e/ed_scalarmult_base.c b/pkg/urbit/jets/e/ed_scalarmult_base.c index 3bdbedaa1..fb0d2f813 100644 --- a/pkg/urbit/jets/e/ed_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_scalarmult_base.c @@ -6,8 +6,8 @@ /* functions */ - u3_noun - u3qc_scalarmult_base(u3_atom a) + static u3_atom + _cqee_scalarmult_base(u3_atom a) { c3_w met_w = u3r_met(3, a); @@ -34,6 +34,6 @@ return u3m_bail(c3__exit); } else { - return u3qc_scalarmult_base(a); + return _cqee_scalarmult_base(a); } } diff --git a/pkg/urbit/jets/e/ed_sign.c b/pkg/urbit/jets/e/ed_sign.c index db59b1252..f26c04afd 100644 --- a/pkg/urbit/jets/e/ed_sign.c +++ b/pkg/urbit/jets/e/ed_sign.c @@ -6,7 +6,7 @@ /* functions */ - static u3_noun + static u3_atom _cqee_sign(u3_noun a, u3_noun b) { diff --git a/pkg/urcrypt/urcrypt.c b/pkg/urcrypt/urcrypt.c index 7cc214aaa..a6f9a64e1 100644 --- a/pkg/urcrypt/urcrypt.c +++ b/pkg/urcrypt/urcrypt.c @@ -119,6 +119,13 @@ urcrypt_ed_add_double_scalarmult(uint8_t a[32], return 0; } +void +urcrypt_ed_puck(uint8_t seed[32], uint8_t out[32]) +{ + uint8_t secret[64]; + ed25519_create_keypair(out, secret, seed); +} + void urcrypt_ed_sign(uint8_t *message, size_t length, diff --git a/pkg/urcrypt/urcrypt.h b/pkg/urcrypt/urcrypt.h index 62e0c279a..9ca52dd59 100644 --- a/pkg/urcrypt/urcrypt.h +++ b/pkg/urcrypt/urcrypt.h @@ -18,9 +18,10 @@ int urcrypt_ed_add_double_scalarmult(uint8_t a[32], uint8_t b[32], uint8_t b_point[32], uint8_t out[32]); +void urcrypt_ed_puck(uint8_t seed[32], uint8_t out[32]); void urcrypt_ed_sign(uint8_t *message, size_t length, uint8_t seed[32], - uint8_t signature[64]); + uint8_t out[64]); #endif