Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jets for secp tap tweaking #759

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ext/urcrypt/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
.hash = "1220bb683a6df744e618f58a008eaae3eb62b70a78334cec676bd82b1b9e8e944eeb",
},
.urcrypt = .{
.url = "https://github.com/urbit/urcrypt/archive/e77a0998809f7552c455cf7bf8c1b68c141cce18.tar.gz",
.hash = "12202efcf40dcfed9a9b59bba4743cfd0c31364a6d7504724bd4d643b474ff69245b",
.path = "../../../urcrypt",
//.url = "https://github.com/urbit/urcrypt/archive/e77a0998809f7552c455cf7bf8c1b68c141cce18.tar.gz",
//.hash = "12202efcf40dcfed9a9b59bba4743cfd0c31364a6d7504724bd4d643b474ff69245b",
},
},
.paths = .{
Expand Down
26 changes: 16 additions & 10 deletions pkg/noun/jets.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,9 @@ _cj_kick_z(u3_noun cor, u3j_core* cop_u, u3j_harm* ham_u, u3_atom axe)
else {
u3_weak pro, ame;

ham_u->ice = c3y;
//ham_u->ice = c3y;
pro = ham_u->fun_f(cor);
ham_u->ice = c3n;
//ham_u->ice = c3n;

#ifdef U3_MEMORY_DEBUG
u3a_lop(cod_w);
Expand All @@ -893,23 +893,29 @@ _cj_kick_z(u3_noun cor, u3j_core* cop_u, u3j_harm* ham_u, u3_atom axe)
u3z(cor);
return pro;
}
ham_u->liv = c3n;
//ham_u->liv = c3n;
ame = _cj_soft(cor, axe);
ham_u->liv = c3y;
//ham_u->liv = c3y;

if ( c3n == u3r_sing(ame, pro) ) {
u3l_log("test: %s %s: mismatch: good %x, bad %x",
//u3l_log("test: %s %s: mismatch: good %x, bad %x",
// cop_u->cos_c,
// (!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c,
// u3r_mug(ame),
// u3r_mug(pro));
//ham_u->liv = c3n;
u3l_log("test: %s %s: mismatch",
cop_u->cos_c,
(!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c,
u3r_mug(ame),
u3r_mug(pro));
ham_u->liv = c3n;
(!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c
);
u3m_p("good", ame);
u3m_p("baad", pro);

return u3m_bail(c3__fail);
}
else {

#if 0
#if 1
u3l_log("test: %s %s",
cop_u->cos_c,
(!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c);
Expand Down
6 changes: 6 additions & 0 deletions pkg/noun/jets/137/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ static u3j_core _137_hex_scr_d[] =
static u3j_harm _137_hex_secp_secp256k1_make_a[] = {{".2", u3we_make, c3y}, {}};
static u3j_harm _137_hex_secp_secp256k1_sign_a[] = {{".2", u3we_sign, c3y}, {}};
static u3j_harm _137_hex_secp_secp256k1_reco_a[] = {{".2", u3we_reco, c3y}, {}};
static u3j_harm _137_hex_secp_secp256k1_priv_to_pub_a[] = {{".2", u3we_priv_to_pub, c3n}, {}};
static u3j_harm _137_hex_secp_secp256k1_tweak_sec_a[] = {{".2", u3we_tweak_sec, c3n}, {}};
static u3j_harm _137_hex_secp_secp256k1_tweak_pub_a[] = {{".2", u3we_tweak_pub, c3n}, {}};

static u3j_harm _137_hex_secp_secp256k1_schnorr_sosi_a[] =
{{".2", u3we_sosi}, {}};
Expand All @@ -202,6 +205,9 @@ static u3j_core _137_hex_secp_secp256k1_d[] =
{ { "make", 7, _137_hex_secp_secp256k1_make_a, 0, no_hashes },
{ "sign", 7, _137_hex_secp_secp256k1_sign_a, 0, no_hashes },
{ "reco", 7, _137_hex_secp_secp256k1_reco_a, 0, no_hashes },
{ "priv-to-pub", 7, _137_hex_secp_secp256k1_priv_to_pub_a, 0, no_hashes },
{ "tweak-sec", 7, _137_hex_secp_secp256k1_tweak_sec_a, 0, no_hashes },
{ "tweak-pub", 7, _137_hex_secp_secp256k1_tweak_pub_a, 0, no_hashes },
{ "schnorr", 7, 0,
_137_hex_secp_secp256k1_schnorr_d,
no_hashes },
Expand Down
103 changes: 103 additions & 0 deletions pkg/noun/jets/e/secp.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,106 @@ u3we_sove(u3_noun cor)
return _cqes_sove(pub, mes, sig);
}
}

static u3_atom
_cqes_tweak_sec(u3_atom sek, u3_atom tek) {
c3_y scalar[32], tweak[32];

if (0 != u3r_bytes_fit(32, scalar, sek)) {
return u3m_bail(c3__exit);
}

if (0 != u3r_bytes_fit(32, tweak, tek)) {
return u3m_bail(c3__exit);
}

if (0 != urcrypt_secp_scalar_tweak_add(sec_u, scalar, tweak)) {
return u3m_bail(c3__exit);
}

return u3i_bytes(32, scalar);
}

u3_noun
u3we_tweak_sec(u3_noun cor)
{
u3_noun sek, tek;

if ( (c3n == u3r_mean(cor,
u3x_sam_2, &sek,
u3x_sam_3, &tek,
0)) ||
(c3n == u3ud(sek)) ||
(c3n == u3ud(tek))) {
return u3m_bail(c3__exit);
}
else {
return _cqes_tweak_sec(sek, tek);
}
}

static u3_atom
_cqes_tweak_pub(u3_atom pub, u3_atom tek) {
c3_y cmp_point[33], tweak[32];

if (0 != u3r_bytes_fit(33, cmp_point, pub)) {
return u3m_bail(c3__exit);
}

if (0 != u3r_bytes_fit(32, tweak, tek)) {
return u3m_bail(c3__exit);
}

if (0 != urcrypt_secp_cmp_point_tweak_add(sec_u, cmp_point, tweak)) {
return u3m_bail(c3__exit);
}

return u3i_bytes(33, cmp_point);
}

u3_noun
u3we_tweak_pub(u3_noun cor)
{
u3_noun pub, tek;

if ( (c3n == u3r_mean(cor,
u3x_sam_2, &pub,
u3x_sam_3, &tek,
0)) ||
(c3n == u3ud(pub)) ||
(c3n == u3ud(tek))) {
return u3m_bail(c3__exit);
}
else {
return _cqes_tweak_pub(pub, tek);
}
}

static u3_noun
_cqes_priv_to_pub(u3_atom sek) {
c3_y scalar[32], cmp_point[33];

if (0 != u3r_bytes_fit(32, scalar, sek)) {
return u3m_bail(c3__exit);
}

if (0 != urcrypt_secp_cmp_point_from_scalar(sec_u, scalar, cmp_point)) {
return u3m_bail(c3__exit);
}

return u3i_bytes(33, cmp_point);
}

u3_noun
u3we_priv_to_pub(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 _cqes_priv_to_pub(a);
}
}
4 changes: 4 additions & 0 deletions pkg/noun/jets/w.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@
u3_noun u3we_sosi(u3_noun);
u3_noun u3we_sove(u3_noun);

u3_noun u3we_priv_to_pub(u3_noun);
u3_noun u3we_tweak_sec(u3_noun);
u3_noun u3we_tweak_pub(u3_noun);

u3_noun u3we_en_base16(u3_noun);
u3_noun u3we_de_base16(u3_noun);

Expand Down