ed_sign moved to urcrypt

This commit is contained in:
Paul Driver 2020-07-30 14:40:47 -07:00
parent 74d06deb1b
commit 6cb81fe084
4 changed files with 43 additions and 27 deletions

View File

@ -6,7 +6,6 @@
/* functions
*/
// TODO: should these exits be u3_none or bail: fail instead?
u3_noun
u3qc_scalarmult(u3_atom a,
u3_atom b)
@ -15,11 +14,12 @@
c3_y a_y[32], b_y[32], out_y[32];
if ( (ate_w = u3r_met(3, a)) > 32 ) {
return u3m_bail(c3__exit);
// hoon does not check size of inputs
return u3_none;
}
if ( (bet_w = u3r_met(3, b)) > 32 ) {
return u3m_bail(c3__exit);
return u3_none;
}
memset(a_y, 0, 32);
@ -28,7 +28,8 @@
u3r_bytes(0, bet_w, b_y, b);
if ( 0 != urcrypt_ed_scalarmult(a_y, b_y, out_y) ) {
return u3m_bail(c3__exit);
// this is unlikely to happen, but there is a return code.
return u3_none;
}
return u3i_bytes(32, out_y);

View File

@ -2,9 +2,7 @@
**
*/
#include "all.h"
#include <ed25519.h>
#include <urcrypt.h>
/* functions
*/
@ -12,30 +10,26 @@
_cqee_sign(u3_noun a,
u3_noun b)
{
c3_y sig_y[64];
c3_y sed_y[32];
c3_y pub_y[64];
c3_y sec_y[64];
c3_w b_w = u3r_met(3, b);
c3_w mesm_w = u3r_met(3, a);
c3_w mess_w = u3r_met(3, b);
if ( b_w > 32 ) {
// 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];
c3_y* mes_y = 0;
memset(sed_y, 0, 32);
u3r_bytes(0, a_w, mes_y, a);
u3r_bytes(0, b_w, sed_y, b);
memset(sig_y, 0, 64);
memset(sed_y, 0, 32);
memset(pub_y, 0, 64);
memset(sec_y, 0, 64);
urcrypt_ed_sign(mes_y, a_w, sed_y, sig_y);
mes_y = u3a_malloc(mesm_w);
u3r_bytes(0, mesm_w, mes_y, a);
u3r_bytes(0, mess_w, sed_y, b);
ed25519_create_keypair(pub_y, sec_y, sed_y);
ed25519_sign(sig_y, mes_y, mesm_w, pub_y, sec_y);
u3a_free(mes_y);
return u3i_bytes(64, sig_y);
u3a_free(mes_y);
return u3i_bytes(64, sig_y);
}
}
u3_noun

View File

@ -17,3 +17,19 @@ urcrypt_ed_scalarmult(uint8_t a[32], uint8_t b[32], uint8_t out[32])
ge_p3_tobytes(out, &result);
return 0;
}
void
urcrypt_ed_sign(uint8_t *message,
size_t length,
uint8_t seed[32],
uint8_t out[64])
{
uint8_t public[64], secret[64];
memset(public, 0, 64);
memset(secret, 0, 64);
memset(out, 0, 64);
ed25519_create_keypair(public, secret, seed);
ed25519_sign(out, message, length, public, secret);
}

View File

@ -2,9 +2,14 @@
#define URCRYPT_H
#include <stdint.h>
#include <string.h>
#include <ed25519.h>
#include <ge-additions.h>
int urcrypt_ed_scalarmult(uint8_t a[32], uint8_t b[32], uint8_t out[32]);
void urcrypt_ed_sign(uint8_t *message,
size_t length,
uint8_t seed[32],
uint8_t signature[64]);
#endif