libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_sign / ed25519 / ref10 / sign.c
blob49507b0287a849fa81a6be91cc328b972f0b409d
1 #include "api.h"
2 #include "crypto_hash_sha512.h"
3 #include "ge.h"
4 #include "sc.h"
6 int crypto_sign(
7 unsigned char *sm,unsigned long long *smlen,
8 const unsigned char *m,unsigned long long mlen,
9 const unsigned char *sk
12 unsigned char az[64];
13 unsigned char r[64];
14 unsigned char hram[64];
15 ge_p3 R;
16 unsigned long long i;
18 crypto_hash_sha512(az,sk,32);
19 az[0] &= 248;
20 az[31] &= 63;
21 az[31] |= 64;
23 *smlen = mlen + 64;
24 for (i = 0;i < mlen;++i) sm[64 + i] = m[i];
25 for (i = 0;i < 32;++i) sm[32 + i] = az[32 + i];
26 crypto_hash_sha512(r,sm + 32,mlen + 32);
27 for (i = 0;i < 32;++i) sm[32 + i] = sk[32 + i];
29 sc_reduce(r);
30 ge_scalarmult_base(&R,r);
31 ge_p3_tobytes(sm,&R);
33 crypto_hash_sha512(hram,sm,mlen + 64);
34 sc_reduce(hram);
35 sc_muladd(sm + 32,hram,az,r);
37 return 0;