]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/implementations/ciphers/cipher_sm4_gcm_hw.c
providers: Add SM4 GCM implementation
[thirdparty/openssl.git] / providers / implementations / ciphers / cipher_sm4_gcm_hw.c
CommitLineData
c2ee608a
TZ
1/*
2 * Copyright 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 * Generic support for SM4 GCM.
12 */
13
14#include "cipher_sm4_gcm.h"
15
16static int sm4_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
17 size_t keylen)
18{
19 PROV_SM4_GCM_CTX *actx = (PROV_SM4_GCM_CTX *)ctx;
20 SM4_KEY *ks = &actx->ks.ks;
21
22 ctx->ks = ks;
23 ossl_sm4_set_key(key, ks);
24 CRYPTO_gcm128_init(&ctx->gcm, ks, (block128_f)ossl_sm4_encrypt);
25 ctx->ctr = (ctr128_f)NULL;
26 ctx->key_set = 1;
27
28 return 1;
29}
30
31static const PROV_GCM_HW sm4_gcm = {
32 sm4_gcm_initkey,
33 ossl_gcm_setiv,
34 ossl_gcm_aad_update,
35 ossl_gcm_cipher_update,
36 ossl_gcm_cipher_final,
37 ossl_gcm_one_shot
38};
39
40const PROV_GCM_HW *ossl_prov_sm4_hw_gcm(size_t keybits)
41{
42 return &sm4_gcm;
43}