Embedded SDK
Embedded SDK
lcx_eddsa.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Ledger Nano S - Secure firmware
4  * (c) 2022 Ledger
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  ********************************************************************************/
18 
28 #ifndef LCX_EDDSA_H
29 #define LCX_EDDSA_H
30 
31 #include "lcx_ecfp.h"
32 #include "lcx_wrappers.h"
33 
34 #ifdef HAVE_EDDSA
35 
74 WARN_UNUSED_RESULT cx_err_t cx_eddsa_sign_no_throw(const cx_ecfp_private_key_t *pvkey,
75  cx_md_t hashID,
76  const uint8_t *hash,
77  size_t hash_len,
78  uint8_t *sig,
79  size_t sig_len);
80 
85 DEPRECATED static inline size_t cx_eddsa_sign(const cx_ecfp_private_key_t *pvkey,
86  int mode,
87  cx_md_t hashID,
88  const unsigned char *hash,
89  unsigned int hash_len,
90  const unsigned char *ctx,
91  unsigned int ctx_len,
92  unsigned char *sig,
93  unsigned int sig_len,
94  unsigned int *info)
95 {
96  UNUSED(ctx);
97  UNUSED(ctx_len);
98  UNUSED(mode);
99  UNUSED(info);
100 
101  CX_THROW(cx_eddsa_sign_no_throw(pvkey, hashID, hash, hash_len, sig, sig_len));
102 
103  size_t size;
104  CX_THROW(cx_ecdomain_parameters_length(pvkey->curve, &size));
105 
106  return 2 * size;
107 }
108 
134 WARN_UNUSED_RESULT bool cx_eddsa_verify_no_throw(const cx_ecfp_public_key_t *pukey,
135  cx_md_t hashID,
136  const uint8_t *hash,
137  size_t hash_len,
138  const uint8_t *sig,
139  size_t sig_len);
140 
174 static inline int cx_eddsa_verify(const cx_ecfp_public_key_t *pukey,
175  int mode,
176  cx_md_t hashID,
177  const unsigned char *hash,
178  unsigned int hash_len,
179  const unsigned char *ctx,
180  unsigned int ctx_len,
181  const unsigned char *sig,
182  unsigned int sig_len)
183 {
184  UNUSED(mode);
185  UNUSED(ctx);
186  UNUSED(ctx_len);
187 
188  return cx_eddsa_verify_no_throw(pukey, hashID, hash, hash_len, sig, sig_len);
189 }
190 
201 void cx_encode_coord(uint8_t *coord, int len, int sign);
202 
212 int cx_decode_coord(uint8_t *coord, int len);
213 
227 cx_err_t cx_eddsa_sign_init_first_hash(cx_hash_t *hash_context,
228  const cx_ecfp_private_key_t *private_key,
229  cx_md_t hash_id);
230 
249 cx_err_t cx_eddsa_sign_init_second_hash(cx_hash_t *hash_context,
250  const cx_ecfp_private_key_t *private_key,
251  cx_md_t hash_id,
252  uint8_t *hash,
253  size_t hash_len,
254  uint8_t *sig,
255  size_t sig_len);
256 
268 cx_err_t cx_eddsa_sign_hash(const cx_ecfp_private_key_t *pv_key,
269  cx_md_t hash_id,
270  const uint8_t *hash,
271  size_t hash_len,
272  uint8_t *sig,
273  size_t sig_len);
274 
289 cx_err_t cx_eddsa_verify_init_hash(cx_hash_t *hash_context,
290  const cx_ecfp_public_key_t *public_key,
291  cx_md_t hash_id,
292  const uint8_t *sig_r,
293  size_t sig_r_len);
294 
310 cx_err_t cx_eddsa_update_hash(cx_hash_t *hash_context, const uint8_t *msg, size_t msg_len);
311 
323 cx_err_t cx_eddsa_final_hash(cx_hash_t *hash_context, uint8_t *hash, size_t hash_len);
324 
337 bool cx_eddsa_verify_hash(const cx_ecfp_public_key_t *public_key,
338  uint8_t *hash,
339  size_t hash_len,
340  const uint8_t *signature,
341  size_t signature_len);
342 
343 #endif // HAVE_EDDSA
344 
345 #endif // LCX_EDDSA_H
Key pair generation based on elliptic curves.
#define CX_THROW(call)
Definition: lcx_wrappers.h:15
unsigned char uint8_t
Definition: usbd_conf.h:53