1/*
2 * Copyright 2001-2021 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_aes_gcm_hw.c
13 */
14
15static 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    GCM_HW_SET_KEY_CTR_FN(ks, aes_t4_set_encrypt_key, aes_t4_encrypt, ctr);
38    return 1;
39}
40
41static const PROV_GCM_HW t4_aes_gcm = {
42    t4_aes_gcm_initkey,
43    ossl_gcm_setiv,
44    ossl_gcm_aad_update,
45    generic_aes_gcm_cipher_update,
46    ossl_gcm_cipher_final,
47    ossl_gcm_one_shot
48};
49const PROV_GCM_HW *ossl_prov_aes_hw_gcm(size_t keybits)
50{
51    return SPARC_AES_CAPABLE ? &t4_aes_gcm : &aes_gcm;
52}
53