0cb3f811e1aba66a0497400df3631f47840a0290
[openssl.git] / providers / common / ciphers / cipher_aes_gcm_hw_t4.inc
1 /*
2  * Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
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  * Fujitsu SPARC64 X support for AES GCM.
12  * This file is included by cipher_gcm_hw.c
13  */
14
15 static int t4_aes_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
16                               size_t keylen)
17 {
18     ctr128_f ctr;
19     PROV_AES_GCM_CTX *actx = (PROV_AES_GCM_CTX *)ctx;
20     AES_KEY *ks = &actx->ks.ks;
21
22
23     switch (keylen) {
24     case 16:
25         ctr = (ctr128_f)aes128_t4_ctr32_encrypt;
26         break;
27     case 24:
28         ctr = (ctr128_f)aes192_t4_ctr32_encrypt;
29         break;
30     case 32:
31         ctr = (ctr128_f)aes256_t4_ctr32_encrypt;
32         break;
33     default:
34         return 0;
35     }
36
37     SET_KEY_CTR_FN(ks, aes_t4_set_encrypt_key, aes_t4_encrypt, ctr);
38     return 1;
39 }
40
41 static const PROV_GCM_HW t4_aes_gcm = {
42     t4_aes_gcm_initkey,
43     gcm_setiv,
44     gcm_aad_update,
45     gcm_cipher_update,
46     gcm_cipher_final,
47     gcm_one_shot
48 };
49 const PROV_GCM_HW *PROV_AES_HW_gcm(size_t keybits)
50 {
51     return SPARC_AES_CAPABLE ? &t4_aes_gcm : &aes_gcm;
52 }