1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
* Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* This file uses the low level AES functions (which are deprecated for
* non-internal use) in order to implement provider AES ciphers.
*/
#include "internal/deprecated.h"
#include "cipher_aes_ocb.h"
#define OCB_SET_KEY_FN(fn_set_enc_key, fn_set_dec_key, \
fn_block_enc, fn_block_dec, \
fn_stream_enc, fn_stream_dec) \
CRYPTO_ocb128_cleanup(&ctx->ocb); \
fn_set_enc_key(key, keylen * 8, &ctx->ksenc.ks); \
fn_set_dec_key(key, keylen * 8, &ctx->ksdec.ks); \
if (!CRYPTO_ocb128_init(&ctx->ocb, &ctx->ksenc.ks, &ctx->ksdec.ks, \
(block128_f)fn_block_enc, (block128_f)fn_block_dec, \
ctx->base.enc ? (ocb128_f)fn_stream_enc : \
(ocb128_f)fn_stream_dec)) \
return 0; \
ctx->key_set = 1
static int cipher_hw_aes_ocb_generic_initkey(PROV_CIPHER_CTX *vctx,
const unsigned char *key,
size_t keylen)
{
PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
/*
* We set both the encrypt and decrypt key here because decrypt
* needs both. (i.e- AAD uses encrypt).
*/
# ifdef HWAES_CAPABLE
if (HWAES_CAPABLE) {
OCB_SET_KEY_FN(HWAES_set_encrypt_key, HWAES_set_decrypt_key,
HWAES_encrypt, HWAES_decrypt,
HWAES_ocb_encrypt, HWAES_ocb_decrypt);
} else
# endif
# ifdef VPAES_CAPABLE
if (VPAES_CAPABLE) {
OCB_SET_KEY_FN(vpaes_set_encrypt_key, vpaes_set_decrypt_key,
vpaes_encrypt, vpaes_decrypt, NULL, NULL);
} else
# endif
{
OCB_SET_KEY_FN(AES_set_encrypt_key, AES_set_decrypt_key,
AES_encrypt, AES_decrypt, NULL, NULL);
}
return 1;
}
# if defined(AESNI_CAPABLE)
static int cipher_hw_aes_ocb_aesni_initkey(PROV_CIPHER_CTX *vctx,
const unsigned char *key,
size_t keylen)
{
PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
OCB_SET_KEY_FN(aesni_set_encrypt_key, aesni_set_decrypt_key,
aesni_encrypt, aesni_decrypt,
aesni_ocb_encrypt, aesni_ocb_decrypt);
return 1;
}
# define PROV_CIPHER_HW_declare() \
static const PROV_CIPHER_HW aesni_ocb = { \
cipher_hw_aes_ocb_aesni_initkey, \
NULL \
};
# define PROV_CIPHER_HW_select() \
if (AESNI_CAPABLE) \
return &aesni_ocb;
#elif defined(SPARC_AES_CAPABLE)
static int cipher_hw_aes_ocb_t4_initkey(PROV_CIPHER_CTX *vctx,
const unsigned char *key,
size_t keylen)
{
PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
OCB_SET_KEY_FN(aes_t4_set_encrypt_key, aes_t4_set_decrypt_key,
aes_t4_encrypt, aes_t4_decrypt, NULL, NULL);
return 1;
}
# define PROV_CIPHER_HW_declare() \
static const PROV_CIPHER_HW aes_t4_ocb = { \
cipher_hw_aes_ocb_t4_initkey, \
NULL \
};
# define PROV_CIPHER_HW_select() \
if (SPARC_AES_CAPABLE) \
return &aes_t4_ocb;
#elif defined(RV64I_ZKND_ZKNE_CAPABLE)
static int cipher_hw_aes_ocb_rv64i_zknd_zkne_initkey(PROV_CIPHER_CTX *vctx,
const unsigned char *key,
size_t keylen)
{
PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
OCB_SET_KEY_FN(rv64i_zkne_set_encrypt_key, rv64i_zknd_set_decrypt_key,
rv64i_zkne_encrypt, rv64i_zknd_decrypt, NULL, NULL);
return 1;
}
# define PROV_CIPHER_HW_declare() \
static const PROV_CIPHER_HW aes_rv64i_zknd_zkne_ocb = { \
cipher_hw_aes_ocb_rv64i_zknd_zkne_initkey, \
NULL \
};
# define PROV_CIPHER_HW_select() \
if (RV64I_ZKND_ZKNE_CAPABLE) \
return &aes_rv64i_zknd_zkne_ocb;
#else
# define PROV_CIPHER_HW_declare()
# define PROV_CIPHER_HW_select()
# endif
static const PROV_CIPHER_HW aes_generic_ocb = {
cipher_hw_aes_ocb_generic_initkey,
NULL
};
PROV_CIPHER_HW_declare()
const PROV_CIPHER_HW *ossl_prov_cipher_hw_aes_ocb(size_t keybits)
{
PROV_CIPHER_HW_select()
return &aes_generic_ocb;
}
|