This commit is contained in:
Frank Denis 2014-07-10 22:04:01 -07:00
parent f7c79dbea7
commit 5b4a3b5715

View File

@ -7,11 +7,10 @@
#include "ge.h"
#include "sc.h"
int crypto_sign_open(
unsigned char *m,unsigned long long *mlen,
const unsigned char *sm,unsigned long long smlen,
const unsigned char *pk
)
int
crypto_sign_open(unsigned char *m, unsigned long long *mlen,
const unsigned char *sm, unsigned long long smlen,
const unsigned char *pk)
{
crypto_hash_sha512_state hs;
unsigned char h[64];
@ -21,13 +20,21 @@ int crypto_sign_open(
ge_p3 A;
ge_p2 R;
if (smlen < 64) goto badsig;
if (sm[63] & 224) goto badsig;
if (ge_frombytes_negate_vartime(&A,pk) != 0) goto badsig;
for (i = 0; i < 32; ++i) d |= pk[i];
if (d == 0) return -1;
if (smlen < 64) {
goto badsig;
}
if (sm[63] & 224) {
goto badsig;
}
if (ge_frombytes_negate_vartime(&A, pk) != 0) {
goto badsig;
}
for (i = 0; i < 32; ++i) {
d |= pk[i];
}
if (d == 0) {
return -1;
}
crypto_hash_sha512_init(&hs);
crypto_hash_sha512_update(&hs, sm, 32);
crypto_hash_sha512_update(&hs, pk, 32);
@ -35,10 +42,10 @@ int crypto_sign_open(
crypto_hash_sha512_final(&hs, h);
sc_reduce(h);
ge_double_scalarmult_vartime(&R,h,&A,sm+32);
ge_tobytes(rcheck,&R);
if (crypto_verify_32(rcheck,sm) == 0) {
memmove(m, sm + 64,smlen - 64);
ge_double_scalarmult_vartime(&R, h, &A, sm + 32);
ge_tobytes(rcheck, &R);
if (crypto_verify_32(rcheck, sm) == 0) {
memmove(m, sm + 64, smlen - 64);
*mlen = smlen - 64;
return 0;
}
@ -46,5 +53,6 @@ int crypto_sign_open(
badsig:
*mlen = 0;
memset(m, 0, smlen - 64);
return -1;
}