libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_sign / ed25519 / ref10 / open.c
blob7e30bfc1a4f75a4ddc7c951f41b464c5cb3fc573
1 #include "api.h"
2 #include "crypto_hash_sha512.h"
3 #include "crypto_verify_32.h"
4 #include "ge.h"
5 #include "sc.h"
7 int crypto_sign_open(
8 unsigned char *m,unsigned long long *mlen,
9 const unsigned char *sm,unsigned long long smlen,
10 const unsigned char *pk
13 unsigned char h[64];
14 unsigned char checkr[32];
15 ge_p3 A;
16 ge_p2 R;
17 unsigned long long i;
19 *mlen = -1;
20 if (smlen < 64) return -1;
21 if (sm[63] & 224) return -1;
22 if (ge_frombytes_negate_vartime(&A,pk) != 0) return -1;
24 for (i = 0;i < smlen;++i) m[i] = sm[i];
25 for (i = 0;i < 32;++i) m[32 + i] = pk[i];
26 crypto_hash_sha512(h,m,smlen);
27 sc_reduce(h);
29 ge_double_scalarmult_vartime(&R,h,&A,sm + 32);
30 ge_tobytes(checkr,&R);
31 if (crypto_verify_32(checkr,sm) != 0) {
32 for (i = 0;i < smlen;++i) m[i] = 0;
33 return -1;
36 for (i = 0;i < smlen - 64;++i) m[i] = sm[64 + i];
37 for (i = smlen - 64;i < smlen;++i) m[i] = 0;
38 *mlen = smlen - 64;
39 return 0;