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#include "lcx_pbkdf2.h"
26
27#include <stddef.h>
28#include <stdint.h>
29
30#define PBKDF2_BUFFER_LENGTH 64
31
32/* ========= PBKDF2 ========= */
33typedef struct cx_pbkdf2_s {
34 // salt buffer used to initialize each pbkdf2 turn.
35 uint8_t salt[384];
36 uint8_t sha512out[64]; // avoid stack usage in derive_and_set_seed
37
38 uint8_t work[PBKDF2_BUFFER_LENGTH];
39 uint8_t md1[PBKDF2_BUFFER_LENGTH];
40 union {
41#if !defined(HAVE_SHA512) && !defined(HAVE_SHA384) && !defined(HAVE_SHA256) && !defined(HAVE_SHA224)
42#error No hmac defined for pbkdf2 support
43#endif
44
45 cx_hmac_t hmac_ctx;
46
47#if defined(HAVE_HMAC) && (defined(HAVE_SHA512) || defined(HAVE_SHA384))
48 cx_hmac_sha512_t hmac_sha512;
49#endif
50
51#if defined(HAVE_HMAC) && (defined(HAVE_SHA256) || defined(HAVE_SHA224))
52 cx_hmac_sha256_t hmac_sha256;
53#endif
54 };
55} cx_pbkdf2_t;
56
57#endif // HAVE_PBKDF2
58
59#endif // CX_PBKDF2_H
HMAC (Keyed-Hash Message Authentication Code)
PBKDF2 (Password-Based Key Derivation Function)