diff --git a/ext/urcrypt/build.zig.zon b/ext/urcrypt/build.zig.zon index 9de2a9ad72..a7866adde4 100644 --- a/ext/urcrypt/build.zig.zon +++ b/ext/urcrypt/build.zig.zon @@ -14,8 +14,8 @@ .hash = "1220bb683a6df744e618f58a008eaae3eb62b70a78334cec676bd82b1b9e8e944eeb", }, .urcrypt = .{ - .url = "https://github.com/urbit/urcrypt/archive/e77a0998809f7552c455cf7bf8c1b68c141cce18.tar.gz", - .hash = "12202efcf40dcfed9a9b59bba4743cfd0c31364a6d7504724bd4d643b474ff69245b", + .url = "https://github.com/urbit/urcrypt/archive/465aad6262f2710f76f75adfe74effb5751c5ab3.tar.gz", + .hash = "1220c0f7141ab0aeb4164c5c2ae42848035e5b2fdff52c66c57d5744e3e3751e12c8", }, }, .paths = .{ diff --git a/pkg/noun/build.zig b/pkg/noun/build.zig index 1c816ea7f8..73d6d79e1e 100644 --- a/pkg/noun/build.zig +++ b/pkg/noun/build.zig @@ -273,7 +273,12 @@ const c_source_files = [_][]const u8{ "jets/e/ed_add_double_scalarmult.c", "jets/e/ed_add_scalarmult_scalarmult_base.c", "jets/e/ed_point_add.c", + "jets/e/ed_point_neg.c", + "jets/e/ed_scad.c", + "jets/e/ed_recs.c", + "jets/e/ed_smac.c", "jets/e/ed_puck.c", + "jets/e/ed_luck.c", "jets/e/ed_scalarmult.c", "jets/e/ed_scalarmult_base.c", "jets/e/ed_shar.c", diff --git a/pkg/noun/jets/137/tree.c b/pkg/noun/jets/137/tree.c index fec03edf1f..760f84e593 100644 --- a/pkg/noun/jets/137/tree.c +++ b/pkg/noun/jets/137/tree.c @@ -112,10 +112,29 @@ static u3j_harm _137_hex__crc32_a[] = {{".2", u3we_crc32}, {}}; static u3j_core _137_hex__crc_d[] = {{"crc32", 7, _137_hex__crc32_a, 0, no_hashes }, {}}; +static u3j_harm _137_hex_coed__ed_scad_a[] = {{".2", u3wee_scad}, {}}; +static u3j_harm _137_hex_coed__ed_scas_a[] = {{".2", u3wee_scas}, {}}; +static u3j_harm _137_hex_coed__ed_scap_a[] = {{".2", u3wee_scap}, {}}; + static u3j_harm _137_hex_coed__ed_puck_a[] = {{".2", u3wee_puck}, {}}; +static u3j_harm _137_hex_coed__ed_luck_a[] = {{".2", u3wee_luck}, {}}; +static u3j_harm _137_hex_coed__ed_sign_a[] = {{".2", u3wee_sign}, {}}; +static u3j_harm _137_hex_coed__ed_sign_raw_a[] = {{".2", u3wee_sign_raw}, {}}; static u3j_harm _137_hex_coed__ed_sign_octs_a[] = {{".2", u3wee_sign_octs}, {}}; +static u3j_harm _137_hex_coed__ed_sign_octs_raw_a[] = {{".2", u3wee_sign_octs_raw}, {}}; static u3j_harm _137_hex_coed__ed_veri_octs_a[] = {{".2", u3wee_veri_octs}, {}}; +static u3j_harm _137_hex_coed__ed_veri_a[] = {{".2", u3wee_veri}, {}}; static u3j_harm _137_hex_coed__ed_shar_a[] = {{".2", u3wee_shar}, {}}; +static u3j_harm _137_hex_coed__ed_slar_a[] = {{".2", u3wee_slar}, {}}; + +static u3j_harm _137_hex_coed__ed_smac_a[] = + {{".2", u3wee_smac}, {}}; + +static u3j_harm _137_hex_coed__ed_recs_a[] = + {{".2", u3wee_recs}, {}}; + +static u3j_harm _137_hex_coed__ed_point_neg_a[] = + {{".2", u3wee_point_neg}, {}}; static u3j_harm _137_hex_coed__ed_point_add_a[] = {{".2", u3wee_point_add}, {}}; @@ -133,11 +152,23 @@ static u3j_harm _137_hex_coed__ed_add_double_scalarmult_a[] = {{".2", u3wee_add_double_scalarmult}, {}}; static u3j_core _137_hex_coed__ed_d[] = - { { "sign-octs", 7, _137_hex_coed__ed_sign_octs_a, 0, no_hashes }, + { { "sign", 7, _137_hex_coed__ed_sign_a, 0, no_hashes }, + { "sign-raw", 7, _137_hex_coed__ed_sign_raw_a, 0, no_hashes }, + { "sign-octs", 7, _137_hex_coed__ed_sign_octs_a, 0, no_hashes }, + { "sign-octs-raw", 7, _137_hex_coed__ed_sign_octs_raw_a, 0, no_hashes }, { "puck", 7, _137_hex_coed__ed_puck_a, 0, no_hashes }, + { "luck", 7, _137_hex_coed__ed_luck_a, 0, no_hashes }, + { "scad", 7, _137_hex_coed__ed_scad_a, 0, no_hashes }, + { "scas", 7, _137_hex_coed__ed_scas_a, 0, no_hashes }, + { "scap", 7, _137_hex_coed__ed_scap_a, 0, no_hashes }, { "veri-octs", 7, _137_hex_coed__ed_veri_octs_a, 0, no_hashes }, + { "veri", 7, _137_hex_coed__ed_veri_a, 0, no_hashes }, { "shar", 7, _137_hex_coed__ed_shar_a, 0, no_hashes }, + { "slar", 7, _137_hex_coed__ed_slar_a, 0, no_hashes }, { "point-add", 7, _137_hex_coed__ed_point_add_a, 0, 0 }, + { "point-neg", 7, _137_hex_coed__ed_point_neg_a, 0, 0 }, + { "recs", 7, _137_hex_coed__ed_recs_a, 0, 0 }, + { "smac", 7, _137_hex_coed__ed_smac_a, 0, 0 }, { "scalarmult", 7, _137_hex_coed__ed_scalarmult_a, 0, no_hashes }, { "scalarmult-base", 7, _137_hex_coed__ed_scalarmult_base_a, 0, diff --git a/pkg/noun/jets/e/ed_add_double_scalarmult.c b/pkg/noun/jets/e/ed_add_double_scalarmult.c index b37f3e00e7..65129197cd 100644 --- a/pkg/noun/jets/e/ed_add_double_scalarmult.c +++ b/pkg/noun/jets/e/ed_add_double_scalarmult.c @@ -8,18 +8,43 @@ static u3_atom _cqee_add_double_scalarmult(u3_atom a, + u3_atom a_point, u3_atom b, - u3_atom c, - u3_atom d) + u3_atom b_point) { - c3_y a_y[32], b_y[32], c_y[32], d_y[32], out_y[32]; - - if ( (0 != u3r_bytes_fit(32, a_y, a)) || - (0 != u3r_bytes_fit(32, b_y, b)) || - (0 != u3r_bytes_fit(32, c_y, c)) || - (0 != u3r_bytes_fit(32, d_y, d)) || - (0 != urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) ) { - return u3_none; + c3_y a_y[32], a_point_y[32], + b_y[32], b_point_y[32], + out_y[32]; + c3_w met_w; + + met_w = u3r_met(3, a); + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, a)) ) + ) { + u3_noun a_recs = u3qee_recs(a); + u3r_bytes(0, 32, a_y, a_recs); + u3z(a_recs); + } else { + u3r_bytes(0, 32, a_y, a); + } + + met_w = u3r_met(3, b); + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, b)) ) + ) { + u3_noun b_recs = u3qee_recs(b); + u3r_bytes(0, 32, b_y, b_recs); + u3z(b_recs); + } else { + u3r_bytes(0, 32, b_y, b); + } + + if ( (0 != u3r_bytes_fit(32, a_point_y, a_point)) || + (0 != u3r_bytes_fit(32, b_point_y, b_point)) || + (0 != urcrypt_ed_add_double_scalarmult(a_y, a_point_y, b_y, b_point_y, out_y)) ) { + return u3m_bail(c3__exit); } else { return u3i_bytes(32, out_y); @@ -37,11 +62,11 @@ u3x_sam_15, &d, 0)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || - (c3n == u3ud(c)) ) + (c3n == u3ud(c)) || + (c3n == u3ud(d)) ) { return u3m_bail(c3__exit); } else { - return u3l_punt("add-double-scalarmult", - _cqee_add_double_scalarmult(a, b, c, d)); + return _cqee_add_double_scalarmult(a, b, c, d); } } diff --git a/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c b/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c index 6ec27bfaeb..39eda5392b 100644 --- a/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c +++ b/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c @@ -8,16 +8,39 @@ static u3_atom _cqee_add_scalarmult_scalarmult_base(u3_atom a, - u3_atom b, - u3_atom c) + u3_atom a_point, + u3_atom b) { - c3_y a_y[32], b_y[32], c_y[32], out_y[32]; + c3_y a_y[32], a_point_y[32], b_y[32], out_y[32]; + c3_w met_w; - if ( (0 != u3r_bytes_fit(32, a_y, a)) || - (0 != u3r_bytes_fit(32, b_y, b)) || - (0 != u3r_bytes_fit(32, c_y, c)) || - (0 != urcrypt_ed_add_scalarmult_scalarmult_base(a_y, b_y, c_y, out_y)) ) { - return u3_none; + met_w = u3r_met(3, a); + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, a)) ) + ) { + u3_noun a_recs = u3qee_recs(a); + u3r_bytes(0, 32, a_y, a_recs); + u3z(a_recs); + } else { + u3r_bytes(0, 32, a_y, a); + } + + met_w = u3r_met(3, b); + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, b)) ) + ) { + u3_noun b_recs = u3qee_recs(b); + u3r_bytes(0, 32, b_y, b_recs); + u3z(b_recs); + } else { + u3r_bytes(0, 32, b_y, b); + } + + if ( (0 != u3r_bytes_fit(32, a_point_y, a_point)) || + (0 != urcrypt_ed_add_scalarmult_scalarmult_base(a_y, a_point_y, b_y, out_y)) ) { + return u3m_bail(c3__exit); } else { return u3i_bytes(32, out_y); @@ -38,7 +61,6 @@ { return u3m_bail(c3__exit); } else { - return u3l_punt("add-scalarmult-scalarmult-base", - _cqee_add_scalarmult_scalarmult_base(a, b, c)); + return _cqee_add_scalarmult_scalarmult_base(a, b, c); } } diff --git a/pkg/noun/jets/e/ed_luck.c b/pkg/noun/jets/e/ed_luck.c new file mode 100644 index 0000000000..c21889ee63 --- /dev/null +++ b/pkg/noun/jets/e/ed_luck.c @@ -0,0 +1,37 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" +#include "urcrypt.h" + + static u3_atom + _cqee_luck(u3_atom sed) + { + c3_y sed_y[32]; + + if ( 0 != u3r_bytes_fit(32, sed_y, sed) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + else { + c3_y pub_y[32]; + c3_y sec_y[64]; + urcrypt_ed_luck(sed_y, pub_y, sec_y); + return u3nc(u3i_bytes(32, pub_y), u3i_bytes(64, sec_y)); + } + } + + u3_noun + u3wee_luck(u3_noun cor) + { + u3_noun a = u3r_at(u3x_sam, cor); + + if ( (u3_none == a) || (c3n == u3ud(a)) ) { + return u3m_bail(c3__exit); + } + else { + return _cqee_luck(a); + } + } diff --git a/pkg/noun/jets/e/ed_point_add.c b/pkg/noun/jets/e/ed_point_add.c index 20ce3041ef..70fe563c20 100644 --- a/pkg/noun/jets/e/ed_point_add.c +++ b/pkg/noun/jets/e/ed_point_add.c @@ -16,7 +16,7 @@ if ( (0 != u3r_bytes_fit(32, a_y, a)) || (0 != u3r_bytes_fit(32, b_y, b)) || (0 != urcrypt_ed_point_add(a_y, b_y, out_y)) ) { - return u3_none; + return u3m_bail(c3__exit); } else { return u3i_bytes(32, out_y); @@ -35,6 +35,6 @@ { return u3m_bail(c3__exit); } else { - return u3l_punt("point-add", _cqee_point_add(a, b)); + return _cqee_point_add(a, b); } } diff --git a/pkg/noun/jets/e/ed_point_neg.c b/pkg/noun/jets/e/ed_point_neg.c new file mode 100644 index 0000000000..5a1a5bd237 --- /dev/null +++ b/pkg/noun/jets/e/ed_point_neg.c @@ -0,0 +1,37 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" +#include "urcrypt.h" + + + static u3_atom + _cqee_point_neg(u3_atom a) + { + c3_y a_y[32]; + + if ( (0 != u3r_bytes_fit(32, a_y, a)) || + (0 != urcrypt_ed_point_neg(a_y)) ) { + return u3m_bail(c3__exit); + } + else { + return u3i_bytes(32, a_y); + } + } + + u3_noun + u3wee_point_neg(u3_noun cor) + { + + u3_noun a; + + if ( (u3_none == (a = u3r_at(u3x_sam, cor))) || + (c3n == u3ud(a)) ) + { + return u3m_bail(c3__exit); + } else { + return _cqee_point_neg(a); + } + } diff --git a/pkg/noun/jets/e/ed_recs.c b/pkg/noun/jets/e/ed_recs.c new file mode 100644 index 0000000000..bdcf2249cc --- /dev/null +++ b/pkg/noun/jets/e/ed_recs.c @@ -0,0 +1,48 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" +#include "urcrypt.h" + + // `@ux`(rev 3 32 l:ed:crypto) + static c3_y _cqee_l_prime[] = { + 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, + 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + }; + + u3_atom + u3qee_recs(u3_atom a) + { + c3_w met_w = u3r_met(3, a); + + if ( 64 < met_w ) { + u3_atom l_prime = u3i_bytes(32, _cqee_l_prime); + u3_atom pro = u3qa_mod(a, l_prime); + u3z(l_prime); + return pro; + } + + c3_y a_y[64]; + + u3r_bytes(0, 64, a_y, a); + urcrypt_ed_scalar_reduce(a_y); + return u3i_bytes(32, a_y); + } + + u3_noun + u3wee_recs(u3_noun cor) + { + u3_noun a; + + if ( (u3_none == (a = u3r_at(u3x_sam, cor))) || + (c3n == u3ud(a)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qee_recs(a); + } + } diff --git a/pkg/noun/jets/e/ed_scad.c b/pkg/noun/jets/e/ed_scad.c new file mode 100644 index 0000000000..af95563424 --- /dev/null +++ b/pkg/noun/jets/e/ed_scad.c @@ -0,0 +1,124 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" +#include "urcrypt.h" + + static u3_atom + _cqee_scad(u3_atom pub, u3_atom sek, u3_atom sca) + { + c3_y pub_y[32]; + c3_y sek_y[64]; + c3_y sca_y[32]; + + if ( 0 != u3r_bytes_fit(32, pub_y, pub) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + if ( 0 != u3r_bytes_fit(64, sek_y, sek) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + if ( 0 != u3r_bytes_fit(32, sca_y, sca) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + else { + urcrypt_ed_add_scalar_public_private(pub_y, sek_y, sca_y); + return u3nc(u3i_bytes(32, pub_y), u3i_bytes(64, sek_y)); + } + } + + u3_noun + u3wee_scad(u3_noun cor) + { + u3_noun pub, sek, sca; + if ( (c3n == u3r_mean(cor, + u3x_sam_2, &pub, + u3x_sam_6, &sek, + u3x_sam_7, &sca, 0)) || + (c3n == u3ud(pub)) || + (c3n == u3ud(sek)) || + (c3n == u3ud(sca)) ) { + return u3m_bail(c3__exit); + } + else { + return _cqee_scad(pub, sek, sca); + } + } + + static u3_atom + _cqee_scas(u3_atom sek, u3_atom sca) + { + c3_y sek_y[64]; + c3_y sca_y[32]; + + if ( 0 != u3r_bytes_fit(64, sek_y, sek) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + if ( 0 != u3r_bytes_fit(32, sca_y, sca) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + else { + urcrypt_ed_add_scalar_private(sek_y, sca_y); + return u3i_bytes(64, sek_y); + } + } + + u3_noun + u3wee_scas(u3_noun cor) + { + u3_noun sek, sca; + if ( (c3n == u3r_mean(cor, + u3x_sam_2, &sek, + u3x_sam_3, &sca, 0)) || + (c3n == u3ud(sek)) || + (c3n == u3ud(sca)) ) { + return u3m_bail(c3__exit); + } + else { + return _cqee_scas(sek, sca); + } + } + + static u3_atom + _cqee_scap(u3_atom pub, u3_atom sca) + { + c3_y pub_y[32]; + c3_y sca_y[32]; + + if ( 0 != u3r_bytes_fit(32, pub_y, pub) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + if ( 0 != u3r_bytes_fit(32, sca_y, sca) ) { + // hoon explicitly crashes on mis-size + return u3m_bail(c3__exit); + } + else { + urcrypt_ed_add_scalar_public(pub_y, sca_y); + return u3i_bytes(32, pub_y); + } + } + + u3_noun + u3wee_scap(u3_noun cor) + { + u3_noun pub, sca; + if ( (c3n == u3r_mean(cor, + u3x_sam_2, &pub, + u3x_sam_3, &sca, 0)) || + (c3n == u3ud(pub)) || + (c3n == u3ud(sca)) ) { + return u3m_bail(c3__exit); + } + else { + return _cqee_scap(pub, sca); + } + } + + diff --git a/pkg/noun/jets/e/ed_scalarmult.c b/pkg/noun/jets/e/ed_scalarmult.c index 9cc3f77481..8585c29623 100644 --- a/pkg/noun/jets/e/ed_scalarmult.c +++ b/pkg/noun/jets/e/ed_scalarmult.c @@ -11,12 +11,26 @@ u3_atom b) { c3_y a_y[32], b_y[32], out_y[32]; + if (0 != u3r_bytes_fit(32, b_y, b)) { + return u3m_bail(c3__exit); + } + + c3_w met_w = u3r_met(3, a); + // scalarmult expects a_y[31] <= 127 + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, a)) ) + ) { + u3_noun a_recs = u3qee_recs(a); + u3r_bytes(0, 32, a_y, a_recs); + u3z(a_recs); + } else { + u3r_bytes(0, 32, a_y, a); + } - if ( (0 != u3r_bytes_fit(32, a_y, a)) || - (0 != u3r_bytes_fit(32, b_y, b)) || - (0 != urcrypt_ed_scalarmult(a_y, b_y, out_y)) ) { - // hoon does not check size of inputs - return u3_none; + if ( (0 != urcrypt_ed_scalarmult(a_y, b_y, out_y)) ) { + // at this point, will only fail if b is bad point + return u3m_bail(c3__exit); } else { return u3i_bytes(32, out_y); @@ -35,6 +49,6 @@ { return u3m_bail(c3__exit); } else { - return u3l_punt("scalarmult", _cqee_scalarmult(a, b)); + return _cqee_scalarmult(a, b); } } diff --git a/pkg/noun/jets/e/ed_scalarmult_base.c b/pkg/noun/jets/e/ed_scalarmult_base.c index e000515156..61935846f2 100644 --- a/pkg/noun/jets/e/ed_scalarmult_base.c +++ b/pkg/noun/jets/e/ed_scalarmult_base.c @@ -9,14 +9,25 @@ static u3_atom _cqee_scalarmult_base(u3_atom a) { - c3_y a_y[32]; + c3_y a_y[32], out_y[32]; + c3_w met_w = u3r_met(3, a); + // scalarmult_base expects a_y[31] <= 127 + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, a)) ) + ) { + u3_noun a_recs = u3qee_recs(a); + u3r_bytes(0, 32, a_y, a_recs); + u3z(a_recs); + } else { + u3r_bytes(0, 32, a_y, a); + } - if ( 0 != u3r_bytes_fit(32, a_y, a) ) { - return u3_none; + if (0 != urcrypt_ed_scalarmult_base(a_y, out_y)) { + // should be unreachable, as scalar already reduced + return u3m_bail(c3__exit); } else { - c3_y out_y[32]; - urcrypt_ed_scalarmult_base(a_y, out_y); return u3i_bytes(32, out_y); } } @@ -30,6 +41,6 @@ return u3m_bail(c3__exit); } else { - return u3l_punt("scalarmult-base", _cqee_scalarmult_base(a)); + return _cqee_scalarmult_base(a); } } diff --git a/pkg/noun/jets/e/ed_shar.c b/pkg/noun/jets/e/ed_shar.c index 30f3920c8b..ed293f777a 100644 --- a/pkg/noun/jets/e/ed_shar.c +++ b/pkg/noun/jets/e/ed_shar.c @@ -7,27 +7,59 @@ #include "urcrypt.h" static u3_atom - _cqee_shar(u3_atom pub, u3_atom sek) + _cqee_shar(u3_atom pub, u3_atom sed) { - c3_y pub_y[32], sek_y[32]; + c3_y pub_y[32], sed_y[32]; if ( 0 != u3r_bytes_fit(32, pub_y, pub) ) { - // pub is not size checked in the hoon - return u3_none; + return u3m_bail(c3__exit); } - else if ( 0 != u3r_bytes_fit(32, sek_y, sek) ) { - // sek explicitly bails through suck + else if ( 0 != u3r_bytes_fit(32, sed_y, sed) ) { + // hoon calls luck, which crashes return u3m_bail(c3__exit); } else { c3_y shr_y[32]; - urcrypt_ed_shar(pub_y, sek_y, shr_y); + urcrypt_ed_shar(pub_y, sed_y, shr_y); return u3i_bytes(32, shr_y); } } u3_noun u3wee_shar(u3_noun cor) + { + u3_noun pub, sed; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, u3x_sam_3, &sed, 0)) || + (c3n == u3ud(pub)) || + (c3n == u3ud(sed)) ) + { + return u3m_bail(c3__exit); + } else { + return _cqee_shar(pub, sed); + } + } + + static u3_atom + _cqee_slar(u3_atom pub, u3_atom sek) + { + c3_y pub_y[32], sek_y[64]; + + if ( 0 != u3r_bytes_fit(32, pub_y, pub) ) { + return u3m_bail(c3__exit); + } + else if ( 0 != u3r_bytes_fit(64, sek_y, sek) ) { + return u3m_bail(c3__exit); + } + else { + c3_y shr_y[32]; + urcrypt_ed_slar(pub_y, sek_y, shr_y); + return u3i_bytes(32, shr_y); + } + } + + u3_noun + u3wee_slar(u3_noun cor) { u3_noun pub, sek; @@ -37,6 +69,6 @@ { return u3m_bail(c3__exit); } else { - return u3l_punt("shar", _cqee_shar(pub, sek)); + return _cqee_slar(pub, sek); } } diff --git a/pkg/noun/jets/e/ed_sign.c b/pkg/noun/jets/e/ed_sign.c index 0cde84ec71..cd1797d4dd 100644 --- a/pkg/noun/jets/e/ed_sign.c +++ b/pkg/noun/jets/e/ed_sign.c @@ -9,12 +9,12 @@ #include static u3_atom - _cqee_sign_octs(u3_noun len, u3_noun dat, u3_noun key) + _cqee_sign_octs(u3_noun len, u3_noun dat, u3_noun sed) { - c3_y key_y[32]; + c3_y sed_y[32]; c3_w len_w; - if ( 0 != u3r_bytes_fit(32, key_y, key) ) { - // hoon calls suck, which calls puck, which crashes + if ( 0 != u3r_bytes_fit(32, sed_y, sed) ) { + // hoon calls luck, which crashes return u3m_bail(c3__exit); } else if ( !u3r_word_fit(&len_w, len) ) { @@ -23,7 +23,7 @@ else { c3_y sig_y[64]; c3_y* dat_y = u3r_bytes_alloc(0, len_w, dat); - urcrypt_ed_sign(dat_y, len_w, key_y, sig_y); + urcrypt_ed_sign(dat_y, len_w, sed_y, sig_y); u3a_free(dat_y); return u3i_bytes(64, sig_y); } @@ -32,33 +32,78 @@ u3_noun u3wee_sign_octs(u3_noun cor) { - u3_noun msg, key; + u3_noun msg, sed; u3_noun len, dat; - if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_3, &key, 0) || - c3n == u3r_cell(msg, &len, &dat) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_3, &sed, 0) || + c3n == u3r_cell(msg, &len, &dat) || + c3n == u3ud(sed) || + c3n == u3ud(len) || + c3n == u3ud(dat) ) { return u3m_bail(c3__fail); } else { - return _cqee_sign_octs(len, dat, key); + return _cqee_sign_octs(len, dat, sed); } } static u3_atom - _cqee_sign(u3_noun a, - u3_noun b) + _cqee_sign_octs_raw(u3_noun len, u3_noun dat, u3_noun pub, u3_noun sek) + { + c3_y pub_y[32], sek_y[64]; + c3_w len_w; + if ( 0 != u3r_bytes_fit(32, pub_y, pub) ) { + // hoon asserts size + return u3m_bail(c3__exit); + } + if ( 0 != u3r_bytes_fit(64, sek_y, sek) ) { + // hoon asserts size + return u3m_bail(c3__exit); + } + else if ( !u3r_word_fit(&len_w, len) ) { + return u3m_bail(c3__fail); + } + else { + c3_y sig_y[64]; + c3_y* dat_y = u3r_bytes_alloc(0, len_w, dat); + urcrypt_ed_sign_raw(dat_y, len_w, pub_y, sek_y, sig_y); + u3a_free(dat_y); + return u3i_bytes(64, sig_y); + } + } + + u3_noun + u3wee_sign_octs_raw(u3_noun cor) + { + u3_noun msg, pub, sek; + u3_noun len, dat; + if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_6, &pub, u3x_sam_7, &sek, 0) || + c3n == u3r_cell(msg, &len, &dat) || + c3n == u3ud(pub) || + c3n == u3ud(sek) || + c3n == u3ud(len) || + c3n == u3ud(dat) ) { + return u3m_bail(c3__fail); + } else { + return _cqee_sign_octs_raw(len, dat, pub, sek); + } + } + + static u3_atom + _cqee_sign(u3_noun msg, + u3_noun sed) { c3_y sed_y[32]; - if ( 0 != u3r_bytes_fit(32, sed_y, b) ) { - // hoon calls suck, which calls puck, which crashes + if ( 0 != u3r_bytes_fit(32, sed_y, sed) ) { + // hoon calls luck, which crashes return u3m_bail(c3__exit); } else { c3_y sig_y[64]; c3_w met_w; - c3_y* mes_y = u3r_bytes_all(&met_w, a); + c3_y* msg_y = u3r_bytes_all(&met_w, msg); - urcrypt_ed_sign(mes_y, met_w, sed_y, sig_y); - u3a_free(mes_y); + urcrypt_ed_sign(msg_y, met_w, sed_y, sig_y); + u3a_free(msg_y); return u3i_bytes(64, sig_y); } @@ -67,11 +112,55 @@ u3_noun u3wee_sign(u3_noun cor) { - u3_noun a, b; + u3_noun msg, sed; + if ( c3n == u3r_mean(cor, + u3x_sam_2, &msg, u3x_sam_3, &sed, 0) || + c3n == u3ud(msg) || + c3n == u3ud(sed) ) { + return u3m_bail(c3__fail); + } else { + return _cqee_sign(msg, sed); + } + } + + static u3_atom + _cqee_sign_raw(u3_noun msg, + u3_noun pub, + u3_noun sek) + { + c3_y pub_y[32], sek_y[64]; + + if ( 0 != u3r_bytes_fit(32, pub_y, pub) ) { + // hoon asserts size + return u3m_bail(c3__exit); + } + if ( 0 != u3r_bytes_fit(64, sek_y, sek) ) { + // hoon asserts size + return u3m_bail(c3__exit); + } + else { + c3_y sig_y[64]; + c3_w met_w; + c3_y* msg_y = u3r_bytes_all(&met_w, msg); + + urcrypt_ed_sign_raw(msg_y, met_w, pub_y, sek_y, sig_y); + u3a_free(msg_y); + + return u3i_bytes(64, sig_y); + } + } + + u3_noun + u3wee_sign_raw(u3_noun cor) + { + u3_noun msg, pub, sek; if ( c3n == u3r_mean(cor, - u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + u3x_sam_2, &msg, u3x_sam_6, &pub, u3x_sam_7, &sek, 0) || + c3n == u3ud(msg) || + c3n == u3ud(pub) || + c3n == u3ud(sek) ) { return u3m_bail(c3__fail); } else { - return _cqee_sign(a, b); + return _cqee_sign_raw(msg, pub, sek); } } diff --git a/pkg/noun/jets/e/ed_smac.c b/pkg/noun/jets/e/ed_smac.c new file mode 100644 index 0000000000..ce0ffac0d6 --- /dev/null +++ b/pkg/noun/jets/e/ed_smac.c @@ -0,0 +1,73 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" +#include "urcrypt.h" + + static u3_atom + _cqee_smac(u3_atom a, + u3_atom b, + u3_atom c) + { + c3_y a_y[32], b_y[32], c_y[32], out_y[32]; + c3_w met_w; + + met_w = u3r_met(3, a); + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, a)) ) + ) { + u3_noun a_recs = u3qee_recs(a); + u3r_bytes(0, 32, a_y, a_recs); + u3z(a_recs); + } else { + u3r_bytes(0, 32, a_y, a); + } + + met_w = u3r_met(3, b); + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, b)) ) + ) { + u3_noun b_recs = u3qee_recs(b); + u3r_bytes(0, 32, b_y, b_recs); + u3z(b_recs); + } else { + u3r_bytes(0, 32, b_y, b); + } + + met_w = u3r_met(3, c); + if ( (32 < met_w) || + ( (32 == met_w) && + (127 < u3r_byte(31, c)) ) + ) { + u3_noun c_recs = u3qee_recs(c); + u3r_bytes(0, 32, c_y, c_recs); + u3z(c_recs); + } else { + u3r_bytes(0, 32, c_y, c); + } + + urcrypt_ed_scalar_muladd(a_y, b_y, c_y, out_y); + return u3i_bytes(32, out_y); + } + + u3_noun + u3wee_smac(u3_noun cor) + { + u3_noun a, b, c; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, + u3x_sam_6, &b, + u3x_sam_7, &c, 0)) || + (c3n == u3ud(a)) || + (c3n == u3ud(b)) || + (c3n == u3ud(c)) ) + { + return u3m_bail(c3__exit); + } else { + return _cqee_smac(a, b, c); + } + } diff --git a/pkg/noun/jets/e/ed_veri.c b/pkg/noun/jets/e/ed_veri.c index 82649fb939..6d7b7502f8 100644 --- a/pkg/noun/jets/e/ed_veri.c +++ b/pkg/noun/jets/e/ed_veri.c @@ -17,8 +17,7 @@ if ( (0 != u3r_bytes_fit(64, sig_y, sig)) || (0 != u3r_bytes_fit(32, pub_y, pub)) || !u3r_word_fit(&len_w, len) ) { - // hoon checks sizes, but weirdly and without crashes - return u3_none; + return c3n; } else { c3_y* dat_y = u3r_bytes_alloc(0, len_w, dat); @@ -37,10 +36,14 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &sig, u3x_sam_6, &msg, u3x_sam_7, &pub, 0) || - c3n == u3r_cell(msg, &len, &dat) ){ + c3n == u3r_cell(msg, &len, &dat) || + (c3n == u3ud(sig)) || + (c3n == u3ud(pub)) || + (c3n == u3ud(len)) || + (c3n == u3ud(dat)) ) { return u3m_bail(c3__fail); } else { - return u3l_punt("veri-octs", _cqee_veri_octs(sig, len, dat, pub)); + return _cqee_veri_octs(sig, len, dat, pub); } } @@ -53,8 +56,7 @@ if ( (0 != u3r_bytes_fit(64, sig_y, s)) || (0 != u3r_bytes_fit(32, pub_y, pk)) ) { - // hoon checks sizes, but weirdly and without crashes - return u3_none; + return c3n; } else { c3_w met_w; @@ -70,11 +72,14 @@ u3wee_veri(u3_noun cor) { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, - u3x_sam_7, &c, 0) ) { + u3x_sam_7, &c, 0)) || + (c3n == u3ud(a)) || + (c3n == u3ud(b)) || + (c3n == u3ud(c)) ) { return u3m_bail(c3__fail); } else { - return u3l_punt("veri", _cqee_veri(a, b, c)); + return _cqee_veri(a, b, c); } } diff --git a/pkg/noun/jets/q.h b/pkg/noun/jets/q.h index a12d4766a8..5160058a9d 100644 --- a/pkg/noun/jets/q.h +++ b/pkg/noun/jets/q.h @@ -157,6 +157,8 @@ u3_noun u3qea_de(u3_atom, u3_atom); u3_noun u3qea_en(u3_atom, u3_atom); + u3_noun u3qee_recs(u3_atom); + u3_atom u3qe_fein_ob(u3_atom pyn); u3_atom u3qe_fynd_ob(u3_atom pyn); diff --git a/pkg/noun/jets/w.h b/pkg/noun/jets/w.h index 78494314fe..340ecf2bad 100644 --- a/pkg/noun/jets/w.h +++ b/pkg/noun/jets/w.h @@ -193,12 +193,23 @@ u3_noun u3weo_raw(u3_noun); + u3_noun u3wee_scad(u3_noun); + u3_noun u3wee_scas(u3_noun); + u3_noun u3wee_scap(u3_noun); + u3_noun u3wee_puck(u3_noun); + u3_noun u3wee_luck(u3_noun); u3_noun u3wee_sign(u3_noun); + u3_noun u3wee_sign_raw(u3_noun); u3_noun u3wee_veri(u3_noun); u3_noun u3wee_sign_octs(u3_noun); + u3_noun u3wee_sign_octs_raw(u3_noun); u3_noun u3wee_veri_octs(u3_noun); u3_noun u3wee_shar(u3_noun); + u3_noun u3wee_slar(u3_noun); + u3_noun u3wee_recs(u3_noun); + u3_noun u3wee_smac(u3_noun); + u3_noun u3wee_point_neg(u3_noun); u3_noun u3wee_point_add(u3_noun); u3_noun u3wee_scalarmult(u3_noun); u3_noun u3wee_scalarmult_base(u3_noun);