From 381901482c756e89b213077dec975211f02e5f8f Mon Sep 17 00:00:00 2001 From: ziffee Date: Mon, 2 Dec 2024 19:30:33 +0700 Subject: [PATCH] zif/ed-reform: add jets for scad:ed, scas:ed, scap:ed --- ext/urcrypt/build.zig.zon | 4 +- pkg/noun/build.zig | 1 + pkg/noun/jets/137/tree.c | 7 +++ pkg/noun/jets/e/ed_scad.c | 117 ++++++++++++++++++++++++++++++++++++++ pkg/noun/jets/w.h | 4 ++ 5 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 pkg/noun/jets/e/ed_scad.c diff --git a/ext/urcrypt/build.zig.zon b/ext/urcrypt/build.zig.zon index 4cea9a2722..396ca83376 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/0e1ccd5d80531d11013b255b529a3a0e91985d08.tar.gz", - .hash = "122029a2c9ad5eeefb6ee757765d599aafcacbf9a70ce586c1771a3a6171ee3265e1", + .url = "https://github.com/urbit/urcrypt/archive/9599acb4e12002ddb1c39591bb9477621f848470.tar.gz", + .hash = "12203c3694e5871a0a6b70cef76cc0fab15a8eb1dabbb4d1fe14f454a738db41a53f", }, }, .paths = .{ diff --git a/pkg/noun/build.zig b/pkg/noun/build.zig index a6785c4ef3..276d29a2d4 100644 --- a/pkg/noun/build.zig +++ b/pkg/noun/build.zig @@ -273,6 +273,7 @@ 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_scad.c", "jets/e/ed_puck.c", "jets/e/ed_luck.c", "jets/e/ed_scalarmult.c", diff --git a/pkg/noun/jets/137/tree.c b/pkg/noun/jets/137/tree.c index 85ab0fc2aa..9b8b4c95c8 100644 --- a/pkg/noun/jets/137/tree.c +++ b/pkg/noun/jets/137/tree.c @@ -112,6 +112,10 @@ 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}, {}}; @@ -143,6 +147,9 @@ static u3j_core _137_hex_coed__ed_d[] = { "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 }, { "shar", 7, _137_hex_coed__ed_shar_a, 0, no_hashes }, { "point-add", 7, _137_hex_coed__ed_point_add_a, 0, 0 }, diff --git a/pkg/noun/jets/e/ed_scad.c b/pkg/noun/jets/e/ed_scad.c new file mode 100644 index 0000000000..81735d6e30 --- /dev/null +++ b/pkg/noun/jets/e/ed_scad.c @@ -0,0 +1,117 @@ +/// @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) ) { + 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) ) { + 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) ) { + return u3m_bail(c3__exit); + } + else { + return _cqee_scap(pub, sca); + } + } + + diff --git a/pkg/noun/jets/w.h b/pkg/noun/jets/w.h index f025c3b527..e84c3c8912 100644 --- a/pkg/noun/jets/w.h +++ b/pkg/noun/jets/w.h @@ -193,6 +193,10 @@ 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);