blob: 0dbd86c18be974ed8764acfd9bad11580e98e2e1 [file] [log] [blame]
Gilles Peskine9ef733f2018-02-07 21:05:37 +01001/**
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
Nir Sonnenschein35dfbf42018-06-07 16:20:17 +030048#if defined(MBEDTLS_SHA512_C)
Gilles Peskineb3e6e5d2018-06-18 22:16:43 +020049#define PSA_HASH_MAX_SIZE 64
50#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128
Gilles Peskine2d277862018-06-18 15:41:12 +020051#else
Gilles Peskineb3e6e5d2018-06-18 22:16:43 +020052#define PSA_HASH_MAX_SIZE 32
53#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64
Nir Sonnenschein35dfbf42018-06-07 16:20:17 +030054#endif
55
Gilles Peskine9ef733f2018-02-07 21:05:37 +010056struct psa_hash_operation_s
57{
58 psa_algorithm_t alg;
59 union
60 {
Gilles Peskine058e0b92018-03-22 16:20:19 +010061 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
Gilles Peskine9ef733f2018-02-07 21:05:37 +010062#if defined(MBEDTLS_MD2_C)
63 mbedtls_md2_context md2;
64#endif
65#if defined(MBEDTLS_MD4_C)
66 mbedtls_md4_context md4;
67#endif
68#if defined(MBEDTLS_MD5_C)
69 mbedtls_md5_context md5;
70#endif
71#if defined(MBEDTLS_RIPEMD160_C)
72 mbedtls_ripemd160_context ripemd160;
73#endif
74#if defined(MBEDTLS_SHA1_C)
75 mbedtls_sha1_context sha1;
76#endif
77#if defined(MBEDTLS_SHA256_C)
78 mbedtls_sha256_context sha256;
79#endif
80#if defined(MBEDTLS_SHA512_C)
81 mbedtls_sha512_context sha512;
82#endif
83 } ctx;
84};
85
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +030086
Gilles Peskine2d277862018-06-18 15:41:12 +020087typedef struct
88{
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +030089 /** The hash context. */
90 struct psa_hash_operation_s hash_ctx;
91 /** The HMAC part of the context. */
Gilles Peskineb3e6e5d2018-06-18 22:16:43 +020092 uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +030093} psa_hmac_internal_data;
94
95
Gilles Peskine9ef733f2018-02-07 21:05:37 +010096struct psa_mac_operation_s
97{
98 psa_algorithm_t alg;
99 int key_set : 1;
100 int iv_required : 1;
101 int iv_set : 1;
102 int has_input : 1;
mohammad16036df908f2018-04-02 08:34:15 -0700103 int key_usage_sign : 1;
104 int key_usage_verify : 1;
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100105 uint8_t mac_size;
106 union
107 {
Gilles Peskine058e0b92018-03-22 16:20:19 +0100108 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100109#if defined(MBEDTLS_MD_C)
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +0300110 psa_hmac_internal_data hmac;
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100111#endif
112#if defined(MBEDTLS_CMAC_C)
113 mbedtls_cipher_context_t cmac;
114#endif
115 } ctx;
116};
117
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100118struct psa_cipher_operation_s
119{
120 psa_algorithm_t alg;
121 int key_set : 1;
Moran Pekerad9d82c2018-04-30 12:31:04 +0300122 int iv_required : 1;
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100123 int iv_set : 1;
124 uint8_t iv_size;
125 uint8_t block_size;
126 union
127 {
mohammad1603503973b2018-03-12 15:59:30 +0200128 mbedtls_cipher_context_t cipher;
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100129 } ctx;
130};
131
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100132struct psa_key_policy_s
133{
134 psa_key_usage_t usage;
135 psa_algorithm_t alg;
136};
137
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100138#endif /* PSA_CRYPTO_STRUCT_H */