Embedded SDK
Embedded SDK
lcx_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 
33 #ifndef LCX_AES_GCM_H
34 #define LCX_AES_GCM_H
35 
36 #if defined(HAVE_AES) && defined(HAVE_AES_GCM)
37 
38 #include "ox.h"
39 #include <stddef.h>
40 
44 typedef struct {
45  cx_aes_key_t key;
46  size_t len;
47  size_t aad_len;
48  uint8_t enc_block[16];
49  uint8_t J0[16];
50  uint8_t processed[16];
51  uint8_t hash_key[16];
52  uint32_t mode;
53  uint8_t flag;
54 } cx_aes_gcm_context_t;
55 
56 void cx_aes_gcm_init(cx_aes_gcm_context_t *ctx);
57 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_set_key(cx_aes_gcm_context_t *ctx,
58  const uint8_t *raw_key,
59  size_t key_len);
60 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_start(cx_aes_gcm_context_t *ctx,
61  uint32_t mode,
62  const uint8_t *iv,
63  size_t iv_len);
64 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_update_aad(cx_aes_gcm_context_t *ctx,
65  const uint8_t *aad,
66  size_t aad_len);
67 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_update(cx_aes_gcm_context_t *ctx,
68  const uint8_t *in,
69  uint8_t *out,
70  size_t len);
71 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_finish(cx_aes_gcm_context_t *ctx,
72  uint8_t *tag,
73  size_t tag_len);
74 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_encrypt_and_tag(cx_aes_gcm_context_t *ctx,
75  uint8_t *in,
76  size_t len,
77  const uint8_t *iv,
78  size_t iv_len,
79  const uint8_t *aad,
80  size_t aad_len,
81  uint8_t *out,
82  uint8_t *tag,
83  size_t tag_len);
84 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_decrypt_and_auth(cx_aes_gcm_context_t *ctx,
85  uint8_t *in,
86  size_t len,
87  const uint8_t *iv,
88  size_t iv_len,
89  const uint8_t *aad,
90  size_t aad_len,
91  uint8_t *out,
92  const uint8_t *tag,
93  size_t tag_len);
94 WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_check_tag(cx_aes_gcm_context_t *ctx,
95  const uint8_t *tag,
96  size_t tag_len);
97 
98 #endif // HAVE_AES && HAVE_AES_GCM
99 
100 #endif // LCX_AES_GCM_H
unsigned char uint8_t
Definition: usbd_conf.h:53