| 1 |
#include <string.h> |
| 2 |
#include "crypto_sign.h" |
| 3 |
#include "crypto_hash_sha512.h" |
| 4 |
#include "ge.h" |
| 5 |
#include "sc.h" |
| 6 |
#include "zeroize.h" |
| 7 |
#include "crypto_additions.h" |
| 8 |
|
| 9 |
/* NEW: Compare to pristine crypto_sign() |
| 10 |
Uses explicit private key for nonce derivation and as scalar, |
| 11 |
instead of deriving both from a master key. |
| 12 |
*/ |
| 13 |
int crypto_sign_modified( |
| 14 |
unsigned char *sm, |
| 15 |
const unsigned char *m,unsigned long long mlen, |
| 16 |
const unsigned char *sk, const unsigned char* pk, |
| 17 |
const unsigned char* random |
| 18 |
) |
| 19 |
{ |
| 20 |
unsigned char nonce[64]; |
| 21 |
unsigned char hram[64]; |
| 22 |
ge_p3 R; |
| 23 |
int count=0; |
| 24 |
|
| 25 |
memmove(sm + 64,m,mlen); |
| 26 |
memmove(sm + 32,sk,32); /* NEW: Use privkey directly for nonce derivation */ |
| 27 |
|
| 28 |
/* NEW : add prefix to separate hash uses - see .h */ |
| 29 |
sm[0] = 0xFE; |
| 30 |
for (count = 1; count < 32; count++) |
| 31 |
sm[count] = 0xFF; |
| 32 |
|
| 33 |
/* NEW: add suffix of random data */ |
| 34 |
memmove(sm + mlen + 64, random, 64); |
| 35 |
|
| 36 |
crypto_hash_sha512(nonce,sm,mlen + 128); |
| 37 |
memmove(sm + 32,pk,32); |
| 38 |
|
| 39 |
sc_reduce(nonce); |
| 40 |
|
| 41 |
ge_scalarmult_base(&R,nonce); |
| 42 |
ge_p3_tobytes(sm,&R); |
| 43 |
|
| 44 |
crypto_hash_sha512(hram,sm,mlen + 64); |
| 45 |
sc_reduce(hram); |
| 46 |
sc_muladd(sm + 32,hram,sk,nonce); /* NEW: Use privkey directly */ |
| 47 |
|
| 48 |
/* Erase any traces of private scalar or |
| 49 |
nonce left in the stack from sc_muladd */ |
| 50 |
zeroize_stack(); |
| 51 |
zeroize(nonce, 64); |
| 52 |
return 0; |
| 53 |
} |