]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/implementations/ciphers/cipher_aes_hw_t4.inc
Update copyright year
[thirdparty/openssl.git] / providers / implementations / ciphers / cipher_aes_hw_t4.inc
CommitLineData
e1178600 1/*
a28d06f3 2 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
e1178600
SL
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10/*-
11 * Sparc t4 support for AES modes ecb, cbc, ofb, cfb, ctr.
12 * This file is included by cipher_aes_hw.c
13 */
14
15static int cipher_hw_aes_t4_initkey(PROV_CIPHER_CTX *dat,
16 const unsigned char *key, size_t keylen)
17{
18 int ret, bits;
19 PROV_AES_CTX *adat = (PROV_AES_CTX *)dat;
8c95977f 20 AES_KEY *ks = &adat->ks.ks;
e1178600 21
8c95977f 22 dat->ks = (const void *)ks; /* used by cipher_hw_generic_XXX */
e1178600
SL
23
24 bits = keylen * 8;
25 if ((dat->mode == EVP_CIPH_ECB_MODE || dat->mode == EVP_CIPH_CBC_MODE)
26 && !dat->enc) {
27 ret = 0;
8c95977f
SL
28 aes_t4_set_decrypt_key(key, bits, ks);
29 dat->block = (block128_f)aes_t4_decrypt;
e1178600
SL
30 switch (bits) {
31 case 128:
32 dat->stream.cbc = dat->mode == EVP_CIPH_CBC_MODE ?
8c95977f 33 (cbc128_f)aes128_t4_cbc_decrypt : NULL;
e1178600
SL
34 break;
35 case 192:
36 dat->stream.cbc = dat->mode == EVP_CIPH_CBC_MODE ?
8c95977f 37 (cbc128_f)aes192_t4_cbc_decrypt : NULL;
e1178600
SL
38 break;
39 case 256:
40 dat->stream.cbc = dat->mode == EVP_CIPH_CBC_MODE ?
8c95977f 41 (cbc128_f)aes256_t4_cbc_decrypt : NULL;
e1178600
SL
42 break;
43 default:
44 ret = -1;
45 }
46 } else {
47 ret = 0;
8c95977f 48 aes_t4_set_encrypt_key(key, bits, ks);
e1178600
SL
49 dat->block = (block128_f)aes_t4_encrypt;
50 switch (bits) {
51 case 128:
52 if (dat->mode == EVP_CIPH_CBC_MODE)
53 dat->stream.cbc = (cbc128_f)aes128_t4_cbc_encrypt;
54 else if (dat->mode == EVP_CIPH_CTR_MODE)
55 dat->stream.ctr = (ctr128_f)aes128_t4_ctr32_encrypt;
56 else
57 dat->stream.cbc = NULL;
58 break;
59 case 192:
60 if (dat->mode == EVP_CIPH_CBC_MODE)
61 dat->stream.cbc = (cbc128_f)aes192_t4_cbc_encrypt;
62 else if (dat->mode == EVP_CIPH_CTR_MODE)
63 dat->stream.ctr = (ctr128_f)aes192_t4_ctr32_encrypt;
64 else
65 dat->stream.cbc = NULL;
66 break;
67 case 256:
68 if (dat->mode == EVP_CIPH_CBC_MODE)
69 dat->stream.cbc = (cbc128_f)aes256_t4_cbc_encrypt;
70 else if (dat->mode == EVP_CIPH_CTR_MODE)
71 dat->stream.ctr = (ctr128_f)aes256_t4_ctr32_encrypt;
72 else
73 dat->stream.cbc = NULL;
74 break;
75 default:
76 ret = -1;
77 }
78 }
79
80 if (ret < 0) {
f5f29796 81 ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED);
e1178600
SL
82 return 0;
83 }
84
85 return 1;
86}
87
88#define PROV_CIPHER_HW_declare(mode) \
89static const PROV_CIPHER_HW aes_t4_##mode = { \
90 cipher_hw_aes_t4_initkey, \
5723a8ec 91 ossl_cipher_hw_generic_##mode, \
f75abcc0 92 cipher_hw_aes_copyctx \
e1178600
SL
93};
94#define PROV_CIPHER_HW_select(mode) \
95 if (SPARC_AES_CAPABLE) \
f8c0218f 96 return &aes_t4_##mode;