Loading...
Searching...
No Matches
psa_crypto_operation_encoder.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 HAW Hamburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
24#ifndef PSA_CRYPTO_OPERATION_ENCODER_H
25#define PSA_CRYPTO_OPERATION_ENCODER_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include "psa/crypto.h"
33
37#define PSA_INVALID_OPERATION (0xFF)
38
44typedef enum {
45 PSA_CBC_NO_PAD_AES_128,
46 PSA_CBC_NO_PAD_AES_192,
47 PSA_CBC_NO_PAD_AES_256,
48 PSA_CBC_PKCS7_AES_256,
49 PSA_STREAM_CIPHER_CHACHA20
51
57typedef enum {
58 PSA_ECC_P160_K1,
59 PSA_ECC_P160_R1,
60 PSA_ECC_P160_R2,
61 PSA_ECC_P192_K1,
62 PSA_ECC_P192_R1,
63 PSA_ECC_P224_K1,
64 PSA_ECC_P224_R1,
65 PSA_ECC_P256_K1,
66 PSA_ECC_P256_R1,
67 PSA_ECC_P384_R1,
68 PSA_ECC_P521_R1,
69 PSA_ECC_FRP,
70 PSA_ECC_ED25519,
72
81#define PSA_ENCODE_ECC_KEY_TYPE_SECPR1(bits) \
82 ((bits == 256) || (bits == 520) ? PSA_ECC_P256_R1 : \
83 (bits == 192) || (bits == 392) ? PSA_ECC_P192_R1 : \
84 PSA_INVALID_OPERATION)
85
94#define PSA_ENCODE_ECC_KEY_TYPE_EDWARDS(bits) \
95 ((bits == 255) || (bits == 256) ? PSA_ECC_ED25519 : \
96 PSA_INVALID_OPERATION)
97
107#define PSA_ENCODE_ECC_KEY_TYPE(bits, curve) \
108 ((curve == PSA_ECC_FAMILY_SECP_R1) ? PSA_ENCODE_ECC_KEY_TYPE_SECPR1(bits) : \
109 (curve == PSA_ECC_FAMILY_TWISTED_EDWARDS) ? PSA_ENCODE_ECC_KEY_TYPE_EDWARDS(bits) : \
110 PSA_INVALID_OPERATION)
111
121#define GET_CBC_NO_PADDING_OPERATION(type, bits) \
122 ((type == PSA_KEY_TYPE_AES) ? \
123 ((bits == 128) ? PSA_CBC_NO_PAD_AES_128 : \
124 (bits == 192) ? PSA_CBC_NO_PAD_AES_192 : \
125 (bits == 256) ? PSA_CBC_NO_PAD_AES_256 : \
126 PSA_INVALID_OPERATION) : \
127 PSA_INVALID_OPERATION)
128
138#define GET_CBC_PKCS7_OPERATION(type, bits) \
139 (((alg == PSA_ALG_CBC_PKCS7) && (type == PSA_KEY_TYPE_AES)) ? PSA_CBC_PKCS7_AES_256 : \
140 PSA_INVALID_OPERATION)
141
151#define GET_CFB_OPERATION(type, bits) \
152 (PSA_INVALID_OPERATION)
153
163#define GET_CTR_OPERATION(type, bits) \
164 (PSA_INVALID_OPERATION)
165
175#define GET_ECB_NO_PADDING_OPERATION(type, bits) \
176 (PSA_INVALID_OPERATION)
177
187#define GET_OFB_OPERATION(type, bits) \
188 (PSA_INVALID_OPERATION)
189
199#define GET_STREAM_CIPHER_OPERATION(type, bits) \
200 (((type == PSA_KEY_TYPE_CHACHA20) && (bits == 256)) ? PSA_STREAM_CIPHER_CHACHA20 : \
201 PSA_INVALID_OPERATION)
202
212#define GET_XTS_OPERATION(type, bits) \
213 (PSA_INVALID_OPERATION)
214
225#define PSA_ENCODE_CIPHER_OPERATION(alg, type, bits) \
226 ((alg == PSA_ALG_CBC_NO_PADDING) ? GET_CBC_NO_PADDING_OPERATION(type, bits) : \
227 (alg == PSA_ALG_CBC_PKCS7) ? GET_CBC_PKCS7_OPERATION(type, bits) : \
228 (alg == PSA_ALG_CFB) ? GET_CFB_OPERATION(type, bits) : \
229 (alg == PSA_ALG_CTR) ? GET_CTR_OPERATION(type, bits) : \
230 (alg == PSA_ALG_ECB_NO_PADDING) ? GET_ECB_NO_PADDING_OPERATION(type, bits) : \
231 (alg == PSA_ALG_OFB) ? GET_OFB_OPERATION(type, bits) : \
232 (alg == PSA_ALG_STREAM_CIPHER) ? GET_STREAM_CIPHER_OPERATION(type, bits) : \
233 (alg == PSA_ALG_XTS) ? GET_XTS_OPERATION(type, bits) : \
234 PSA_INVALID_OPERATION)
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif /* PSA_CRYPTO_OPERATION_ENCODER_H */
Function declarations for PSA Crypto.
psa_cipher_op_t
Enum encoding available cipher operations.
psa_asym_key_t
Enum encoding available asymmetric key types and sizes.
PSA key slot management function declarations.