| 1 |
#include <string.h> |
| 2 |
#include "crypto_sign.h" |
| 3 |
#include "crypto_verify_32.h" |
| 4 |
#include "crypto_hash_sha512.h" |
| 5 |
#include "crypto_mGnP_ed25519.h" |
| 6 |
|
| 7 |
int crypto_sign_open( |
| 8 |
unsigned char *m,long long *mlen, |
| 9 |
const unsigned char *sm,long long smlen, |
| 10 |
const unsigned char *pk |
| 11 |
) |
| 12 |
{ |
| 13 |
unsigned char Acopy[32]; |
| 14 |
unsigned char Rcopy[32]; |
| 15 |
unsigned char Scopy[32]; |
| 16 |
unsigned char hram[64]; |
| 17 |
unsigned char Rcheck[33]; |
| 18 |
|
| 19 |
if (smlen < 64) goto badsig; |
| 20 |
if (sm[63] & 224) goto badsig; |
| 21 |
|
| 22 |
memmove(Acopy,pk,32); |
| 23 |
memmove(Rcopy,sm,32); |
| 24 |
memmove(Scopy,sm+32,32); |
| 25 |
|
| 26 |
memmove(m,sm,smlen); |
| 27 |
memmove(m+32,Acopy,32); |
| 28 |
crypto_hash_sha512(hram,m,smlen); |
| 29 |
crypto_mGnP_ed25519(Rcheck,Scopy,hram,Acopy); |
| 30 |
if (Rcheck[32] != 1) goto badsig; |
| 31 |
|
| 32 |
if (crypto_verify_32(Rcopy,Rcheck) == 0) { |
| 33 |
memmove(m,m+64,smlen-64); |
| 34 |
memset(m+smlen-64,0,64); |
| 35 |
*mlen = smlen-64; |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
badsig: |
| 40 |
*mlen = (unsigned long long) -1; |
| 41 |
memset(m,0,smlen); |
| 42 |
return -1; |
| 43 |
} |