2018-03-06 09:44:42 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common values for the SM4 algorithm
|
|
|
|
* Copyright (C) 2018 ARM Limited or its affiliates.
|
crypto: sm4 - create SM4 library based on sm4 generic code
Take the existing small footprint and mostly time invariant C code
and turn it into a SM4 library that can be used for non-performance
critical, casual use of SM4, and as a fallback for, e.g., SIMD code
that needs a secondary path that can be taken in contexts where the
SIMD unit is off limits.
Secondly, some codes have been optimized, such as unrolling small
times loop, removing unnecessary memory shifts, exporting sbox, fk,
ck arrays, and basic encryption and decryption functions.
Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-07-20 03:46:39 +00:00
|
|
|
* Copyright (c) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
|
2018-03-06 09:44:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CRYPTO_SM4_H
|
|
|
|
#define _CRYPTO_SM4_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/crypto.h>
|
|
|
|
|
|
|
|
#define SM4_KEY_SIZE 16
|
|
|
|
#define SM4_BLOCK_SIZE 16
|
|
|
|
#define SM4_RKEY_WORDS 32
|
|
|
|
|
2021-07-20 03:46:40 +00:00
|
|
|
struct sm4_ctx {
|
2018-03-06 09:44:42 +00:00
|
|
|
u32 rkey_enc[SM4_RKEY_WORDS];
|
|
|
|
u32 rkey_dec[SM4_RKEY_WORDS];
|
|
|
|
};
|
|
|
|
|
2022-03-15 09:44:51 +00:00
|
|
|
extern const u32 crypto_sm4_fk[];
|
|
|
|
extern const u32 crypto_sm4_ck[];
|
|
|
|
extern const u8 crypto_sm4_sbox[];
|
|
|
|
|
crypto: sm4 - create SM4 library based on sm4 generic code
Take the existing small footprint and mostly time invariant C code
and turn it into a SM4 library that can be used for non-performance
critical, casual use of SM4, and as a fallback for, e.g., SIMD code
that needs a secondary path that can be taken in contexts where the
SIMD unit is off limits.
Secondly, some codes have been optimized, such as unrolling small
times loop, removing unnecessary memory shifts, exporting sbox, fk,
ck arrays, and basic encryption and decryption functions.
Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-07-20 03:46:39 +00:00
|
|
|
/**
|
|
|
|
* sm4_expandkey - Expands the SM4 key as described in GB/T 32907-2016
|
|
|
|
* @ctx: The location where the computed key will be stored.
|
|
|
|
* @in_key: The supplied key.
|
|
|
|
* @key_len: The length of the supplied key.
|
|
|
|
*
|
|
|
|
* Returns 0 on success. The function fails only if an invalid key size (or
|
|
|
|
* pointer) is supplied.
|
|
|
|
*/
|
2021-07-20 03:46:40 +00:00
|
|
|
int sm4_expandkey(struct sm4_ctx *ctx, const u8 *in_key,
|
2018-03-06 09:44:42 +00:00
|
|
|
unsigned int key_len);
|
|
|
|
|
crypto: sm4 - create SM4 library based on sm4 generic code
Take the existing small footprint and mostly time invariant C code
and turn it into a SM4 library that can be used for non-performance
critical, casual use of SM4, and as a fallback for, e.g., SIMD code
that needs a secondary path that can be taken in contexts where the
SIMD unit is off limits.
Secondly, some codes have been optimized, such as unrolling small
times loop, removing unnecessary memory shifts, exporting sbox, fk,
ck arrays, and basic encryption and decryption functions.
Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2021-07-20 03:46:39 +00:00
|
|
|
/**
|
|
|
|
* sm4_crypt_block - Encrypt or decrypt a single SM4 block
|
|
|
|
* @rk: The rkey_enc for encrypt or rkey_dec for decrypt
|
|
|
|
* @out: Buffer to store output data
|
|
|
|
* @in: Buffer containing the input data
|
|
|
|
*/
|
|
|
|
void sm4_crypt_block(const u32 *rk, u8 *out, const u8 *in);
|
|
|
|
|
2018-03-06 09:44:42 +00:00
|
|
|
#endif
|