| 1 |
#include <string.h> |
| 2 |
#include "crypto_sign.h" |
| 3 |
#include "crypto_hash_sha512.h" |
| 4 |
#include "ge25519.h" |
| 5 |
|
| 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 |
| 10 |
) |
| 11 |
{ |
| 12 |
unsigned char pk[32]; |
| 13 |
unsigned char az[64]; |
| 14 |
unsigned char nonce[64]; |
| 15 |
unsigned char hram[64]; |
| 16 |
sc25519 sck, scs, scsk; |
| 17 |
ge25519 ger; |
| 18 |
|
| 19 |
memmove(pk,sk + 32,32); |
| 20 |
|
| 21 |
|
| 22 |
crypto_hash_sha512(az,sk,32); |
| 23 |
az[0] &= 248; |
| 24 |
az[31] &= 127; |
| 25 |
az[31] |= 64; |
| 26 |
|
| 27 |
|
| 28 |
*smlen = mlen + 64; |
| 29 |
memmove(sm + 64,m,mlen); |
| 30 |
memmove(sm + 32,az + 32,32); |
| 31 |
|
| 32 |
|
| 33 |
crypto_hash_sha512(nonce, sm+32, mlen+32); |
| 34 |
|
| 35 |
|
| 36 |
sc25519_from64bytes(&sck, nonce); |
| 37 |
ge25519_scalarmult_base(&ger, &sck); |
| 38 |
ge25519_pack(sm, &ger); |
| 39 |
|
| 40 |
|
| 41 |
memmove(sm + 32,pk,32); |
| 42 |
|
| 43 |
|
| 44 |
crypto_hash_sha512(hram,sm,mlen + 64); |
| 45 |
|
| 46 |
|
| 47 |
sc25519_from64bytes(&scs, hram); |
| 48 |
sc25519_from32bytes(&scsk, az); |
| 49 |
sc25519_mul(&scs, &scs, &scsk); |
| 50 |
sc25519_add(&scs, &scs, &sck); |
| 51 |
|
| 52 |
|
| 53 |
sc25519_to32bytes(sm + 32,&scs); |
| 54 |
|
| 55 |
|
| 56 |
return 0; |
| 57 |
} |