/** * \file psa/crypto_struct.h * * \brief PSA cryptography module: Mbed TLS structured type implementations */ /* * Copyright (C) 2018, ARM Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This file is part of mbed TLS (https://tls.mbed.org) */ #ifndef PSA_CRYPTO_STRUCT_H #define PSA_CRYPTO_STRUCT_H /* Include the Mbed TLS configuration file, the way Mbed TLS does it * in each of its header files. */ #if !defined(MBEDTLS_CONFIG_FILE) #include "../mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #include "mbedtls/cipher.h" #include "mbedtls/cmac.h" #include "mbedtls/gcm.h" #include "mbedtls/md.h" #include "mbedtls/md2.h" #include "mbedtls/md4.h" #include "mbedtls/md5.h" #include "mbedtls/ripemd160.h" #include "mbedtls/sha1.h" #include "mbedtls/sha256.h" #include "mbedtls/sha512.h" #if defined(MBEDTLS_SHA512_C) #define PSA_HASH_MAX_SIZE 64 #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128 #else #define PSA_HASH_MAX_SIZE 32 #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64 #endif struct psa_hash_operation_s { psa_algorithm_t alg; union { unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ #if defined(MBEDTLS_MD2_C) mbedtls_md2_context md2; #endif #if defined(MBEDTLS_MD4_C) mbedtls_md4_context md4; #endif #if defined(MBEDTLS_MD5_C) mbedtls_md5_context md5; #endif #if defined(MBEDTLS_RIPEMD160_C) mbedtls_ripemd160_context ripemd160; #endif #if defined(MBEDTLS_SHA1_C) mbedtls_sha1_context sha1; #endif #if defined(MBEDTLS_SHA256_C) mbedtls_sha256_context sha256; #endif #if defined(MBEDTLS_SHA512_C) mbedtls_sha512_context sha512; #endif } ctx; }; typedef struct { /** The hash context. */ struct psa_hash_operation_s hash_ctx; /** The HMAC part of the context. */ uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE]; } psa_hmac_internal_data; struct psa_mac_operation_s { psa_algorithm_t alg; int key_set : 1; int iv_required : 1; int iv_set : 1; int has_input : 1; int key_usage_sign : 1; int key_usage_verify : 1; uint8_t mac_size; union { unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ #if defined(MBEDTLS_MD_C) psa_hmac_internal_data hmac; #endif #if defined(MBEDTLS_CMAC_C) mbedtls_cipher_context_t cmac; #endif } ctx; }; struct psa_cipher_operation_s { psa_algorithm_t alg; int key_set : 1; int iv_required : 1; int iv_set : 1; uint8_t iv_size; uint8_t block_size; union { mbedtls_cipher_context_t cipher; } ctx; }; struct psa_key_policy_s { psa_key_usage_t usage; psa_algorithm_t alg; }; #endif /* PSA_CRYPTO_STRUCT_H */