shrub/gen164/5/ed_sign.c

65 lines
1.5 KiB
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"
#include "../pit.h"
#include <ed25519.h>
/* functions
*/
u2_weak // transfer
j2_mcc(Pt5, ed, sign)(u2_wire wir_r,
2014-04-17 07:15:49 +04:00
u2_noun a, // retain
u2_noun b) // retain
2014-04-11 05:05:59 +04:00
{
c3_y sig_y[64];
2014-04-17 07:15:49 +04:00
c3_y sec_y[32];
2014-04-11 05:05:59 +04:00
c3_y pub_y[32];
2014-04-17 07:15:49 +04:00
c3_y sed_y[32];
2014-04-11 05:05:59 +04:00
c3_w secm_w = u2_met(3, b);
c3_w mesm_w = u2_met(3, a);
c3_y* mes_y = 0;
2014-04-11 05:05:59 +04:00
if ( 64 < secm_w ) {
return u2_bl_bail(wir_r, c3__exit);
}
memset(&sig_y, 64, 0);
memset(&pub_y, 32, 0);
2014-04-11 05:05:59 +04:00
mes_y = c3_malloc(mesm_w);
2014-04-17 07:15:49 +04:00
memset(sec_y, 0, 32);
2014-04-11 05:05:59 +04:00
u2_cr_bytes(0, mesm_w, mes_y, a);
2014-04-17 07:15:49 +04:00
u2_cr_bytes(0, 32, 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);
return u2_ci_bytes(64, sig_y);
}
u2_weak
j2_md(Pt5, coed, ed, sign)(u2_wire wir_r,
u2_noun cor)
{
2014-04-17 07:15:49 +04:00
u2_noun a, b;
if ( u2_no == u2_mean(cor,
2014-04-17 07:15:49 +04:00
u2_cv_sam_2, &a, u2_cv_sam_3, &b, 0) ) {
return u2_bl_bail(wir_r, c3__fail);
} else {
2014-04-17 07:15:49 +04:00
return j2_mcc(Pt5, ed, sign)(wir_r, a, b);
}
}
2014-04-11 05:05:59 +04:00
/* structures
*/
u2_ho_jet
j2_mdj(Pt5, coed, ed, sign)[] = {
{ ".2", c3__lite, j2_md(Pt5, coed, ed, sign), u2_jet_test|u2_jet_live, u2_none, u2_none },
2014-04-11 05:05:59 +04:00
{ }
};