Embedded SDK
Embedded SDK
cx_aes_gcm.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 
19 #ifndef CX_AES_GCM_H
20 #define CX_AES_GCM_H
21 
22 #if defined(HAVE_AEAD)
23 #include "lcx_aead.h"
24 #endif // HAVE_AEAD
25 #include <stddef.h>
26 
27 // Store unaligned 32-bit integer (big-endian encoding)
28 #define STORE32BE(a, p) \
29  ((uint8_t *) (p))[0] = ((uint32_t) (a) >> 24) & 0xFFU, \
30  ((uint8_t *) (p))[1] = ((uint32_t) (a) >> 16) & 0xFFU, \
31  ((uint8_t *) (p))[2] = ((uint32_t) (a) >> 8) & 0xFFU, \
32  ((uint8_t *) (p))[3] = ((uint32_t) (a) >> 0) & 0xFFU
33 
34 // Store unaligned 64-bit integer (big-endian encoding)
35 #define STORE64BE(a, p) \
36  ((uint8_t *) (p))[0] = ((uint64_t) (a) >> 56) & 0xFFU, \
37  ((uint8_t *) (p))[1] = ((uint64_t) (a) >> 48) & 0xFFU, \
38  ((uint8_t *) (p))[2] = ((uint64_t) (a) >> 40) & 0xFFU, \
39  ((uint8_t *) (p))[3] = ((uint64_t) (a) >> 32) & 0xFFU, \
40  ((uint8_t *) (p))[4] = ((uint64_t) (a) >> 24) & 0xFFU, \
41  ((uint8_t *) (p))[5] = ((uint64_t) (a) >> 16) & 0xFFU, \
42  ((uint8_t *) (p))[6] = ((uint64_t) (a) >> 8) & 0xFFU, \
43  ((uint8_t *) (p))[7] = ((uint64_t) (a) >> 0) & 0xFFU
44 
45 #if defined(HAVE_AEAD)
46 extern const cx_aead_info_t cx_aes128_gcm_info;
47 extern const cx_aead_info_t cx_aes192_gcm_info;
48 extern const cx_aead_info_t cx_aes256_gcm_info;
49 #endif // HAVE_AEAD
50 
51 #endif // CX_AES_GCM_H
Authenticated Encryption with Associated Data (AEAD)