]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/implementations/ciphers/cipher_sm4_hw.c
Update copyright year
[thirdparty/openssl.git] / providers / implementations / ciphers / cipher_sm4_hw.c
CommitLineData
105dde25 1/*
3c2bdd7d 2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
105dde25
SL
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#include "cipher_sm4.h"
11
12static int cipher_hw_sm4_initkey(PROV_CIPHER_CTX *ctx,
13 const unsigned char *key, size_t keylen)
14{
15 PROV_SM4_CTX *sctx = (PROV_SM4_CTX *)ctx;
16 SM4_KEY *ks = &sctx->ks.ks;
17
8a6e9125 18 ossl_sm4_set_key(key, ks);
105dde25
SL
19 ctx->ks = ks;
20 if (ctx->enc
21 || (ctx->mode != EVP_CIPH_ECB_MODE
22 && ctx->mode != EVP_CIPH_CBC_MODE))
8a6e9125 23 ctx->block = (block128_f)ossl_sm4_encrypt;
105dde25 24 else
8a6e9125 25 ctx->block = (block128_f)ossl_sm4_decrypt;
105dde25
SL
26 return 1;
27}
28
f75abcc0
SL
29IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_sm4_copyctx, PROV_SM4_CTX)
30
105dde25
SL
31# define PROV_CIPHER_HW_sm4_mode(mode) \
32static const PROV_CIPHER_HW sm4_##mode = { \
33 cipher_hw_sm4_initkey, \
592dcfd3 34 ossl_cipher_hw_chunked_##mode, \
f75abcc0 35 cipher_hw_sm4_copyctx \
105dde25 36}; \
7d6766cb 37const PROV_CIPHER_HW *ossl_prov_cipher_hw_sm4_##mode(size_t keybits) \
105dde25
SL
38{ \
39 return &sm4_##mode; \
40}
41
42PROV_CIPHER_HW_sm4_mode(cbc)
43PROV_CIPHER_HW_sm4_mode(ecb)
44PROV_CIPHER_HW_sm4_mode(ofb128)
45PROV_CIPHER_HW_sm4_mode(cfb128)
46PROV_CIPHER_HW_sm4_mode(ctr)