]>
Commit | Line | Data |
---|---|---|
4a42e264 SL |
1 | /* |
2 | * Copyright 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 | /* Dispatch functions for AES GCM mode */ | |
11 | ||
12 | #include "cipher_locl.h" | |
13 | #include "internal/ciphers/cipher_gcm.h" | |
14 | ||
15 | static int generic_aes_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key, | |
16 | size_t keylen) | |
17 | { | |
18 | PROV_AES_GCM_CTX *actx = (PROV_AES_GCM_CTX *)ctx; | |
19 | AES_KEY *ks = &actx->ks.ks; | |
20 | ||
21 | # ifdef HWAES_CAPABLE | |
22 | if (HWAES_CAPABLE) { | |
23 | # ifdef HWAES_ctr32_encrypt_blocks | |
24 | GCM_HW_SET_KEY_CTR_FN(ks, HWAES_set_encrypt_key, HWAES_encrypt, | |
25 | HWAES_ctr32_encrypt_blocks); | |
26 | # else | |
27 | GCM_HW_SET_KEY_CTR_FN(ks, HWAES_set_encrypt_key, HWAES_encrypt, NULL); | |
28 | # endif /* HWAES_ctr32_encrypt_blocks */ | |
29 | } else | |
30 | # endif /* HWAES_CAPABLE */ | |
31 | ||
32 | # ifdef BSAES_CAPABLE | |
33 | if (BSAES_CAPABLE) { | |
34 | GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt, | |
35 | bsaes_ctr32_encrypt_blocks); | |
36 | } else | |
37 | # endif /* BSAES_CAPABLE */ | |
38 | ||
39 | # ifdef VPAES_CAPABLE | |
40 | if (VPAES_CAPABLE) { | |
41 | GCM_HW_SET_KEY_CTR_FN(ks, vpaes_set_encrypt_key, vpaes_encrypt, NULL); | |
42 | } else | |
43 | # endif /* VPAES_CAPABLE */ | |
44 | ||
45 | { | |
46 | # ifdef AES_CTR_ASM | |
47 | GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt, | |
48 | AES_ctr32_encrypt); | |
49 | # else | |
50 | GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt, NULL); | |
51 | # endif /* AES_CTR_ASM */ | |
52 | } | |
53 | ctx->key_set = 1; | |
54 | return 1; | |
55 | } | |
56 | ||
57 | static const PROV_GCM_HW aes_gcm = { | |
58 | generic_aes_gcm_initkey, | |
59 | gcm_setiv, | |
60 | gcm_aad_update, | |
61 | gcm_cipher_update, | |
62 | gcm_cipher_final, | |
63 | gcm_one_shot | |
64 | }; | |
65 | ||
66 | #if defined(S390X_aes_128_CAPABLE) | |
67 | # include "cipher_aes_gcm_hw_s390x.inc" | |
68 | #elif defined(AESNI_CAPABLE) | |
69 | # include "cipher_aes_gcm_hw_aesni.inc" | |
70 | #elif defined(SPARC_AES_CAPABLE) | |
71 | # include "cipher_aes_gcm_hw_t4.inc" | |
72 | #else | |
73 | const PROV_GCM_HW *PROV_AES_HW_gcm(size_t keybits) | |
74 | { | |
75 | return &aes_gcm; | |
76 | } | |
77 | #endif | |
78 |