1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 *
4 * LibTomCrypt is a library that provides various cryptographic
5 * algorithms in a highly modular and flexible manner.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10 #include "tomcrypt_private.h"
11
12 /**
13 @file ed25519_verify.c
14 Verify an Ed25519 signature, Steffen Jaeckel
15 */
16
17 #ifdef LTC_CURVE25519
18
19 /**
20 Verify an Ed25519 signature.
21 @param private_key The private Ed25519 key in the pair
22 @param public_key The public Ed25519 key in the pair
23 @param out [out] The destination of the shared data
24 @param outlen [in/out] The max size and resulting size of the shared data.
25 @param stat [out] The result of the signature verification, 1==valid, 0==invalid
26 @return CRYPT_OK if successful
27 */
ed25519_verify(const unsigned char * msg,unsigned long msglen,const unsigned char * sig,unsigned long siglen,int * stat,const curve25519_key * public_key)28 int ed25519_verify(const unsigned char *msg, unsigned long msglen,
29 const unsigned char *sig, unsigned long siglen,
30 int *stat, const curve25519_key *public_key)
31 {
32 unsigned char* m;
33 unsigned long long mlen;
34 int err;
35
36 LTC_ARGCHK(msg != NULL);
37 LTC_ARGCHK(sig != NULL);
38 LTC_ARGCHK(stat != NULL);
39 LTC_ARGCHK(public_key != NULL);
40
41 *stat = 0;
42
43 if (siglen != 64uL) return CRYPT_INVALID_ARG;
44 if (public_key->algo != PKA_ED25519) return CRYPT_PK_INVALID_TYPE;
45
46 mlen = msglen + siglen;
47 if ((mlen < msglen) || (mlen < siglen)) return CRYPT_OVERFLOW;
48
49 m = XMALLOC(mlen);
50 if (m == NULL) return CRYPT_MEM;
51
52 XMEMCPY(m, sig, siglen);
53 XMEMCPY(m + siglen, msg, msglen);
54
55 err = tweetnacl_crypto_sign_open(stat,
56 m, &mlen,
57 m, mlen,
58 public_key->pub);
59
60 #ifdef LTC_CLEAN_STACK
61 zeromem(m, mlen);
62 #endif
63 XFREE(m);
64
65 return err;
66 }
67
68 #endif
69
70 /* ref: $Format:%D$ */
71 /* git commit: $Format:%H$ */
72 /* commit time: $Format:%ai$ */
73