mirror of
https://github.com/urbit/shrub.git
synced 2024-12-13 16:03:36 +03:00
Jet for +add:ed:crypto
This commit is contained in:
parent
4f486cd3d5
commit
683de2ed52
@ -155,6 +155,7 @@
|
||||
u3_noun u3wee_sign(u3_noun);
|
||||
u3_noun u3wee_veri(u3_noun);
|
||||
u3_noun u3wee_shar(u3_noun);
|
||||
u3_noun u3wee_point_add(u3_noun);
|
||||
u3_noun u3wee_double_scalarmult(u3_noun);
|
||||
u3_noun u3wee_scalarmult_base(u3_noun);
|
||||
|
||||
|
79
jets/e/ed_point_add.c
Normal file
79
jets/e/ed_point_add.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* gen164/5/ed_point_add.c
|
||||
**
|
||||
*/
|
||||
#include "all.h"
|
||||
|
||||
|
||||
#include <ed25519.h>
|
||||
#include <ge.h>
|
||||
|
||||
/* functions
|
||||
*/
|
||||
u3_noun
|
||||
u3qc_point_add(u3_atom a,
|
||||
u3_atom b)
|
||||
{
|
||||
c3_y met_w;
|
||||
|
||||
met_w = u3r_met(3, a);
|
||||
if (met_w > 32) {
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
c3_y a_y[32];
|
||||
memset(a_y, 0, 32);
|
||||
u3r_bytes(0, met_w, a_y, a);
|
||||
|
||||
met_w = u3r_met(3, b);
|
||||
if (met_w > 32) {
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
c3_y b_y[32];
|
||||
memset(b_y, 0, 32);
|
||||
u3r_bytes(0, met_w, b_y, b);
|
||||
|
||||
ge_p3 A;
|
||||
if (ge_frombytes_negate_vartime(&A, a_y) != 0) {
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
|
||||
ge_p3 B;
|
||||
if (ge_frombytes_negate_vartime(&B, b_y) != 0) {
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
|
||||
// Undo the negation from above. See add_scalar.c in the ed25519 distro.
|
||||
fe_neg(A.X, A.X);
|
||||
fe_neg(A.T, A.T);
|
||||
fe_neg(B.X, B.X);
|
||||
fe_neg(B.T, B.T);
|
||||
|
||||
ge_cached b_cached;
|
||||
ge_p3_to_cached(&b_cached, &B);
|
||||
|
||||
ge_p1p1 sum;
|
||||
ge_add(&sum, &A, &b_cached);
|
||||
|
||||
ge_p3 result;
|
||||
ge_p1p1_to_p3(&result, &sum);
|
||||
|
||||
c3_y output_y[32];
|
||||
ge_p3_tobytes(output_y, &result);
|
||||
|
||||
return u3i_bytes(32, output_y);
|
||||
}
|
||||
|
||||
u3_noun
|
||||
u3wee_point_add(u3_noun cor)
|
||||
{
|
||||
u3_noun a, b;
|
||||
|
||||
if ( (c3n == u3r_mean(cor, u3x_sam_2, &a,
|
||||
u3x_sam_3, &b, 0)) ||
|
||||
(c3n == u3ud(a)) ||
|
||||
(c3n == u3ud(b)) )
|
||||
{
|
||||
return u3m_bail(c3__exit);
|
||||
} else {
|
||||
return u3qc_point_add(a, b);
|
||||
}
|
||||
}
|
@ -175,6 +175,9 @@ static c3_c* _141_hex_coed__ed_shar_ha[] = {
|
||||
0
|
||||
};
|
||||
|
||||
static u3j_harm _141_hex_coed__ed_add_a[] =
|
||||
{{".2", u3wee_point_add}, {}};
|
||||
|
||||
static u3j_harm _141_hex_coed__ed_double_scalarmult_a[] =
|
||||
{{".2", u3wee_double_scalarmult}, {}};
|
||||
|
||||
@ -186,6 +189,7 @@ static u3j_core _141_hex_coed__ed_d[] =
|
||||
{ "puck", 7, _141_hex_coed__ed_puck_a, 0, _141_hex_coed__ed_puck_ha },
|
||||
{ "veri", 7, _141_hex_coed__ed_veri_a, 0, _141_hex_coed__ed_veri_ha },
|
||||
{ "shar", 7, _141_hex_coed__ed_shar_a, 0, _141_hex_coed__ed_shar_ha },
|
||||
{ "add", 7, _141_hex_coed__ed_add_a, 0, 0 },
|
||||
{ "scalarmult-base", 7, _141_hex_coed__ed_scalarmult_a, 0, 0 },
|
||||
{ "double-scalarmult", 7, _141_hex_coed__ed_double_scalarmult_a, 0, 0 },
|
||||
{}
|
||||
|
@ -137,6 +137,7 @@ jets_e_ed_src = [
|
||||
'jets/e/ed_sign.c',
|
||||
'jets/e/ed_veri.c',
|
||||
'jets/e/ed_shar.c',
|
||||
'jets/e/ed_point_add.c',
|
||||
'jets/e/ed_scalarmult_base.c',
|
||||
'jets/e/ed_double_scalarmult.c'
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user