rename u3r_unpack->u3r_bytes_fit, u3r_unpack_alloc->u3r_bytes_all

This commit is contained in:
Paul Driver 2020-08-11 11:12:25 -07:00
parent 6fdc65dea6
commit 6deec62292
12 changed files with 32 additions and 31 deletions

View File

@ -346,21 +346,22 @@
c3_y* c_y,
u3_atom d);
/* u3r_unpack():
/* u3r_bytes_fit():
**
** Copy (len_w) bytes of (a) into (buf_y) if it fits, returning overage
*/
c3_w
u3r_unpack(c3_w len_w,
c3_y *buf_y,
u3r_bytes_fit(c3_w len_w,
c3_y* buf_y,
u3_atom a);
/* u3r_unpack_alloc():
/* u3r_bytes_all():
**
** Allocate a new byte array with all the bytes of (a)
*/
c3_y*
u3r_unpack_alloc(c3_w* len_w, u3_atom a);
u3r_bytes_all(c3_w* len_w,
u3_atom a);
/* u3r_chop():
**

View File

@ -25,7 +25,7 @@ typedef c3_y* (*urcrypt_cbc)(const c3_y*,
u3r_bytes(0, 16, iv_y, iv);
msg_y = u3r_unpack_alloc(&met_w, msg);
msg_y = u3r_bytes_all(&met_w, msg);
out_y = (*low_f)(msg_y, met_w, key_y, iv_y, &len);
u3a_free(msg_y);

View File

@ -14,10 +14,10 @@
{
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)) ||
if ( (0 != u3r_bytes_fit(32, a_y, a)) ||
(0 != u3r_bytes_fit(32, b_y, b)) ||
(0 != u3r_bytes_fit(32, c_y, c)) ||
(0 != u3r_bytes_fit(32, d_y, d)) ||
(0 != urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) ) {
return u3_none;
}

View File

@ -13,9 +13,9 @@
{
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)) ||
if ( (0 != u3r_bytes_fit(32, a_y, a)) ||
(0 != u3r_bytes_fit(32, b_y, b)) ||
(0 != u3r_bytes_fit(32, c_y, c)) ||
(0 != urcrypt_ed_add_scalarmult_scalarmult_base(a_y, b_y, c_y, out_y)) ) {
return u3_none;
}

View File

@ -13,8 +13,8 @@
{
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)) ||
if ( (0 != u3r_bytes_fit(32, a_y, a)) ||
(0 != u3r_bytes_fit(32, b_y, b)) ||
(0 != urcrypt_ed_point_add(a_y, b_y, out_y)) ) {
return u3_none;
}

View File

@ -11,7 +11,7 @@
{
c3_y sed_y[32];
if ( 0 != u3r_unpack(32, sed_y, sed) ) {
if ( 0 != u3r_bytes_fit(32, sed_y, sed) ) {
// hoon explicitly crashes on mis-size
return u3m_bail(c3__exit);
}

View File

@ -12,8 +12,8 @@
{
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)) ||
if ( (0 != u3r_bytes_fit(32, a_y, a)) ||
(0 != u3r_bytes_fit(32, b_y, b)) ||
(0 != urcrypt_ed_scalarmult(a_y, b_y, out_y)) ) {
// hoon does not check size of inputs
return u3_none;

View File

@ -11,7 +11,7 @@
{
c3_y a_y[32];
if ( 0 != u3r_unpack(32, a_y, a) ) {
if ( 0 != u3r_bytes_fit(32, a_y, a) ) {
return u3_none;
}
else {

View File

@ -9,11 +9,11 @@
{
c3_y pub_y[32], sek_y[32];
if ( 0 != u3r_unpack(32, pub_y, pub) ) {
if ( 0 != u3r_bytes_fit(32, pub_y, pub) ) {
// pub is not size checked in the hoon
return u3_none;
}
else if ( 0 != u3r_unpack(32, sek_y, sek) ) {
else if ( 0 != u3r_bytes_fit(32, sek_y, sek) ) {
// sek explicitly bails through suck
return u3m_bail(c3__exit);
}

View File

@ -12,14 +12,14 @@
{
c3_y sed_y[32];
if ( 0 != u3r_unpack(32, sed_y, b) ) {
if ( 0 != u3r_bytes_fit(32, sed_y, b) ) {
// hoon calls suck, which calls puck, which crashes
return u3m_bail(c3__exit);
}
else {
c3_y sig_y[64];
c3_w met_w;
c3_y* mes_y = u3r_unpack_alloc(&met_w, a);
c3_y* mes_y = u3r_bytes_all(&met_w, a);
urcrypt_ed_sign(mes_y, met_w, sed_y, sig_y);
u3a_free(mes_y);

View File

@ -13,14 +13,14 @@
{
c3_y sig_y[64], pub_y[32];
if ( (0 != u3r_unpack(64, sig_y, s)) ||
(0 != u3r_unpack(32, pub_y, pk)) ) {
if ( (0 != u3r_bytes_fit(64, sig_y, s)) ||
(0 != u3r_bytes_fit(32, pub_y, pk)) ) {
// hoon checks sizes, but weirdly and without crashes
return u3_none;
}
else {
c3_w met_w;
c3_y* mes_y = u3r_unpack_alloc(&met_w, m);
c3_y* mes_y = u3r_bytes_all(&met_w, m);
c3_t val_t = urcrypt_ed_veri(mes_y, met_w, pub_y, sig_y);
u3a_free(mes_y);

View File

@ -1076,12 +1076,12 @@ u3r_bytes(c3_w a_w,
}
}
/* u3r_unpack():
/* u3r_bytes_fit():
**
** Copy (len_w) bytes of (a) into (buf_y) if it fits, returning overage
*/
c3_w
u3r_unpack(c3_w len_w, c3_y *buf_y, u3_atom a)
u3r_bytes_fit(c3_w len_w, c3_y *buf_y, u3_atom a)
{
c3_w met_w = u3r_met(3, a);
if ( met_w <= len_w ) {
@ -1093,12 +1093,12 @@ u3r_unpack(c3_w len_w, c3_y *buf_y, u3_atom a)
}
}
/* u3r_unpack_alloc():
/* u3r_bytes_all():
**
** Allocate a new byte array with all the bytes of (a)
*/
c3_y*
u3r_unpack_alloc(c3_w* len_w, u3_atom a)
u3r_bytes_all(c3_w* len_w, u3_atom a)
{
c3_w met_w = u3r_met(3, a);
c3_y* a_y = u3a_malloc(met_w);