Skip to content

Commit

Permalink
zif/ed-reform: add jets for scad:ed, scas:ed, scap:ed
Browse files Browse the repository at this point in the history
  • Loading branch information
xiphiness committed Dec 2, 2024
1 parent 7c0acf7 commit 3819014
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 2 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/0e1ccd5d80531d11013b255b529a3a0e91985d08.tar.gz",
.hash = "122029a2c9ad5eeefb6ee757765d599aafcacbf9a70ce586c1771a3a6171ee3265e1",
.url = "https://github.com/urbit/urcrypt/archive/9599acb4e12002ddb1c39591bb9477621f848470.tar.gz",
.hash = "12203c3694e5871a0a6b70cef76cc0fab15a8eb1dabbb4d1fe14f454a738db41a53f",
},
},
.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 @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions pkg/noun/jets/137/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}, {}};
Expand Down Expand Up @@ -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 },
Expand Down
117 changes: 117 additions & 0 deletions pkg/noun/jets/e/ed_scad.c
Original file line number Diff line number Diff line change
@@ -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);
}
}


4 changes: 4 additions & 0 deletions pkg/noun/jets/w.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3819014

Please sign in to comment.