1#include <string.h>
2#include "crypto_sign.h"
3#include "crypto_hash_sha512.h"
4#include "ge.h"
5#include "sc.h"
6
7int crypto_sign(
8 unsigned char *sm,
9 const unsigned char *m,unsigned long long mlen,
10 const unsigned char *pw,unsigned long long pwlen
11)
12{
13 unsigned char az[64];
14 unsigned char nonce[64];
15 unsigned char hram[64];
16 ge_p3 A, R;
17
18 crypto_hash_sha512(az,pw,pwlen);
19 az[0] &= 248;
20 az[31] &= 63;
21 az[31] |= 64;
22
23 memmove(sm + 64,m,mlen);
24 memmove(sm + 32,az + 32,32);
25 crypto_hash_sha512(nonce,sm + 32,mlen + 32);
26
27 ge_scalarmult_base(&A,az);
28 ge_p3_tobytes(sm + 32,&A);
29
30 sc_reduce(nonce);
31 ge_scalarmult_base(&R,nonce);
32 ge_p3_tobytes(sm,&R);
33
34 crypto_hash_sha512(hram,sm,mlen + 64);
35 sc_reduce(hram);
36 sc_muladd(sm + 32,hram,az,nonce);
37
38 return 0;
39}
40