shrub/j/5/ed_sign.c

52 lines
974 B
C
Raw Normal View History

2014-04-11 05:05:59 +04:00
/* gen164/5/ed_sign.c
**
** This file is in the public domain.
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2014-04-11 05:05:59 +04:00
#include <ed25519.h>
/* functions
*/
2014-09-06 00:13:24 +04:00
static u3_noun
_cqee_sign(u3_noun a, u3_noun b)
2014-04-11 05:05:59 +04:00
{
c3_y sig_y[64];
2014-04-17 07:15:49 +04:00
c3_y sed_y[32];
c3_y pub_y[64];
c3_y sec_y[64];
2014-04-11 05:05:59 +04:00
2014-09-06 00:13:24 +04:00
c3_w mesm_w = u3_cr_met(3, a);
c3_w mess_w = u3_cr_met(3, b);
2014-04-11 05:05:59 +04:00
c3_y* mes_y = 0;
memset(sig_y, 0, 64);
memset(sed_y, 0, 32);
memset(pub_y, 0, 64);
memset(sec_y, 0, 64);
mes_y = malloc(mesm_w);
2014-09-06 00:13:24 +04:00
u3_cr_bytes(0, mesm_w, mes_y, a);
u3_cr_bytes(0, mess_w, sed_y, b);
2014-04-11 05:05:59 +04:00
2014-04-17 07:15:49 +04:00
ed25519_create_keypair(pub_y, sec_y, sed_y);
2014-04-11 05:05:59 +04:00
ed25519_sign(sig_y, mes_y, mesm_w, pub_y, sec_y);
free(mes_y);
2014-09-06 00:13:24 +04:00
return u3_ci_bytes(64, sig_y);
2014-04-11 05:05:59 +04:00
}
2014-09-04 01:33:18 +04:00
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwee_sign(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
if ( u3_no == u3_cr_mean(cor,
u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ) {
return u3_cm_bail(c3__fail);
} else {
2014-09-04 01:33:18 +04:00
return _cqee_sign(a, b);
}
}