sm4_generic.c (c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2) sm4_generic.c (674f368a952c48ede71784935a799a5205b92b6c)
1// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * SM4 Cipher Algorithm.
5 *
6 * Copyright (C) 2018 ARM Limited or its affiliates.
7 * All rights reserved.
8 */

--- 129 unchanged lines hidden (view full) ---

138 for (i = 0; i < 32; ++i)
139 ctx->rkey_dec[i] = ctx->rkey_enc[31 - i];
140
141 return 0;
142}
143EXPORT_SYMBOL_GPL(crypto_sm4_expand_key);
144
145/**
1// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * SM4 Cipher Algorithm.
5 *
6 * Copyright (C) 2018 ARM Limited or its affiliates.
7 * All rights reserved.
8 */

--- 129 unchanged lines hidden (view full) ---

138 for (i = 0; i < 32; ++i)
139 ctx->rkey_dec[i] = ctx->rkey_enc[31 - i];
140
141 return 0;
142}
143EXPORT_SYMBOL_GPL(crypto_sm4_expand_key);
144
145/**
146 * crypto_sm4_set_key - Set the AES key.
146 * crypto_sm4_set_key - Set the SM4 key.
147 * @tfm: The %crypto_tfm that is used in the context.
148 * @in_key: The input key.
149 * @key_len: The size of the key.
150 *
147 * @tfm: The %crypto_tfm that is used in the context.
148 * @in_key: The input key.
149 * @key_len: The size of the key.
150 *
151 * Returns 0 on success, on failure the %CRYPTO_TFM_RES_BAD_KEY_LEN flag in tfm
152 * is set. The function uses crypto_sm4_expand_key() to expand the key.
151 * This function uses crypto_sm4_expand_key() to expand the key.
153 * &crypto_sm4_ctx _must_ be the private data embedded in @tfm which is
154 * retrieved with crypto_tfm_ctx().
152 * &crypto_sm4_ctx _must_ be the private data embedded in @tfm which is
153 * retrieved with crypto_tfm_ctx().
154 *
155 * Return: 0 on success; -EINVAL on failure (only happens for bad key lengths)
155 */
156int crypto_sm4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
157 unsigned int key_len)
158{
159 struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm);
156 */
157int crypto_sm4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
158 unsigned int key_len)
159{
160 struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm);
160 u32 *flags = &tfm->crt_flags;
161 int ret;
162
161
163 ret = crypto_sm4_expand_key(ctx, in_key, key_len);
164 if (!ret)
165 return 0;
166
167 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
168 return -EINVAL;
162 return crypto_sm4_expand_key(ctx, in_key, key_len);
169}
170EXPORT_SYMBOL_GPL(crypto_sm4_set_key);
171
172static void sm4_do_crypt(const u32 *rk, u32 *out, const u32 *in)
173{
174 u32 x[4], i, t;
175
176 for (i = 0; i < 4; ++i)

--- 70 unchanged lines hidden ---
163}
164EXPORT_SYMBOL_GPL(crypto_sm4_set_key);
165
166static void sm4_do_crypt(const u32 *rk, u32 *out, const u32 *in)
167{
168 u32 x[4], i, t;
169
170 for (i = 0; i < 4; ++i)

--- 70 unchanged lines hidden ---