Skip to content

Commit

Permalink
first hack at sign:ed jet
Browse files Browse the repository at this point in the history
  • Loading branch information
vvisigoth committed Apr 11, 2014
1 parent e4d9b2e commit 60a9dc3
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ endif
LIBS=-lssl -lcrypto -lgmp -lncurses -lsigsegv $(OSLIBS)

INCLUDE=include
GENERATED=generated
MDEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"

CFLAGS= -O2 -g \
Expand All @@ -63,7 +62,7 @@ CFLAGS= -O2 -g \
-Ioutside/libuv/include \
-Ioutside/re2 \
-Ioutside/cre2/src/src \
-I $(GENERATED) \
-Ioutside/ed25519/src \
$(DEFINES) \
$(MDEFINES)

Expand Down Expand Up @@ -163,6 +162,7 @@ J164_4_OFILES=\

J164_5_OFILES=\
gen164/5/cue.o \
gen164/5/ed.o \
gen164/5/jam.o \
gen164/5/mat.o \
gen164/5/mink.o \
Expand All @@ -176,6 +176,9 @@ J164_5_OFILES=\
gen164/5/tape.o \
gen164/5/trip.o

J164_5_OFILES_ED=\
gen164/5/ed_sign.o

J164_6_OFILES=\
gen164/6/al.o \
gen164/6/ap.o \
Expand Down Expand Up @@ -234,6 +237,7 @@ J164_OFILES=\
$(J164_3_OFILES) \
$(J164_4_OFILES) \
$(J164_5_OFILES) \
$(J164_5_OFILES_ED) \
$(J164_6_OFILES) \
$(J164_6_OFILES_UT) \
gen164/watt.o
Expand Down Expand Up @@ -303,7 +307,7 @@ etags:
etags -f .etags $$(find -name '*.c' -or -name '*.h')

clean:
$(RM) $(VERE_OFILES) $(BIN)/vere $(BIN)/eyre
$(RM) $(VERE_OFILES) $(BIN)/vere
$(MAKE) -C outside/libuv clean
$(MAKE) -C outside/re2 clean
$(MAKE) -C outside/ed25519 clean
Expand Down
22 changes: 22 additions & 0 deletions gen164/5/ed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* gen164/5/ed.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"

/* declarations
*/
extern u2_ho_jet j2_mcj(Pt5, ed, sign)[];

/* structures
*/
u2_ho_driver
j2_mbd(Pt5, ed)[] = {
{ j2_sc(Pt5, ed, sign), j2_mcj(Pt5, ed, sign), 0, 0, u2_none },
{}
};

u2_ho_driver
j2_db(Pt5, ed) =
{ j2_sb(Pt5, ed), 0, j2_mbd(Pt5, ed), 0, u2_none };
51 changes: 51 additions & 0 deletions gen164/5/ed_sign.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* 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_mc(Pt5, ed, sign)(u2_wire wir_r,
u2_noun a, // retain
u2_noun b, // retain
u2_noun c) // retain
{
c3_y sig_y[64];
c3_y sec_y[64];
c3_y pub_y[32];

c3_w secm_w = u2_met(3, b);
c3_w pubm_w = u2_met(3, c);

c3_w mesm_w = u2_met(3, a);

c3_y* mes_y = 0;

if ( 64 < secm_w ) {
return u2_bl_bail(wir_r, c3__exit);
}
if ( 32 < pubm_w ) {
return u2_bl_bail(wir_r, c3__exit);
}

mes_y = c3_malloc(mesm_w);
u2_cr_bytes(0, mesm_w, mes_y, a);
u2_cr_bytes(0, 64, sec_y, b);
u2_cr_bytes(0, 32, pub_y, c);

ed25519_sign(sig_y, mes_y, mesm_w, pub_y, sec_y);
free(mes_y);
return u2_ci_bytes(64, sig_y);
}
/* structures
*/
u2_ho_jet
j2_mcj(Pt5, ed, sign)[] = {
{ ".2", c3__lite, j2_mc(Pt5, ed, sign), u2_jet_test|u2_jet_live, u2_none, u2_none },
{ }
};
135 changes: 135 additions & 0 deletions urb/zod/arvo/hoon.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -3954,6 +3954,141 @@
$(hel t.hel, hev t.hev, rag (done %| [i.hel ~] [i.hev ~]))
--
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: section 2eX, ed25519 signatures ::
::
++ ed :: ed25519
~/ %ed
=> =+ b=256
=+ q=(sub (bex 255) 19)
=+ fq=~(. fo q)
=+ ^= l
%+ add
(bex 252)
27.742.317.777.372.353.535.851.937.790.883.648.493
=+ d=(dif.fq 0 (fra.fq 121.665 121.666))
=+ ii=(exp.fq (div (dec q) 4) 2)
|%
++ norm |=(x=@ ?:(=(0 (mod x 2)) x (sub q x)))
::
++ xrec :: recover x-coord
|= y=@ ^- @
=+ ^= xx
%+ mul (dif.fq (mul y y) 1)
(inv.fq +(:(mul d y y)))
=+ x=(exp.fq (div (add 3 q) 8) xx)
?: !=(0 (dif.fq (mul x x) (sit.fq xx)))
(norm (pro.fq x ii))
(norm x)
::
++ ward :: edwards multiply
|= [pp=[@ @] qq=[@ @]] ^- [@ @]
=+ dp=:(pro.fq d -.pp -.qq +.pp +.qq)
=+ ^= xt
%+ pro.fq
%+ sum.fq
(pro.fq -.pp +.qq)
(pro.fq -.qq +.pp)
(inv.fq (sum.fq 1 dp))
=+ ^= yt
%+ pro.fq
%+ sum.fq
(pro.fq +.pp +.qq)
(pro.fq -.pp -.qq)
(inv.fq (dif.fq 1 dp))
[xt yt]
::
++ scam :: scalar multiply
|= [pp=[@ @] e=@] ^- [@ @]
?: =(0 e)
[0 1]
=+ qq=$(e (div e 2))
=> .(qq (ward qq qq))
?: =(1 (dis 1 e))
(ward qq pp)
qq
::
++ etch :: encode point
|= pp=[@ @] ^- @
(can 0 ~[[(sub b 1) +.pp] [1 (dis 1 -.pp)]])
::
++ curv :: point on curve?
|= [x=@ y=@] ^- ?
.= 0
%+ dif.fq
%+ sum.fq
(pro.fq (sub q (sit.fq x)) x)
(pro.fq y y)
(sum.fq 1 :(pro.fq d x x y y))
::
++ deco :: decode point
|= s=@ ^- (unit ,[@ @])
=+ y=(cut 0 [0 (dec b)] s)
=+ si=(cut 0 [(dec b) 1] s)
=+ x=(xrec y)
=> .(x ?:(!=(si (dis 1 x)) (sub q x) x))
=+ pp=[x y]
?. (curv pp)
~
[~ pp]
::
--
=+ ^= bb
=+ bby=(pro.fq 4 (inv.fq 5))
[(xrec bby) bby]
|%
++ puck :: public key
|= sk=@ ^- @
=+ h=(shal (rsh 0 3 b) sk)
=+ ^= a
%+ add
(bex (sub b 2))
(lsh 0 3 (cut 0 [3 (sub b 5)] h))
=+ aa=(scam bb a)
(etch aa)
::
++ sign :: certify
|= [m=@ sk=@ pk=@] ^- @
=+ h=(shal (rsh 0 3 b) sk)
=+ ^= a
%+ add
(bex (sub b 2))
(lsh 0 3 (cut 0 [3 (sub b 5)] h))
=+ ^= r
=+ hm=(cut 0 [b b] h)
=+ ^= i
%+ can 0
:~ [b hm]
[(met 0 m) m]
==
(shaz i)
=+ rr=(scam bb r)
=+ ^= ss
=+ er=(etch rr)
=+ ^= ha
%+ can 0
:~ [b er]
[b pk]
[(met 0 m) m]
==
(~(sit fo l) (add r (mul (shaz ha) a)))
(can 0 ~[[b (etch rr)] [b ss]])
::
++ veri :: validate
~/ %veri
|= [s=@ m=@ pk=@] ^- ?
?: (gth (div b 4) (met 3 s)) |
?: (gth (div b 8) (met 3 pk)) |
=+ rr=(deco (cut 0 [0 b] s))
?~ rr |
=+ aa=(deco pk)
?~ aa |
=+ ss=(cut 0 [b b] s)
=+ ha=(can 0 ~[[b (etch u.rr)] [b pk] [(met 0 m) m]])
=+ h=(shaz ha)
=((scam bb ss) (ward u.rr (scam u.aa h)))
::
--
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: section 2eY, SHA-256 (move me) ::
::
++ shad |=(ruz=@ (shax (shax ruz))) :: double sha-256
Expand Down

0 comments on commit 60a9dc3

Please sign in to comment.