| Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1 | /** | 
|  | 2 | * \file psa/crypto_struct.h | 
|  | 3 | * | 
|  | 4 | * \brief PSA cryptography module: Mbed TLS structured type implementations | 
|  | 5 | */ | 
|  | 6 | /* | 
|  | 7 | *  Copyright (C) 2018, ARM Limited, All Rights Reserved | 
|  | 8 | *  SPDX-License-Identifier: Apache-2.0 | 
|  | 9 | * | 
|  | 10 | *  Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 11 | *  not use this file except in compliance with the License. | 
|  | 12 | *  You may obtain a copy of the License at | 
|  | 13 | * | 
|  | 14 | *  http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 15 | * | 
|  | 16 | *  Unless required by applicable law or agreed to in writing, software | 
|  | 17 | *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 18 | *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 19 | *  See the License for the specific language governing permissions and | 
|  | 20 | *  limitations under the License. | 
|  | 21 | * | 
|  | 22 | *  This file is part of mbed TLS (https://tls.mbed.org) | 
|  | 23 | */ | 
|  | 24 |  | 
|  | 25 | #ifndef PSA_CRYPTO_STRUCT_H | 
|  | 26 | #define PSA_CRYPTO_STRUCT_H | 
|  | 27 |  | 
|  | 28 | /* Include the Mbed TLS configuration file, the way Mbed TLS does it | 
|  | 29 | * in each of its header files. */ | 
|  | 30 | #if !defined(MBEDTLS_CONFIG_FILE) | 
|  | 31 | #include "../mbedtls/config.h" | 
|  | 32 | #else | 
|  | 33 | #include MBEDTLS_CONFIG_FILE | 
|  | 34 | #endif | 
|  | 35 |  | 
|  | 36 | #include "mbedtls/cipher.h" | 
|  | 37 | #include "mbedtls/cmac.h" | 
|  | 38 | #include "mbedtls/gcm.h" | 
|  | 39 | #include "mbedtls/md.h" | 
|  | 40 | #include "mbedtls/md2.h" | 
|  | 41 | #include "mbedtls/md4.h" | 
|  | 42 | #include "mbedtls/md5.h" | 
|  | 43 | #include "mbedtls/ripemd160.h" | 
|  | 44 | #include "mbedtls/sha1.h" | 
|  | 45 | #include "mbedtls/sha256.h" | 
|  | 46 | #include "mbedtls/sha512.h" | 
|  | 47 |  | 
|  | 48 | struct psa_hash_operation_s | 
|  | 49 | { | 
|  | 50 | psa_algorithm_t alg; | 
|  | 51 | union | 
|  | 52 | { | 
| Gilles Peskine | 058e0b9 | 2018-03-22 16:20:19 +0100 | [diff] [blame] | 53 | unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ | 
| Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 54 | #if defined(MBEDTLS_MD2_C) | 
|  | 55 | mbedtls_md2_context md2; | 
|  | 56 | #endif | 
|  | 57 | #if defined(MBEDTLS_MD4_C) | 
|  | 58 | mbedtls_md4_context md4; | 
|  | 59 | #endif | 
|  | 60 | #if defined(MBEDTLS_MD5_C) | 
|  | 61 | mbedtls_md5_context md5; | 
|  | 62 | #endif | 
|  | 63 | #if defined(MBEDTLS_RIPEMD160_C) | 
|  | 64 | mbedtls_ripemd160_context ripemd160; | 
|  | 65 | #endif | 
|  | 66 | #if defined(MBEDTLS_SHA1_C) | 
|  | 67 | mbedtls_sha1_context sha1; | 
|  | 68 | #endif | 
|  | 69 | #if defined(MBEDTLS_SHA256_C) | 
|  | 70 | mbedtls_sha256_context sha256; | 
|  | 71 | #endif | 
|  | 72 | #if defined(MBEDTLS_SHA512_C) | 
|  | 73 | mbedtls_sha512_context sha512; | 
|  | 74 | #endif | 
|  | 75 | } ctx; | 
|  | 76 | }; | 
|  | 77 |  | 
|  | 78 | struct psa_mac_operation_s | 
|  | 79 | { | 
|  | 80 | psa_algorithm_t alg; | 
|  | 81 | int key_set : 1; | 
|  | 82 | int iv_required : 1; | 
|  | 83 | int iv_set : 1; | 
|  | 84 | int has_input : 1; | 
| mohammad1603 | 6df908f | 2018-04-02 08:34:15 -0700 | [diff] [blame] | 85 | int key_usage_sign : 1; | 
|  | 86 | int key_usage_verify : 1; | 
| Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 87 | uint8_t mac_size; | 
|  | 88 | union | 
|  | 89 | { | 
| Gilles Peskine | 058e0b9 | 2018-03-22 16:20:19 +0100 | [diff] [blame] | 90 | unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ | 
| Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 91 | #if defined(MBEDTLS_MD_C) | 
|  | 92 | mbedtls_md_context_t hmac; | 
|  | 93 | #endif | 
|  | 94 | #if defined(MBEDTLS_CMAC_C) | 
|  | 95 | mbedtls_cipher_context_t cmac; | 
|  | 96 | #endif | 
|  | 97 | } ctx; | 
|  | 98 | }; | 
|  | 99 |  | 
| Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 100 | struct psa_cipher_operation_s | 
|  | 101 | { | 
|  | 102 | psa_algorithm_t alg; | 
|  | 103 | int key_set : 1; | 
|  | 104 | int iv_set : 1; | 
|  | 105 | uint8_t iv_size; | 
|  | 106 | uint8_t block_size; | 
|  | 107 | union | 
|  | 108 | { | 
| Gilles Peskine | 058e0b9 | 2018-03-22 16:20:19 +0100 | [diff] [blame] | 109 | unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ | 
| Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 110 | } ctx; | 
|  | 111 | }; | 
|  | 112 |  | 
| Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 113 | struct psa_key_policy_s | 
|  | 114 | { | 
|  | 115 | psa_key_usage_t usage; | 
|  | 116 | psa_algorithm_t alg; | 
|  | 117 | }; | 
|  | 118 |  | 
| Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 119 | #endif /* PSA_CRYPTO_STRUCT_H */ |