Embedded SDK
Embedded SDK
lcx_aes.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 
31 #ifndef LCX_AES_H
32 #define LCX_AES_H
33 
34 #ifdef HAVE_AES
35 
36 #include "cx_errors.h"
37 #include "lcx_wrappers.h"
38 #include "lcx_common.h"
39 #include "ox_aes.h"
40 
57 WARN_UNUSED_RESULT cx_err_t cx_aes_init_key_no_throw(const uint8_t *rawkey,
58  size_t key_len,
59  cx_aes_key_t *key);
60 
65 DEPRECATED static inline size_t cx_aes_init_key(const unsigned char *rawkey,
66  unsigned int key_len,
67  cx_aes_key_t *key)
68 {
69  CX_THROW(cx_aes_init_key_no_throw(rawkey, key_len, key));
70  return key_len;
71 }
72 
117 WARN_UNUSED_RESULT cx_err_t cx_aes_iv_no_throw(const cx_aes_key_t *key,
118  uint32_t mode,
119  const uint8_t *iv,
120  size_t iv_len,
121  const uint8_t *in,
122  size_t in_len,
123  uint8_t *out,
124  size_t *out_len);
125 
130 DEPRECATED static inline size_t cx_aes_iv(const cx_aes_key_t *key,
131  uint32_t mode,
132  unsigned char *iv,
133  unsigned int iv_len,
134  const unsigned char *in,
135  unsigned int in_len,
136  unsigned char *out,
137  unsigned int out_len)
138 {
139  size_t out_len_ = out_len;
140  CX_THROW(cx_aes_iv_no_throw(key, mode, iv, iv_len, in, in_len, out, &out_len_));
141  return out_len_;
142 }
143 
184 WARN_UNUSED_RESULT cx_err_t cx_aes_no_throw(const cx_aes_key_t *key,
185  uint32_t mode,
186  const uint8_t *in,
187  size_t in_len,
188  uint8_t *out,
189  size_t *out_len);
190 
195 DEPRECATED static inline size_t cx_aes(const cx_aes_key_t *key,
196  uint32_t mode,
197  const unsigned char *in,
198  unsigned int in_len,
199  unsigned char *out,
200  unsigned int out_len)
201 {
202  size_t out_len_ = out_len;
203  CX_THROW(cx_aes_no_throw(key, mode, in, in_len, out, &out_len_));
204  return out_len_;
205 }
206 
221 WARN_UNUSED_RESULT cx_err_t cx_aes_enc_block(const cx_aes_key_t *key,
222  const uint8_t *inblock,
223  uint8_t *outblock);
224 
239 WARN_UNUSED_RESULT cx_err_t cx_aes_dec_block(const cx_aes_key_t *key,
240  const uint8_t *inblock,
241  uint8_t *outblock);
242 
243 #endif // HAVE_AES
244 
245 #endif // LCX_AES_H
Cryptography flags.
#define CX_THROW(call)
Definition: lcx_wrappers.h:15
unsigned char uint8_t
Definition: usbd_conf.h:53