Embedded SDK
Embedded SDK
lcx_common.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 
26 #ifndef LCX_COMMON_H
27 #define LCX_COMMON_H
28 
29 #include <stdint.h>
30 #include <stddef.h>
31 
32 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
33 #define ARCH_LITTLE_ENDIAN
34 #else
35 #define ARCH_BIG_ENDIAN
36 #endif
37 
38 #if defined(__UINT64_TYPE__) && !defined(NATIVE_64BITS)
39 #define NATIVE_64BITS
40 #endif
41 
42 #ifndef NATIVE_64BITS // NO 64BITS
49 struct uint64_s {
50 #ifdef ARCH_LITTLE_ENDIAN
51  uint32_t l;
52  uint32_t h;
53 #else
54  uint32_t h;
55  uint32_t l;
56 #endif
57 };
58 typedef struct uint64_s uint64bits_t;
59 #else
60 typedef uint64_t uint64bits_t;
61 #endif
62 
66 typedef struct {
67  const uint8_t *iov_base;
68  size_t iov_len;
69 } cx_iovec_t;
70 
71 // clang-format off
109 // clang-format on
110 #define CX_FLAG
111 
115 #define CX_LAST (1 << 0)
116 
120 #define CX_SIG_MODE (1 << 1)
121 
125 #define CX_MASK_SIGCRYPT (3 << 1)
126 #define CX_ENCRYPT (2 << 1)
127 #define CX_DECRYPT (0 << 1)
128 #define CX_SIGN (CX_SIG_MODE | CX_ENCRYPT)
129 #define CX_VERIFY (CX_SIG_MODE | CX_DECRYPT)
130 
134 #define CX_MASK_PAD (7 << 3)
135 #define CX_PAD_NONE (0 << 3)
136 #define CX_PAD_ISO9797M1 (1 << 3)
137 #define CX_PAD_ISO9797M2 (2 << 3)
138 #define CX_PAD_PKCS1_1o5 (3 << 3)
139 #define CX_PAD_PKCS1_PSS (4 << 3)
140 #define CX_PAD_PKCS1_OAEP (5 << 3)
141 
145 #define CX_MASK_CHAIN (7 << 6)
146 #define CX_CHAIN_ECB (0 << 6)
147 #define CX_CHAIN_CBC (1 << 6)
148 #define CX_CHAIN_CTR (2 << 6)
149 #define CX_CHAIN_CFB (3 << 6)
150 #define CX_CHAIN_OFB (4 << 6)
151 
155 #define CX_MASK_ECC_VARIANT (7 << 6)
156 #define CX_NO_CANONICAL (1 << 6)
157 
161 #define CX_MASK_RND (7 << 9)
162 #define CX_RND_PRNG (1 << 9)
163 #define CX_RND_TRNG (2 << 9)
164 #define CX_RND_RFC6979 (3 << 9)
165 #define CX_RND_PROVIDED (4 << 9)
166 
170 #define CX_MASK_EC (7 << 12)
171 #define CX_ECSCHNORR_BIP0340 (0 << 12)
172 #define CX_ECDH_POINT (1 << 12)
173 #define CX_ECDH_X (2 << 12)
174 #define CX_ECSCHNORR_ISO14888_XY (3 << 12)
175 #define CX_ECSCHNORR_ISO14888_X (4 << 12)
176 #define CX_ECSCHNORR_BSI03111 (5 << 12)
177 #define CX_ECSCHNORR_LIBSECP (6 << 12)
178 #define CX_ECSCHNORR_Z (7 << 12)
179 
183 #define CX_NO_REINIT (1 << 15)
184 
185 #endif
struct uint64_s uint64bits_t
Definition: lcx_common.h:58
Similar to libc iovec type.
Definition: lcx_common.h:66
const uint8_t * iov_base
Definition: lcx_common.h:67
size_t iov_len
Definition: lcx_common.h:68
64-bit types, native or by-hands, depending on target and/or compiler support.
Definition: lcx_common.h:49
uint32_t l
32 least significant bits
Definition: lcx_common.h:51
uint32_t h
32 most significant bits
Definition: lcx_common.h:52
unsigned char uint8_t
Definition: usbd_conf.h:53