| 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 | |
| 8 | int crypto_sign_open( |
| 9 | unsigned char *sm, unsigned long long smlen, |
| 10 | const unsigned char *pk |
| 11 | ) |
| 12 | { |
| 13 | unsigned char scopy[32]; |
| 14 | unsigned char h[64]; |
| 15 | unsigned char rcheck[32]; |
| 16 | ge_p3 A; |
| 17 | ge_p2 R; |
| 18 | |
| 19 | if (smlen < 64) goto badsig; |
| 20 | if (sm[63] & 224) goto badsig; |
| 21 | if (ge_frombytes_negate_vartime(&A,pk) != 0) goto badsig; |
| 22 | |
| 23 | memmove(scopy,sm + 32,32); |
| 24 | |
| 25 | memmove(sm + 32,pk,32); |
| 26 | crypto_hash_sha512(h,sm,smlen); |
| 27 | sc_reduce(h); |
| 28 | |
| 29 | ge_double_scalarmult_vartime(&R,h,&A,scopy); |
| 30 | ge_tobytes(rcheck,&R); |
| 31 | if (crypto_verify_32(rcheck,sm) == 0) |
| 32 | return 0; |
| 33 | |
| 34 | badsig: |
| 35 | return -1; |
| 36 | } |
| 37 | |