Embedded SDK
Embedded SDK
lcx_ecdh.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_ECDH_H
29 #define LCX_ECDH_H
30 
31 #ifdef HAVE_ECDH
32 
33 #if defined(HAVE_ECDH) || defined(HAVE_X25519) || defined(HAVE_X448)
34 
35 #include "lcx_wrappers.h"
36 #include "lcx_ecfp.h"
37 #include <stddef.h>
38 
39 #if defined(HAVE_ECDH)
75 WARN_UNUSED_RESULT cx_err_t cx_ecdh_no_throw(const cx_ecfp_private_key_t *pvkey,
76  uint32_t mode,
77  const uint8_t *P,
78  size_t P_len,
79  uint8_t *secret,
80  size_t secret_len);
81 
86 DEPRECATED static inline size_t cx_ecdh(const cx_ecfp_private_key_t *pvkey,
87  uint32_t mode,
88  const unsigned char *P,
89  unsigned int P_len,
90  unsigned char *secret,
91  unsigned int secret_len)
92 {
93  CX_THROW(cx_ecdh_no_throw(pvkey, mode, P, P_len, secret, secret_len));
94 
95  size_t size;
96 
97  CX_THROW(cx_ecdomain_parameters_length(pvkey->curve, &size));
98  if ((mode & CX_MASK_EC) == CX_ECDH_POINT) {
99  return 1 + 2 * size;
100  }
101  else {
102  return size;
103  }
104 }
105 
106 #endif // HAVE_ECDH
107 
108 #if defined(HAVE_X25519)
135 WARN_UNUSED_RESULT cx_err_t cx_x25519(uint8_t *u, const uint8_t *k, size_t k_len);
136 #endif // HAVE_X25519
137 
138 #if defined(HAVE_X448)
165 WARN_UNUSED_RESULT cx_err_t cx_x448(uint8_t *u, const uint8_t *k, size_t k_len);
166 #endif // HAVE_X448
167 
168 #endif // HAVE_ECDH || HAVE_X25519 || HAVE_X448
169 
170 #endif // HAVE_ECDH
171 
172 #endif // LCX_ECDH_H
#define CX_ECDH_POINT
Definition: lcx_common.h:172
#define CX_MASK_EC
Definition: lcx_common.h:170
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