Skip to content

Commit

Permalink
zif/ed-luck: add luck:ed, sign-raw:ed, sign-octs-raw:ed
Browse files Browse the repository at this point in the history
  • Loading branch information
xiphiness committed Dec 2, 2024
1 parent ed83f3b commit 7c0acf7
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ext/urcrypt/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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/0e1ccd5d80531d11013b255b529a3a0e91985d08.tar.gz",
.hash = "122029a2c9ad5eeefb6ee757765d599aafcacbf9a70ce586c1771a3a6171ee3265e1",
},
},
.paths = .{
Expand Down
1 change: 1 addition & 0 deletions pkg/noun/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const c_source_files = [_][]const u8{
"jets/e/ed_add_scalarmult_scalarmult_base.c",
"jets/e/ed_point_add.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",
Expand Down
10 changes: 9 additions & 1 deletion pkg/noun/jets/137/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ static u3j_core _137_hex__crc_d[] = {{"crc32", 7, _137_hex__crc32_a, 0, no_hashe


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_shar_a[] = {{".2", u3wee_shar}, {}};

Expand All @@ -133,8 +137,12 @@ 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 },
{ "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 },
Expand Down
37 changes: 37 additions & 0 deletions pkg/noun/jets/e/ed_luck.c
Original file line number Diff line number Diff line change
@@ -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);
}
}
113 changes: 95 additions & 18 deletions pkg/noun/jets/e/ed_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include <types.h>

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 suck, which calls luck, which crashes
return u3m_bail(c3__exit);
}
else if ( !u3r_word_fit(&len_w, len) ) {
Expand All @@ -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);
}
Expand All @@ -32,33 +32,71 @@
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, &sed, 0) ||
c3n == u3r_cell(msg, &len, &dat) ) {
return u3m_bail(c3__fail);
} else {
return _cqee_sign_octs(len, dat, sed);
}
}

static u3_atom
_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 calls suck, which calls luck, which crashes
return u3m_bail(c3__exit);
}
if ( 0 != u3r_bytes_fit(64, sek_y, sek) ) {
// hoon calls suck, which calls luck, which crashes
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_3, &key, 0) ||
if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_6, &pub, u3x_sam_7, &sek, 0) ||
c3n == u3r_cell(msg, &len, &dat) ) {
return u3m_bail(c3__fail);
} else {
return _cqee_sign_octs(len, dat, key);
return _cqee_sign_octs_raw(len, dat, pub, sek);
}
}

static u3_atom
_cqee_sign(u3_noun a,
u3_noun b)
_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 suck, which 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);
}
Expand All @@ -67,11 +105,50 @@
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) ) {
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 calls suck, which calls luck, which crashes
return u3m_bail(c3__exit);
}
if ( 0 != u3r_bytes_fit(64, sek_y, sek) ) {
// hoon calls suck, which calls luck, which crashes
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) ) {
return u3m_bail(c3__fail);
} else {
return _cqee_sign(a, b);
return _cqee_sign_raw(msg, pub, sek);
}
}
3 changes: 3 additions & 0 deletions pkg/noun/jets/w.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@
u3_noun u3weo_raw(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_point_add(u3_noun);
Expand Down

0 comments on commit 7c0acf7

Please sign in to comment.