-
Notifications
You must be signed in to change notification settings - Fork 493
Expand file tree
/
Copy pathed448_verify.c
More file actions
156 lines (129 loc) · 5.53 KB
/
Copy pathed448_verify.c
File metadata and controls
156 lines (129 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file ed448_verify.c
Verify an Ed448 signature, Steffen Jaeckel
*/
#ifdef LTC_CURVE448
static int s_ed448_verify(const unsigned char *msg, unsigned long msglen,
const unsigned char *sig, unsigned long siglen,
const unsigned char *ctx, unsigned long ctxlen,
int *stat,
const curve448_key *public_key)
{
unsigned char *m;
unsigned long long mlen;
int err;
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;
LTC_ARGCHK(msg != NULL);
LTC_ARGCHK(sig != NULL);
LTC_ARGCHK(public_key != NULL);
if (siglen != 114uL) return CRYPT_INVALID_ARG;
if (public_key->pka != LTC_PKA_ED448) return CRYPT_PK_INVALID_TYPE;
mlen = msglen + siglen;
if ((mlen < msglen) || (mlen < siglen)) return CRYPT_OVERFLOW;
m = XMALLOC((unsigned long)mlen);
if (m == NULL) return CRYPT_MEM;
XMEMCPY(m, sig, siglen);
XMEMCPY(m + siglen, msg, msglen);
err = ec448_verify_internal(stat,
m, &mlen,
m, mlen,
ctx, ctxlen,
public_key->pub);
#ifdef LTC_CLEAN_STACK
zeromem(m, msglen + siglen);
#endif
XFREE(m);
return err;
}
/**
Verify an Ed448ctx signature.
@param msg [in] The data to be verified
@param msglen [in] The size of the data to be verified
@param sig [in] The signature to be verified
@param siglen [in] The size of the signature to be verified
@param ctx [in] The context
@param ctxlen [in] The size of the context
@param stat [out] The result of the signature verification, 1==valid, 0==invalid
@param public_key [in] The public Ed448 key in the pair
@return CRYPT_OK if successful
*/
int ed448ctx_verify(const unsigned char *msg, unsigned long msglen,
const unsigned char *sig, unsigned long siglen,
const unsigned char *ctx, unsigned long ctxlen,
int *stat,
const curve448_key *public_key)
{
int err;
unsigned char ctx_prefix[266];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;
LTC_ARGCHK(ctx != NULL);
if ((err = ec448_crypto_ctx(ctx_prefix, &ctx_prefix_size, 0, ctx, ctxlen)) != CRYPT_OK)
return err;
return s_ed448_verify(msg, msglen, sig, siglen, ctx_prefix, ctx_prefix_size, stat, public_key);
}
/**
Verify an Ed448ph signature.
@param msg [in] The data to be verified
@param msglen [in] The size of the data to be verified
@param sig [in] The signature to be verified
@param siglen [in] The size of the signature to be verified
@param ctx [in] The context
@param ctxlen [in] The size of the context
@param stat [out] The result of the signature verification, 1==valid, 0==invalid
@param public_key [in] The public Ed448 key in the pair
@return CRYPT_OK if successful
*/
int ed448ph_verify(const unsigned char *msg, unsigned long msglen,
const unsigned char *sig, unsigned long siglen,
const unsigned char *ctx, unsigned long ctxlen,
int *stat,
const curve448_key *public_key)
{
int err;
unsigned char msg_hash[64];
unsigned char ctx_prefix[266];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;
if ((err = ec448_crypto_ctx(ctx_prefix, &ctx_prefix_size, 1, ctx, ctxlen)) != CRYPT_OK)
return err;
if ((err = ec448_prehash_internal(msg_hash, msg, msglen)) != CRYPT_OK)
return err;
return s_ed448_verify(msg_hash, sizeof(msg_hash), sig, siglen, ctx_prefix, ctx_prefix_size, stat, public_key);
}
/**
Verify an Ed448 signature (pure mode).
@param msg [in] The data to be verified
@param msglen [in] The size of the data to be verified
@param sig [in] The signature to be verified
@param siglen [in] The size of the signature to be verified
@param stat [out] The result of the signature verification, 1==valid, 0==invalid
@param public_key [in] The public Ed448 key in the pair
@return CRYPT_OK if successful
*/
int ed448_verify(const unsigned char *msg, unsigned long msglen,
const unsigned char *sig, unsigned long siglen,
int *stat,
const curve448_key *public_key)
{
int err;
unsigned char ctx_prefix[266];
unsigned long ctx_prefix_size = sizeof(ctx_prefix);
/* stat is cleared before anything else can return, it stays 0 unless the signature is good */
LTC_ARGCHK(stat != NULL);
*stat = 0;
/* Pure Ed448 still uses DOM4 with flag=0 and empty context */
if ((err = ec448_crypto_ctx(ctx_prefix, &ctx_prefix_size, 0, NULL, 0)) != CRYPT_OK)
return err;
return s_ed448_verify(msg, msglen, sig, siglen, ctx_prefix, ctx_prefix_size, stat, public_key);
}
#endif