| 1 |
#include <string.h> |
| 2 |
#include "crypto_sign.h" |
| 3 |
#include "crypto_hash_sha512.h" |
| 4 |
#include "crypto_verify_32.h" |
| 5 |
#include "ge.h" |
| 6 |
#include "sc.h" |
| 7 |
#include "crypto_additions.h" |
| 8 |
|
| 9 |
int crypto_sign_open_modified( |
| 10 |
unsigned char *m, |
| 11 |
const unsigned char *sm,unsigned long long smlen, |
| 12 |
const unsigned char *pk |
| 13 |
) |
| 14 |
{ |
| 15 |
unsigned char pkcopy[32]; |
| 16 |
unsigned char rcopy[32]; |
| 17 |
unsigned char scopy[32]; |
| 18 |
unsigned char h[64]; |
| 19 |
unsigned char rcheck[32]; |
| 20 |
ge_p3 A; |
| 21 |
ge_p2 R; |
| 22 |
|
| 23 |
if (smlen < 64) goto badsig; |
| 24 |
if (sm[63] & 224) goto badsig; /* strict parsing of s */ |
| 25 |
if (ge_frombytes_negate_vartime(&A,pk) != 0) goto badsig; |
| 26 |
|
| 27 |
memmove(pkcopy,pk,32); |
| 28 |
memmove(rcopy,sm,32); |
| 29 |
memmove(scopy,sm + 32,32); |
| 30 |
|
| 31 |
memmove(m,sm,smlen); |
| 32 |
memmove(m + 32,pkcopy,32); |
| 33 |
crypto_hash_sha512(h,m,smlen); |
| 34 |
sc_reduce(h); |
| 35 |
|
| 36 |
ge_double_scalarmult_vartime(&R,h,&A,scopy); |
| 37 |
ge_tobytes(rcheck,&R); |
| 38 |
|
| 39 |
if (crypto_verify_32(rcheck,rcopy) == 0) { |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
badsig: |
| 44 |
return -1; |
| 45 |
} |