begin move to u3r_unpack() (new function) for consistency in crypto jets

combining the padding and length checking into one function helps make
the crypto jets really boring and easy to scan, improving auditability.
This commit is contained in:
Paul Driver 2020-08-04 13:10:30 -07:00
parent 542bd55dc2
commit 84c959313d
3 changed files with 35 additions and 20 deletions

View File

@ -346,6 +346,15 @@
c3_y* c_y,
u3_atom d);
/* u3r_unpack():
**
** 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_chop():
**
** Into the bloq space of `met`, from position `fum` for a

View File

@ -12,29 +12,18 @@
u3_atom c,
u3_atom d)
{
c3_w ate_w, bet_w, get_w, det_w;
if ( ((ate_w = u3r_met(3, a)) > 32) ||
((bet_w = u3r_met(3, b)) > 32) ||
((get_w = u3r_met(3, c)) > 32) ||
((det_w = u3r_met(3, d)) > 32) ) {
return u3_none;
}
else {
c3_y a_y[32], b_y[32], c_y[32], d_y[32], out_y[32];
memset(a_y, 0, 32);
memset(b_y, 0, 32);
memset(c_y, 0, 32);
memset(d_y, 0, 32);
u3r_bytes(0, ate_w, a_y, a);
u3r_bytes(0, bet_w, b_y, b);
u3r_bytes(0, get_w, c_y, c);
u3r_bytes(0, det_w, d_y, d);
return ( 0 == urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y) )
? u3i_bytes(32, out_y)
: u3_none;
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);
}
else {
return u3_none;
}
}

View File

@ -1076,6 +1076,23 @@ u3r_bytes(c3_w a_w,
}
}
/* u3r_unpack():
**
** 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)
{
c3_w met_w = u3r_met(3, a);
if ( met_w <= len_w ) {
u3r_bytes(0, len_w, buf_y, a);
return 0;
}
else {
return len_w - met_w;
}
}
/* u3r_mp():
**
** Copy (b) into (a_mp).