]>
Commit | Line | Data |
---|---|---|
105dde25 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 | #include "cipher_sm4.h" | |
11 | ||
12 | static 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 | ||
18 | SM4_set_key(key, ks); | |
19 | ctx->ks = ks; | |
20 | if (ctx->enc | |
21 | || (ctx->mode != EVP_CIPH_ECB_MODE | |
22 | && ctx->mode != EVP_CIPH_CBC_MODE)) | |
23 | ctx->block = (block128_f)SM4_encrypt; | |
24 | else | |
25 | ctx->block = (block128_f)SM4_decrypt; | |
26 | return 1; | |
27 | } | |
28 | ||
29 | # define PROV_CIPHER_HW_sm4_mode(mode) \ | |
30 | static const PROV_CIPHER_HW sm4_##mode = { \ | |
31 | cipher_hw_sm4_initkey, \ | |
32 | cipher_hw_chunked_##mode \ | |
33 | }; \ | |
34 | const PROV_CIPHER_HW *PROV_CIPHER_HW_sm4_##mode(size_t keybits) \ | |
35 | { \ | |
36 | return &sm4_##mode; \ | |
37 | } | |
38 | ||
39 | PROV_CIPHER_HW_sm4_mode(cbc) | |
40 | PROV_CIPHER_HW_sm4_mode(ecb) | |
41 | PROV_CIPHER_HW_sm4_mode(ofb128) | |
42 | PROV_CIPHER_HW_sm4_mode(cfb128) | |
43 | PROV_CIPHER_HW_sm4_mode(ctr) |