mirror of
https://github.com/urbit/shrub.git
synced 2024-12-20 09:21:42 +03:00
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:
parent
542bd55dc2
commit
84c959313d
@ -346,6 +346,15 @@
|
|||||||
c3_y* c_y,
|
c3_y* c_y,
|
||||||
u3_atom d);
|
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():
|
/* u3r_chop():
|
||||||
**
|
**
|
||||||
** Into the bloq space of `met`, from position `fum` for a
|
** Into the bloq space of `met`, from position `fum` for a
|
||||||
|
@ -12,29 +12,18 @@
|
|||||||
u3_atom c,
|
u3_atom c,
|
||||||
u3_atom d)
|
u3_atom d)
|
||||||
{
|
{
|
||||||
c3_w ate_w, bet_w, get_w, det_w;
|
c3_y a_y[32], b_y[32], c_y[32], d_y[32], out_y[32];
|
||||||
|
|
||||||
if ( ((ate_w = u3r_met(3, a)) > 32) ||
|
if ( (0 == u3r_unpack(32, a_y, a)) &&
|
||||||
((bet_w = u3r_met(3, b)) > 32) ||
|
(0 == u3r_unpack(32, b_y, b)) &&
|
||||||
((get_w = u3r_met(3, c)) > 32) ||
|
(0 == u3r_unpack(32, c_y, c)) &&
|
||||||
((det_w = u3r_met(3, d)) > 32) ) {
|
(0 == u3r_unpack(32, d_y, d)) &&
|
||||||
return u3_none;
|
(0 == urcrypt_ed_add_double_scalarmult(a_y, b_y, c_y, d_y, out_y)) )
|
||||||
|
{
|
||||||
|
return u3i_bytes(32, out_y);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c3_y a_y[32], b_y[32], c_y[32], d_y[32], out_y[32];
|
return u3_none;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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():
|
/* u3r_mp():
|
||||||
**
|
**
|
||||||
** Copy (b) into (a_mp).
|
** Copy (b) into (a_mp).
|
||||||
|
Loading…
Reference in New Issue
Block a user