Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
cx_pbkdf2.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_PBKDF2_H
20#define CX_PBKDF2_H
21
22#ifdef HAVE_PBKDF2
23
24#include "lcx_hmac.h"
25
26#include <stddef.h>
27#include <stdint.h>
28
29#define PBKDF2_BUFFER_LENGTH 64
30
31/* ========= PBKDF2 ========= */
32struct cx_pbkdf2_s {
33 // salt buffer used to initialize each pbkdf2 turn.
34 uint8_t salt[384];
35 uint8_t sha512out[64]; // avoid stack usage in derive_and_set_seed
36
37 uint8_t work[PBKDF2_BUFFER_LENGTH];
38 uint8_t md1[PBKDF2_BUFFER_LENGTH];
39 union {
40#if !defined(HAVE_SHA512) && !defined(HAVE_SHA384) && !defined(HAVE_SHA256) && !defined(HAVE_SHA224)
41#error No hmac defined for pbkdf2 support
42#endif
43
44 cx_hmac_t hmac_ctx;
45
46#if defined(HAVE_HMAC) && (defined(HAVE_SHA512) || defined(HAVE_SHA384))
47 cx_hmac_sha512_t hmac_sha512;
48#endif
49
50#if defined(HAVE_HMAC) && (defined(HAVE_SHA256) || defined(HAVE_SHA224))
51 cx_hmac_sha256_t hmac_sha256;
52#endif
53 };
54};
55typedef struct cx_pbkdf2_s cx_pbkdf2_t;
56
57WARN_UNUSED_RESULT cx_err_t cx_pbkdf2_hmac(cx_md_t md_type,
58 const uint8_t *password,
59 size_t password_len,
60 const uint8_t *salt,
61 size_t salt_len,
62 uint32_t iterations,
63 uint8_t *key,
64 size_t key_len);
65
66#endif // HAVE_PBKDF2
67
68#endif // CX_PBKDF2_H
HMAC (Keyed-Hash Message Authentication Code)
unsigned char uint8_t
Definition usbd_conf.h:53