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 | /*- |
11 | * Generic support for ARIA GCM. |
12 | */ |
13 | |
14 | #include "cipher_aria_gcm.h" |
15 | |
16 | static int aria_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key, |
17 | size_t keylen) |
18 | { |
19 | PROV_ARIA_GCM_CTX *actx = (PROV_ARIA_GCM_CTX *)ctx; |
20 | ARIA_KEY *ks = &actx->ks.ks; |
21 | |
22 | GCM_HW_SET_KEY_CTR_FN(ks, aria_set_encrypt_key, aria_encrypt, NULL); |
23 | return 1; |
24 | } |
25 | |
26 | static int aria_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in, |
27 | size_t len, unsigned char *out) |
28 | { |
29 | if (ctx->enc) { |
30 | if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len)) |
31 | return 0; |
32 | } else { |
33 | if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len)) |
34 | return 0; |
35 | } |
36 | return 1; |
37 | } |
38 | |
39 | static const PROV_GCM_HW aria_gcm = { |
40 | aria_gcm_initkey, |
41 | gcm_setiv, |
42 | gcm_aad_update, |
43 | aria_cipher_update, |
44 | gcm_cipher_final, |
45 | gcm_one_shot |
46 | }; |
47 | const PROV_GCM_HW *PROV_ARIA_HW_gcm(size_t keybits) |
48 | { |
49 | return &aria_gcm; |
50 | } |
51 | |