Path: blob/master/thirdparty/mbedtls/include/psa/crypto_builtin_key_derivation.h
9904 views
/*1* Context structure declaration of the Mbed TLS software-based PSA drivers2* called through the PSA Crypto driver dispatch layer.3* This file contains the context structures of key derivation algorithms4* which need to rely on other algorithms.5*6* \note This file may not be included directly. Applications must7* include psa/crypto.h.8*9* \note This header and its content are not part of the Mbed TLS API and10* applications must not depend on it. Its main purpose is to define the11* multi-part state objects of the Mbed TLS software-based PSA drivers. The12* definitions of these objects are then used by crypto_struct.h to define the13* implementation-defined types of PSA multi-part state objects.14*/15/*16* Copyright The Mbed TLS Contributors17* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later18*/1920#ifndef PSA_CRYPTO_BUILTIN_KEY_DERIVATION_H21#define PSA_CRYPTO_BUILTIN_KEY_DERIVATION_H22#include "mbedtls/private_access.h"2324#include <psa/crypto_driver_common.h>2526#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF) || \27defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXTRACT) || \28defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXPAND)29typedef struct {30uint8_t *MBEDTLS_PRIVATE(info);31size_t MBEDTLS_PRIVATE(info_length);32#if PSA_HASH_MAX_SIZE > 0xff33#error "PSA_HASH_MAX_SIZE does not fit in uint8_t"34#endif35uint8_t MBEDTLS_PRIVATE(offset_in_block);36uint8_t MBEDTLS_PRIVATE(block_number);37unsigned int MBEDTLS_PRIVATE(state) : 2;38unsigned int MBEDTLS_PRIVATE(info_set) : 1;39uint8_t MBEDTLS_PRIVATE(output_block)[PSA_HASH_MAX_SIZE];40uint8_t MBEDTLS_PRIVATE(prk)[PSA_HASH_MAX_SIZE];41struct psa_mac_operation_s MBEDTLS_PRIVATE(hmac);42} psa_hkdf_key_derivation_t;43#endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF ||44MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXTRACT ||45MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXPAND */46#if defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_ECJPAKE_TO_PMS)47typedef struct {48uint8_t MBEDTLS_PRIVATE(data)[PSA_TLS12_ECJPAKE_TO_PMS_DATA_SIZE];49} psa_tls12_ecjpake_to_pms_t;50#endif /* MBEDTLS_PSA_BUILTIN_ALG_TLS12_ECJPAKE_TO_PMS */5152#if defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF) || \53defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS)54typedef enum {55PSA_TLS12_PRF_STATE_INIT, /* no input provided */56PSA_TLS12_PRF_STATE_SEED_SET, /* seed has been set */57PSA_TLS12_PRF_STATE_OTHER_KEY_SET, /* other key has been set - optional */58PSA_TLS12_PRF_STATE_KEY_SET, /* key has been set */59PSA_TLS12_PRF_STATE_LABEL_SET, /* label has been set */60PSA_TLS12_PRF_STATE_OUTPUT /* output has been started */61} psa_tls12_prf_key_derivation_state_t;6263typedef struct psa_tls12_prf_key_derivation_s {64#if PSA_HASH_MAX_SIZE > 0xff65#error "PSA_HASH_MAX_SIZE does not fit in uint8_t"66#endif6768/* Indicates how many bytes in the current HMAC block have69* not yet been read by the user. */70uint8_t MBEDTLS_PRIVATE(left_in_block);7172/* The 1-based number of the block. */73uint8_t MBEDTLS_PRIVATE(block_number);7475psa_tls12_prf_key_derivation_state_t MBEDTLS_PRIVATE(state);7677uint8_t *MBEDTLS_PRIVATE(secret);78size_t MBEDTLS_PRIVATE(secret_length);79uint8_t *MBEDTLS_PRIVATE(seed);80size_t MBEDTLS_PRIVATE(seed_length);81uint8_t *MBEDTLS_PRIVATE(label);82size_t MBEDTLS_PRIVATE(label_length);83#if defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS)84uint8_t *MBEDTLS_PRIVATE(other_secret);85size_t MBEDTLS_PRIVATE(other_secret_length);86#endif /* MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS */8788uint8_t MBEDTLS_PRIVATE(Ai)[PSA_HASH_MAX_SIZE];8990/* `HMAC_hash( prk, A( i ) + seed )` in the notation of RFC 5246, Sect. 5. */91uint8_t MBEDTLS_PRIVATE(output_block)[PSA_HASH_MAX_SIZE];92} psa_tls12_prf_key_derivation_t;93#endif /* MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF) ||94* MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS */95#if defined(PSA_HAVE_SOFT_PBKDF2)96typedef enum {97PSA_PBKDF2_STATE_INIT, /* no input provided */98PSA_PBKDF2_STATE_INPUT_COST_SET, /* input cost has been set */99PSA_PBKDF2_STATE_SALT_SET, /* salt has been set */100PSA_PBKDF2_STATE_PASSWORD_SET, /* password has been set */101PSA_PBKDF2_STATE_OUTPUT /* output has been started */102} psa_pbkdf2_key_derivation_state_t;103104typedef struct {105psa_pbkdf2_key_derivation_state_t MBEDTLS_PRIVATE(state);106uint64_t MBEDTLS_PRIVATE(input_cost);107uint8_t *MBEDTLS_PRIVATE(salt);108size_t MBEDTLS_PRIVATE(salt_length);109uint8_t MBEDTLS_PRIVATE(password)[PSA_HMAC_MAX_HASH_BLOCK_SIZE];110size_t MBEDTLS_PRIVATE(password_length);111uint8_t MBEDTLS_PRIVATE(output_block)[PSA_HASH_MAX_SIZE];112uint8_t MBEDTLS_PRIVATE(bytes_used);113uint32_t MBEDTLS_PRIVATE(block_number);114} psa_pbkdf2_key_derivation_t;115#endif /* PSA_HAVE_SOFT_PBKDF2 */116117#endif /* PSA_CRYPTO_BUILTIN_KEY_DERIVATION_H */118119120