Mercurial > hg > quicktun
annotate src/tweetnacl.c @ 71:86b8afcf65c7 default tip master
Fixed order of tar arguments in build script
author | Ivo Smits <Ivo@UFO-Net.nl> |
---|---|
date | Mon, 22 Jul 2019 21:12:13 +0200 |
parents | fa53d1c54886 |
children |
rev | line source |
---|---|
64
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
1 //TweetNaCl from https://tweetnacl.cr.yp.to/, public domain. |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
2 #include "tweetnacl.h" |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
3 #define FOR(i,n) for (i = 0;i < n;++i) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
4 #define sv static void |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
5 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
6 typedef unsigned char u8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
7 typedef unsigned long u32; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
8 typedef unsigned long long u64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
9 typedef long long i64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
10 typedef i64 gf[16]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
11 extern void randombytes(u8 *,u64); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
12 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
13 static const u8 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
14 _0[16], |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
15 _9[32] = {9}; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
16 static const gf |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
17 gf0, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
18 gf1 = {1}, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
19 _121665 = {0xDB41,1}, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
20 D = {0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203}, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
21 D2 = {0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406}, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
22 X = {0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169}, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
23 Y = {0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666}, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
24 I = {0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83}; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
25 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
26 static u32 L32(u32 x,int c) { return (x << c) | ((x&0xffffffff) >> (32 - c)); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
27 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
28 static u32 ld32(const u8 *x) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
29 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
30 u32 u = x[3]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
31 u = (u<<8)|x[2]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
32 u = (u<<8)|x[1]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
33 return (u<<8)|x[0]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
34 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
35 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
36 static u64 dl64(const u8 *x) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
37 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
38 u64 i,u=0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
39 FOR(i,8) u=(u<<8)|x[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
40 return u; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
41 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
42 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
43 sv st32(u8 *x,u32 u) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
44 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
45 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
46 FOR(i,4) { x[i] = u; u >>= 8; } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
47 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
48 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
49 sv ts64(u8 *x,u64 u) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
50 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
51 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
52 for (i = 7;i >= 0;--i) { x[i] = u; u >>= 8; } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
53 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
54 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
55 static int vn(const u8 *x,const u8 *y,int n) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
56 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
57 u32 i,d = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
58 FOR(i,n) d |= x[i]^y[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
59 return (1 & ((d - 1) >> 8)) - 1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
60 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
61 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
62 int crypto_verify_16(const u8 *x,const u8 *y) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
63 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
64 return vn(x,y,16); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
65 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
66 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
67 int crypto_verify_32(const u8 *x,const u8 *y) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
68 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
69 return vn(x,y,32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
70 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
71 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
72 sv core(u8 *out,const u8 *in,const u8 *k,const u8 *c,int h) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
73 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
74 u32 w[16],x[16],y[16],t[4]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
75 int i,j,m; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
76 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
77 FOR(i,4) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
78 x[5*i] = ld32(c+4*i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
79 x[1+i] = ld32(k+4*i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
80 x[6+i] = ld32(in+4*i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
81 x[11+i] = ld32(k+16+4*i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
82 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
83 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
84 FOR(i,16) y[i] = x[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
85 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
86 FOR(i,20) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
87 FOR(j,4) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
88 FOR(m,4) t[m] = x[(5*j+4*m)%16]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
89 t[1] ^= L32(t[0]+t[3], 7); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
90 t[2] ^= L32(t[1]+t[0], 9); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
91 t[3] ^= L32(t[2]+t[1],13); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
92 t[0] ^= L32(t[3]+t[2],18); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
93 FOR(m,4) w[4*j+(j+m)%4] = t[m]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
94 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
95 FOR(m,16) x[m] = w[m]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
96 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
97 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
98 if (h) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
99 FOR(i,16) x[i] += y[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
100 FOR(i,4) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
101 x[5*i] -= ld32(c+4*i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
102 x[6+i] -= ld32(in+4*i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
103 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
104 FOR(i,4) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
105 st32(out+4*i,x[5*i]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
106 st32(out+16+4*i,x[6+i]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
107 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
108 } else |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
109 FOR(i,16) st32(out + 4 * i,x[i] + y[i]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
110 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
111 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
112 int crypto_core_salsa20(u8 *out,const u8 *in,const u8 *k,const u8 *c) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
113 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
114 core(out,in,k,c,0); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
115 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
116 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
117 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
118 int crypto_core_hsalsa20(u8 *out,const u8 *in,const u8 *k,const u8 *c) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
119 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
120 core(out,in,k,c,1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
121 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
122 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
123 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
124 static const u8 sigma[16] = "expand 32-byte k"; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
125 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
126 int crypto_stream_salsa20_xor(u8 *c,const u8 *m,u64 b,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
127 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
128 u8 z[16],x[64]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
129 u32 u,i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
130 if (!b) return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
131 FOR(i,16) z[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
132 FOR(i,8) z[i] = n[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
133 while (b >= 64) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
134 crypto_core_salsa20(x,z,k,sigma); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
135 FOR(i,64) c[i] = (m?m[i]:0) ^ x[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
136 u = 1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
137 for (i = 8;i < 16;++i) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
138 u += (u32) z[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
139 z[i] = u; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
140 u >>= 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
141 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
142 b -= 64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
143 c += 64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
144 if (m) m += 64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
145 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
146 if (b) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
147 crypto_core_salsa20(x,z,k,sigma); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
148 FOR(i,b) c[i] = (m?m[i]:0) ^ x[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
149 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
150 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
151 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
152 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
153 int crypto_stream_salsa20(u8 *c,u64 d,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
154 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
155 return crypto_stream_salsa20_xor(c,0,d,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
156 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
157 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
158 int crypto_stream(u8 *c,u64 d,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
159 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
160 u8 s[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
161 crypto_core_hsalsa20(s,n,k,sigma); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
162 return crypto_stream_salsa20(c,d,n+16,s); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
163 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
164 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
165 int crypto_stream_xor(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
166 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
167 u8 s[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
168 crypto_core_hsalsa20(s,n,k,sigma); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
169 return crypto_stream_salsa20_xor(c,m,d,n+16,s); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
170 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
171 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
172 sv add1305(u32 *h,const u32 *c) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
173 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
174 u32 j,u = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
175 FOR(j,17) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
176 u += h[j] + c[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
177 h[j] = u & 255; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
178 u >>= 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
179 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
180 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
181 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
182 static const u32 minusp[17] = { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
183 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
184 } ; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
185 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
186 int crypto_onetimeauth(u8 *out,const u8 *m,u64 n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
187 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
188 u32 s,i,j,u,x[17],r[17],h[17],c[17],g[17]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
189 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
190 FOR(j,17) r[j]=h[j]=0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
191 FOR(j,16) r[j]=k[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
192 r[3]&=15; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
193 r[4]&=252; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
194 r[7]&=15; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
195 r[8]&=252; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
196 r[11]&=15; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
197 r[12]&=252; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
198 r[15]&=15; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
199 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
200 while (n > 0) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
201 FOR(j,17) c[j] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
202 for (j = 0;(j < 16) && (j < n);++j) c[j] = m[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
203 c[j] = 1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
204 m += j; n -= j; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
205 add1305(h,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
206 FOR(i,17) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
207 x[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
208 FOR(j,17) x[i] += h[j] * ((j <= i) ? r[i - j] : 320 * r[i + 17 - j]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
209 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
210 FOR(i,17) h[i] = x[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
211 u = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
212 FOR(j,16) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
213 u += h[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
214 h[j] = u & 255; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
215 u >>= 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
216 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
217 u += h[16]; h[16] = u & 3; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
218 u = 5 * (u >> 2); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
219 FOR(j,16) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
220 u += h[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
221 h[j] = u & 255; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
222 u >>= 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
223 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
224 u += h[16]; h[16] = u; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
225 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
226 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
227 FOR(j,17) g[j] = h[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
228 add1305(h,minusp); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
229 s = -(h[16] >> 7); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
230 FOR(j,17) h[j] ^= s & (g[j] ^ h[j]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
231 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
232 FOR(j,16) c[j] = k[j + 16]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
233 c[16] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
234 add1305(h,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
235 FOR(j,16) out[j] = h[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
236 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
237 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
238 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
239 int crypto_onetimeauth_verify(const u8 *h,const u8 *m,u64 n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
240 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
241 u8 x[16]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
242 crypto_onetimeauth(x,m,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
243 return crypto_verify_16(h,x); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
244 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
245 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
246 int crypto_secretbox(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
247 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
248 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
249 if (d < 32) return -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
250 crypto_stream_xor(c,m,d,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
251 crypto_onetimeauth(c + 16,c + 32,d - 32,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
252 FOR(i,16) c[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
253 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
254 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
255 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
256 int crypto_secretbox_open(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
257 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
258 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
259 u8 x[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
260 if (d < 32) return -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
261 crypto_stream(x,32,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
262 if (crypto_onetimeauth_verify(c + 16,c + 32,d - 32,x) != 0) return -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
263 crypto_stream_xor(m,c,d,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
264 FOR(i,32) m[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
265 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
266 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
267 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
268 sv set25519(gf r, const gf a) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
269 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
270 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
271 FOR(i,16) r[i]=a[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
272 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
273 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
274 sv car25519(gf o) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
275 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
276 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
277 i64 c; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
278 FOR(i,16) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
279 o[i]+=(1LL<<16); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
280 c=o[i]>>16; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
281 o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
282 o[i]-=c<<16; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
283 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
284 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
285 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
286 sv sel25519(gf p,gf q,int b) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
287 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
288 i64 t,i,c=~(b-1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
289 FOR(i,16) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
290 t= c&(p[i]^q[i]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
291 p[i]^=t; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
292 q[i]^=t; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
293 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
294 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
295 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
296 sv pack25519(u8 *o,const gf n) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
297 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
298 int i,j,b; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
299 gf m,t; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
300 FOR(i,16) t[i]=n[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
301 car25519(t); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
302 car25519(t); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
303 car25519(t); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
304 FOR(j,2) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
305 m[0]=t[0]-0xffed; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
306 for(i=1;i<15;i++) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
307 m[i]=t[i]-0xffff-((m[i-1]>>16)&1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
308 m[i-1]&=0xffff; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
309 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
310 m[15]=t[15]-0x7fff-((m[14]>>16)&1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
311 b=(m[15]>>16)&1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
312 m[14]&=0xffff; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
313 sel25519(t,m,1-b); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
314 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
315 FOR(i,16) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
316 o[2*i]=t[i]&0xff; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
317 o[2*i+1]=t[i]>>8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
318 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
319 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
320 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
321 static int neq25519(const gf a, const gf b) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
322 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
323 u8 c[32],d[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
324 pack25519(c,a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
325 pack25519(d,b); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
326 return crypto_verify_32(c,d); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
327 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
328 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
329 static u8 par25519(const gf a) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
330 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
331 u8 d[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
332 pack25519(d,a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
333 return d[0]&1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
334 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
335 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
336 sv unpack25519(gf o, const u8 *n) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
337 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
338 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
339 FOR(i,16) o[i]=n[2*i]+((i64)n[2*i+1]<<8); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
340 o[15]&=0x7fff; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
341 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
342 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
343 sv A(gf o,const gf a,const gf b) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
344 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
345 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
346 FOR(i,16) o[i]=a[i]+b[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
347 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
348 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
349 sv Z(gf o,const gf a,const gf b) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
350 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
351 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
352 FOR(i,16) o[i]=a[i]-b[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
353 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
354 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
355 sv M(gf o,const gf a,const gf b) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
356 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
357 i64 i,j,t[31]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
358 FOR(i,31) t[i]=0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
359 FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
360 FOR(i,15) t[i]+=38*t[i+16]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
361 FOR(i,16) o[i]=t[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
362 car25519(o); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
363 car25519(o); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
364 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
365 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
366 sv S(gf o,const gf a) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
367 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
368 M(o,a,a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
369 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
370 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
371 sv inv25519(gf o,const gf i) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
372 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
373 gf c; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
374 int a; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
375 FOR(a,16) c[a]=i[a]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
376 for(a=253;a>=0;a--) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
377 S(c,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
378 if(a!=2&&a!=4) M(c,c,i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
379 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
380 FOR(a,16) o[a]=c[a]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
381 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
382 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
383 sv pow2523(gf o,const gf i) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
384 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
385 gf c; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
386 int a; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
387 FOR(a,16) c[a]=i[a]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
388 for(a=250;a>=0;a--) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
389 S(c,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
390 if(a!=1) M(c,c,i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
391 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
392 FOR(a,16) o[a]=c[a]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
393 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
394 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
395 int crypto_scalarmult(u8 *q,const u8 *n,const u8 *p) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
396 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
397 u8 z[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
398 i64 x[80],r,i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
399 gf a,b,c,d,e,f; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
400 FOR(i,31) z[i]=n[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
401 z[31]=(n[31]&127)|64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
402 z[0]&=248; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
403 unpack25519(x,p); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
404 FOR(i,16) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
405 b[i]=x[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
406 d[i]=a[i]=c[i]=0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
407 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
408 a[0]=d[0]=1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
409 for(i=254;i>=0;--i) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
410 r=(z[i>>3]>>(i&7))&1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
411 sel25519(a,b,r); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
412 sel25519(c,d,r); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
413 A(e,a,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
414 Z(a,a,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
415 A(c,b,d); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
416 Z(b,b,d); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
417 S(d,e); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
418 S(f,a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
419 M(a,c,a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
420 M(c,b,e); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
421 A(e,a,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
422 Z(a,a,c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
423 S(b,a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
424 Z(c,d,f); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
425 M(a,c,_121665); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
426 A(a,a,d); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
427 M(c,c,a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
428 M(a,d,f); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
429 M(d,b,x); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
430 S(b,e); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
431 sel25519(a,b,r); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
432 sel25519(c,d,r); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
433 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
434 FOR(i,16) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
435 x[i+16]=a[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
436 x[i+32]=c[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
437 x[i+48]=b[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
438 x[i+64]=d[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
439 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
440 inv25519(x+32,x+32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
441 M(x+16,x+16,x+32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
442 pack25519(q,x+16); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
443 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
444 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
445 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
446 int crypto_scalarmult_base(u8 *q,const u8 *n) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
447 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
448 return crypto_scalarmult(q,n,_9); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
449 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
450 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
451 int crypto_box_keypair(u8 *y,u8 *x) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
452 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
453 randombytes(x,32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
454 return crypto_scalarmult_base(y,x); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
455 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
456 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
457 int crypto_box_beforenm(u8 *k,const u8 *y,const u8 *x) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
458 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
459 u8 s[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
460 crypto_scalarmult(s,x,y); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
461 return crypto_core_hsalsa20(k,_0,s,sigma); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
462 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
463 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
464 int crypto_box_afternm(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
465 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
466 return crypto_secretbox(c,m,d,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
467 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
468 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
469 int crypto_box_open_afternm(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *k) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
470 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
471 return crypto_secretbox_open(m,c,d,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
472 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
473 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
474 int crypto_box(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *y,const u8 *x) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
475 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
476 u8 k[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
477 crypto_box_beforenm(k,y,x); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
478 return crypto_box_afternm(c,m,d,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
479 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
480 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
481 int crypto_box_open(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *y,const u8 *x) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
482 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
483 u8 k[32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
484 crypto_box_beforenm(k,y,x); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
485 return crypto_box_open_afternm(m,c,d,n,k); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
486 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
487 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
488 static u64 R(u64 x,int c) { return (x >> c) | (x << (64 - c)); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
489 static u64 Ch(u64 x,u64 y,u64 z) { return (x & y) ^ (~x & z); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
490 static u64 Maj(u64 x,u64 y,u64 z) { return (x & y) ^ (x & z) ^ (y & z); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
491 static u64 Sigma0(u64 x) { return R(x,28) ^ R(x,34) ^ R(x,39); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
492 static u64 Sigma1(u64 x) { return R(x,14) ^ R(x,18) ^ R(x,41); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
493 static u64 sigma0(u64 x) { return R(x, 1) ^ R(x, 8) ^ (x >> 7); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
494 static u64 sigma1(u64 x) { return R(x,19) ^ R(x,61) ^ (x >> 6); } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
495 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
496 static const u64 K[80] = |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
497 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
498 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
499 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
500 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
501 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
502 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
503 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
504 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
505 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
506 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
507 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
508 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
509 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
510 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
511 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
512 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
513 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
514 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
515 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
516 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
517 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
518 }; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
519 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
520 int crypto_hashblocks(u8 *x,const u8 *m,u64 n) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
521 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
522 u64 z[8],b[8],a[8],w[16],t; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
523 int i,j; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
524 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
525 FOR(i,8) z[i] = a[i] = dl64(x + 8 * i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
526 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
527 while (n >= 128) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
528 FOR(i,16) w[i] = dl64(m + 8 * i); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
529 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
530 FOR(i,80) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
531 FOR(j,8) b[j] = a[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
532 t = a[7] + Sigma1(a[4]) + Ch(a[4],a[5],a[6]) + K[i] + w[i%16]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
533 b[7] = t + Sigma0(a[0]) + Maj(a[0],a[1],a[2]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
534 b[3] += t; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
535 FOR(j,8) a[(j+1)%8] = b[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
536 if (i%16 == 15) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
537 FOR(j,16) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
538 w[j] += w[(j+9)%16] + sigma0(w[(j+1)%16]) + sigma1(w[(j+14)%16]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
539 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
540 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
541 FOR(i,8) { a[i] += z[i]; z[i] = a[i]; } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
542 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
543 m += 128; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
544 n -= 128; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
545 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
546 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
547 FOR(i,8) ts64(x+8*i,z[i]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
548 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
549 return n; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
550 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
551 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
552 static const u8 iv[64] = { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
553 0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
554 0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
555 0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
556 0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
557 0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
558 0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
559 0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b, |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
560 0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
561 } ; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
562 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
563 int crypto_hash(u8 *out,const u8 *m,u64 n) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
564 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
565 u8 h[64],x[256]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
566 u64 i,b = n; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
567 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
568 FOR(i,64) h[i] = iv[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
569 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
570 crypto_hashblocks(h,m,n); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
571 m += n; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
572 n &= 127; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
573 m -= n; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
574 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
575 FOR(i,256) x[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
576 FOR(i,n) x[i] = m[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
577 x[n] = 128; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
578 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
579 n = 256-128*(n<112); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
580 x[n-9] = b >> 61; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
581 ts64(x+n-8,b<<3); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
582 crypto_hashblocks(h,x,n); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
583 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
584 FOR(i,64) out[i] = h[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
585 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
586 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
587 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
588 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
589 sv add(gf p[4],gf q[4]) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
590 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
591 gf a,b,c,d,t,e,f,g,h; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
592 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
593 Z(a, p[1], p[0]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
594 Z(t, q[1], q[0]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
595 M(a, a, t); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
596 A(b, p[0], p[1]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
597 A(t, q[0], q[1]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
598 M(b, b, t); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
599 M(c, p[3], q[3]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
600 M(c, c, D2); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
601 M(d, p[2], q[2]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
602 A(d, d, d); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
603 Z(e, b, a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
604 Z(f, d, c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
605 A(g, d, c); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
606 A(h, b, a); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
607 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
608 M(p[0], e, f); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
609 M(p[1], h, g); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
610 M(p[2], g, f); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
611 M(p[3], e, h); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
612 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
613 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
614 sv cswap(gf p[4],gf q[4],u8 b) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
615 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
616 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
617 FOR(i,4) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
618 sel25519(p[i],q[i],b); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
619 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
620 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
621 sv pack(u8 *r,gf p[4]) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
622 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
623 gf tx, ty, zi; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
624 inv25519(zi, p[2]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
625 M(tx, p[0], zi); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
626 M(ty, p[1], zi); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
627 pack25519(r, ty); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
628 r[31] ^= par25519(tx) << 7; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
629 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
630 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
631 sv scalarmult(gf p[4],gf q[4],const u8 *s) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
632 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
633 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
634 set25519(p[0],gf0); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
635 set25519(p[1],gf1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
636 set25519(p[2],gf1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
637 set25519(p[3],gf0); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
638 for (i = 255;i >= 0;--i) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
639 u8 b = (s[i/8]>>(i&7))&1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
640 cswap(p,q,b); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
641 add(q,p); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
642 add(p,p); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
643 cswap(p,q,b); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
644 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
645 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
646 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
647 sv scalarbase(gf p[4],const u8 *s) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
648 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
649 gf q[4]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
650 set25519(q[0],X); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
651 set25519(q[1],Y); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
652 set25519(q[2],gf1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
653 M(q[3],X,Y); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
654 scalarmult(p,q,s); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
655 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
656 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
657 int crypto_sign_keypair(u8 *pk, u8 *sk) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
658 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
659 u8 d[64]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
660 gf p[4]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
661 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
662 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
663 randombytes(sk, 32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
664 crypto_hash(d, sk, 32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
665 d[0] &= 248; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
666 d[31] &= 127; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
667 d[31] |= 64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
668 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
669 scalarbase(p,d); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
670 pack(pk,p); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
671 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
672 FOR(i,32) sk[32 + i] = pk[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
673 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
674 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
675 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
676 static const u64 L[32] = {0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10}; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
677 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
678 sv modL(u8 *r,i64 x[64]) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
679 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
680 i64 carry,i,j; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
681 for (i = 63;i >= 32;--i) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
682 carry = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
683 for (j = i - 32;j < i - 12;++j) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
684 x[j] += carry - 16 * x[i] * L[j - (i - 32)]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
685 carry = (x[j] + 128) >> 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
686 x[j] -= carry << 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
687 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
688 x[j] += carry; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
689 x[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
690 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
691 carry = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
692 FOR(j,32) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
693 x[j] += carry - (x[31] >> 4) * L[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
694 carry = x[j] >> 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
695 x[j] &= 255; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
696 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
697 FOR(j,32) x[j] -= carry * L[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
698 FOR(i,32) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
699 x[i+1] += x[i] >> 8; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
700 r[i] = x[i] & 255; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
701 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
702 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
703 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
704 sv reduce(u8 *r) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
705 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
706 i64 x[64],i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
707 FOR(i,64) x[i] = (u64) r[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
708 FOR(i,64) r[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
709 modL(r,x); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
710 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
711 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
712 int crypto_sign(u8 *sm,u64 *smlen,const u8 *m,u64 n,const u8 *sk) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
713 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
714 u8 d[64],h[64],r[64]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
715 i64 i,j,x[64]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
716 gf p[4]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
717 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
718 crypto_hash(d, sk, 32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
719 d[0] &= 248; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
720 d[31] &= 127; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
721 d[31] |= 64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
722 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
723 *smlen = n+64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
724 FOR(i,n) sm[64 + i] = m[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
725 FOR(i,32) sm[32 + i] = d[32 + i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
726 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
727 crypto_hash(r, sm+32, n+32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
728 reduce(r); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
729 scalarbase(p,r); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
730 pack(sm,p); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
731 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
732 FOR(i,32) sm[i+32] = sk[i+32]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
733 crypto_hash(h,sm,n + 64); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
734 reduce(h); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
735 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
736 FOR(i,64) x[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
737 FOR(i,32) x[i] = (u64) r[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
738 FOR(i,32) FOR(j,32) x[i+j] += h[i] * (u64) d[j]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
739 modL(sm + 32,x); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
740 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
741 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
742 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
743 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
744 static int unpackneg(gf r[4],const u8 p[32]) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
745 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
746 gf t, chk, num, den, den2, den4, den6; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
747 set25519(r[2],gf1); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
748 unpack25519(r[1],p); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
749 S(num,r[1]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
750 M(den,num,D); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
751 Z(num,num,r[2]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
752 A(den,r[2],den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
753 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
754 S(den2,den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
755 S(den4,den2); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
756 M(den6,den4,den2); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
757 M(t,den6,num); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
758 M(t,t,den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
759 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
760 pow2523(t,t); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
761 M(t,t,num); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
762 M(t,t,den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
763 M(t,t,den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
764 M(r[0],t,den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
765 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
766 S(chk,r[0]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
767 M(chk,chk,den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
768 if (neq25519(chk, num)) M(r[0],r[0],I); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
769 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
770 S(chk,r[0]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
771 M(chk,chk,den); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
772 if (neq25519(chk, num)) return -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
773 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
774 if (par25519(r[0]) == (p[31]>>7)) Z(r[0],gf0,r[0]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
775 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
776 M(r[3],r[0],r[1]); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
777 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
778 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
779 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
780 int crypto_sign_open(u8 *m,u64 *mlen,const u8 *sm,u64 n,const u8 *pk) |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
781 { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
782 int i; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
783 u8 t[32],h[64]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
784 gf p[4],q[4]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
785 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
786 *mlen = -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
787 if (n < 64) return -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
788 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
789 if (unpackneg(q,pk)) return -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
790 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
791 FOR(i,n) m[i] = sm[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
792 FOR(i,32) m[i+32] = pk[i]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
793 crypto_hash(h,m,n); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
794 reduce(h); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
795 scalarmult(p,q,h); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
796 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
797 scalarbase(q,sm + 32); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
798 add(p,q); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
799 pack(t,p); |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
800 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
801 n -= 64; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
802 if (crypto_verify_32(sm, t)) { |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
803 FOR(i,n) m[i] = 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
804 return -1; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
805 } |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
806 |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
807 FOR(i,n) m[i] = sm[i + 64]; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
808 *mlen = n; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
809 return 0; |
fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
Ivo Smits <Ivo@UFO-Net.nl>
parents:
diff
changeset
|
810 } |