rest of the unpacks

This commit is contained in:
Paul Driver 2020-08-04 16:58:38 -07:00
parent 4218308d04
commit c8714ebc54
9 changed files with 56 additions and 72 deletions

View File

@ -14,15 +14,15 @@
{
c3_y a_y[32], b_y[32], c_y[32], d_y[32], out_y[32];
if ( (0 == u3r_unpack(32, a_y, a)) &&
(0 == u3r_unpack(32, b_y, b)) &&
(0 == u3r_unpack(32, c_y, c)) &&
(0 == u3r_unpack(32, d_y, d)) &&
(0 == urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) ) {
return u3i_bytes(32, out_y);
if ( (0 != u3r_unpack(32, a_y, a)) ||
(0 != u3r_unpack(32, b_y, b)) ||
(0 != u3r_unpack(32, c_y, c)) ||
(0 != u3r_unpack(32, d_y, d)) ||
(0 != urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) ) {
return u3_none;
}
else {
return u3_none;
return u3i_bytes(32, out_y);
}
}

View File

@ -13,14 +13,14 @@
{
c3_y a_y[32], b_y[32], c_y[32], out_y[32];
if ( (0 == u3r_unpack(32, a_y, a)) &&
(0 == u3r_unpack(32, b_y, b)) &&
(0 == u3r_unpack(32, c_y, c)) &&
(0 == urcrypt_ed_add_scalarmult_scalarmult_base(a_y, b_y, c_y, out_y)) ) {
return u3i_bytes(32, out_y);
if ( (0 != u3r_unpack(32, a_y, a)) ||
(0 != u3r_unpack(32, b_y, b)) ||
(0 != u3r_unpack(32, c_y, c)) ||
(0 != urcrypt_ed_add_scalarmult_scalarmult_base(a_y, b_y, c_y, out_y)) ) {
return u3_none;
}
else {
return u3_none;
return u3i_bytes(32, out_y);
}
}

View File

@ -13,13 +13,13 @@
{
c3_y a_y[32], b_y[32], out_y[32];
if ( (0 == u3r_unpack(32, a_y, a)) &&
(0 == u3r_unpack(32, b_y, b)) &&
(0 == urcrypt_ed_point_add(a_y, b_y, out_y)) ) {
return u3i_bytes(32, out_y);
if ( (0 != u3r_unpack(32, a_y, a)) ||
(0 != u3r_unpack(32, b_y, b)) ||
(0 != urcrypt_ed_point_add(a_y, b_y, out_y)) ) {
return u3_none;
}
else {
return u3_none;
return u3i_bytes(32, out_y);
}
}

View File

@ -9,17 +9,17 @@
static u3_atom
_cqee_puck(u3_atom sed)
{
c3_y sed_y[32], pub_y[32];
c3_w met_w;
c3_y sed_y[32];
if ( 0 == u3r_unpack(32, sed_y, sed) ) {
urcrypt_ed_puck(sed_y, pub_y);
return u3i_bytes(32, pub_y);
}
else {
if ( 0 != u3r_unpack(32, sed_y, sed) ) {
// hoon explicitly crashes on mis-size
return u3m_bail(c3__exit);
}
else {
c3_y pub_y[32];
urcrypt_ed_puck(sed_y, pub_y);
return u3i_bytes(32, pub_y);
}
}
u3_noun

View File

@ -12,15 +12,15 @@
{
c3_y a_y[32], b_y[32], out_y[32];
if ( (0 == u3r_unpack(32, a_y, a)) &&
(0 == u3r_unpack(32, b_y, b)) &&
(0 == urcrypt_ed_scalarmult(a_y, b_y, out_y)) ) {
return u3i_bytes(32, out_y);
}
else {
if ( (0 != u3r_unpack(32, a_y, a)) ||
(0 != u3r_unpack(32, b_y, b)) ||
(0 != urcrypt_ed_scalarmult(a_y, b_y, out_y)) ) {
// hoon does not check size of inputs
return u3_none;
}
else {
return u3i_bytes(32, out_y);
}
}
u3_noun

View File

@ -9,17 +9,13 @@
static u3_atom
_cqee_scalarmult_base(u3_atom a)
{
c3_w met_w = u3r_met(3, a);
c3_y a_y[32];
if ( met_w > 32 ) {
if ( 0 != u3r_unpack(32, a_y, a) ) {
return u3_none;
}
else {
c3_y a_y[32], out_y[32];
memset(a_y, 0, 32);
u3r_bytes(0, met_w, a_y, a);
c3_y out_y[32];
urcrypt_ed_scalarmult_base(a_y, out_y);
return u3i_bytes(32, out_y);
}

View File

@ -7,24 +7,18 @@
static u3_atom
_cqee_shar(u3_atom pub, u3_atom sek)
{
c3_w pet_w, set_w;
c3_y pub_y[32], sek_y[32];
if ( (pet_w = u3r_met(3, pub)) > 32 ) {
if ( 0 != u3r_unpack(32, pub_y, pub) ) {
// pub is not size checked in the hoon
return u3_none;
}
else if ( (set_w = u3r_met(3, sek)) > 32 ) {
else if ( 0 != u3r_unpack(32, sek_y, sek) ) {
// sek explicitly bails through suck
return u3m_bail(c3__exit);
}
else {
c3_y pub_y[32], sek_y[32], shr_y[32];
memset(pub_y, 0, 32);
memset(sek_y, 0, 32);
u3r_bytes(0, 32, pub_y, pub);
u3r_bytes(0, 32, sek_y, sek);
c3_y shr_y[32];
urcrypt_ed_shar(pub_y, sek_y, shr_y);
return u3i_bytes(32, shr_y);
}

View File

@ -10,24 +10,22 @@
_cqee_sign(u3_noun a,
u3_noun b)
{
c3_w b_w = u3r_met(3, b);
c3_y sed_y[32];
if ( b_w > 32 ) {
if ( 0 != u3r_unpack(32, sed_y, b) ) {
// hoon calls suck, which calls puck, which crashes
return u3m_bail(c3__exit);
}
else {
c3_w a_w = u3r_met(3, a);
c3_y* mes_y = u3a_malloc(a_w);
c3_y sed_y[32], sig_y[64];
memset(sed_y, 0, 32);
u3r_bytes(0, a_w, mes_y, a);
u3r_bytes(0, b_w, sed_y, b);
urcrypt_ed_sign(mes_y, a_w, sed_y, sig_y);
c3_y sig_y[64];
c3_y* mes_y;
c3_w met_w = u3r_met(3, a);
mes_y = u3a_malloc(met_w);
u3r_bytes(0, met_w, mes_y, a);
urcrypt_ed_sign(mes_y, met_w, sed_y, sig_y);
u3a_free(mes_y);
return u3i_bytes(64, sig_y);
}
}

View File

@ -11,28 +11,24 @@
u3_noun m,
u3_noun pk)
{
c3_w set_w, pek_w;
c3_y sig_y[64], pub_y[32];
if ( ((set_w = u3r_met(3, s)) > 64) ||
((pek_w = u3r_met(3, pk)) > 32) ) {
if ( (0 != u3r_unpack(64, sig_y, s)) ||
(0 != u3r_unpack(32, pub_y, pk)) ) {
// hoon checks sizes, but weirdly and without crashes
return u3_none;
}
else {
c3_y sig_y[64], pub_y[32];
c3_t val_t;
c3_y* mes_y;
c3_w met_w = u3r_met(3, m);
c3_y* mes_y = u3a_malloc(met_w);
c3_o ret_o;
memset(sig_y, 0, 64);
memset(pub_y, 0, 32);
u3r_bytes(0, 64, sig_y, s);
u3r_bytes(0, 32, pub_y, pk);
mes_y = u3a_malloc(met_w);
u3r_bytes(0, met_w, mes_y, m);
ret_o = urcrypt_ed_veri(mes_y, met_w, pub_y, sig_y) ? c3y : c3n;
val_t = urcrypt_ed_veri(mes_y, met_w, pub_y, sig_y);
u3a_free(mes_y);
return ret_o;
return val_t ? c3y : c3n;
}
}