Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: arm64/sm4-ce - Make dependent on sm4 library instead of sm4-generic

SM4 library is abstracted from sm4-generic algorithm, sm4-ce can depend on
the SM4 library instead of sm4-generic, and some functions in sm4-generic
do not need to be exported.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Tianjia Zhang and committed by
Herbert Xu
c59de48e 2b31277a

+30 -30
+1 -1
arch/arm64/crypto/Kconfig
··· 51 51 tristate "SM4 symmetric cipher (ARMv8.2 Crypto Extensions)" 52 52 depends on KERNEL_MODE_NEON 53 53 select CRYPTO_ALGAPI 54 - select CRYPTO_SM4 54 + select CRYPTO_LIB_SM4 55 55 56 56 config CRYPTO_GHASH_ARM64_CE 57 57 tristate "GHASH/AES-GCM using ARMv8 Crypto Extensions"
+14 -6
arch/arm64/crypto/sm4-ce-glue.c
··· 17 17 18 18 asmlinkage void sm4_ce_do_crypt(const u32 *rk, void *out, const void *in); 19 19 20 + static int sm4_ce_setkey(struct crypto_tfm *tfm, const u8 *key, 21 + unsigned int key_len) 22 + { 23 + struct sm4_ctx *ctx = crypto_tfm_ctx(tfm); 24 + 25 + return sm4_expandkey(ctx, key, key_len); 26 + } 27 + 20 28 static void sm4_ce_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 21 29 { 22 - const struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm); 30 + const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm); 23 31 24 32 if (!crypto_simd_usable()) { 25 - crypto_sm4_encrypt(tfm, out, in); 33 + sm4_crypt_block(ctx->rkey_enc, out, in); 26 34 } else { 27 35 kernel_neon_begin(); 28 36 sm4_ce_do_crypt(ctx->rkey_enc, out, in); ··· 40 32 41 33 static void sm4_ce_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 42 34 { 43 - const struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm); 35 + const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm); 44 36 45 37 if (!crypto_simd_usable()) { 46 - crypto_sm4_decrypt(tfm, out, in); 38 + sm4_crypt_block(ctx->rkey_dec, out, in); 47 39 } else { 48 40 kernel_neon_begin(); 49 41 sm4_ce_do_crypt(ctx->rkey_dec, out, in); ··· 57 49 .cra_priority = 200, 58 50 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 59 51 .cra_blocksize = SM4_BLOCK_SIZE, 60 - .cra_ctxsize = sizeof(struct crypto_sm4_ctx), 52 + .cra_ctxsize = sizeof(struct sm4_ctx), 61 53 .cra_module = THIS_MODULE, 62 54 .cra_u.cipher = { 63 55 .cia_min_keysize = SM4_KEY_SIZE, 64 56 .cia_max_keysize = SM4_KEY_SIZE, 65 - .cia_setkey = crypto_sm4_set_key, 57 + .cia_setkey = sm4_ce_setkey, 66 58 .cia_encrypt = sm4_ce_encrypt, 67 59 .cia_decrypt = sm4_ce_decrypt 68 60 }
+12 -15
crypto/sm4_generic.c
··· 17 17 #include <asm/unaligned.h> 18 18 19 19 /** 20 - * crypto_sm4_set_key - Set the SM4 key. 20 + * sm4_setkey - Set the SM4 key. 21 21 * @tfm: The %crypto_tfm that is used in the context. 22 22 * @in_key: The input key. 23 23 * @key_len: The size of the key. 24 24 * 25 25 * This function uses sm4_expandkey() to expand the key. 26 - * &crypto_sm4_ctx _must_ be the private data embedded in @tfm which is 26 + * &sm4_ctx _must_ be the private data embedded in @tfm which is 27 27 * retrieved with crypto_tfm_ctx(). 28 28 * 29 29 * Return: 0 on success; -EINVAL on failure (only happens for bad key lengths) 30 30 */ 31 - int crypto_sm4_set_key(struct crypto_tfm *tfm, const u8 *in_key, 31 + static int sm4_setkey(struct crypto_tfm *tfm, const u8 *in_key, 32 32 unsigned int key_len) 33 33 { 34 - struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm); 34 + struct sm4_ctx *ctx = crypto_tfm_ctx(tfm); 35 35 36 36 return sm4_expandkey(ctx, in_key, key_len); 37 37 } 38 - EXPORT_SYMBOL_GPL(crypto_sm4_set_key); 39 38 40 39 /* encrypt a block of text */ 41 40 42 - void crypto_sm4_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 41 + static void sm4_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 43 42 { 44 - const struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm); 43 + const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm); 45 44 46 45 sm4_crypt_block(ctx->rkey_enc, out, in); 47 46 } 48 - EXPORT_SYMBOL_GPL(crypto_sm4_encrypt); 49 47 50 48 /* decrypt a block of text */ 51 49 52 - void crypto_sm4_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 50 + static void sm4_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 53 51 { 54 - const struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm); 52 + const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm); 55 53 56 54 sm4_crypt_block(ctx->rkey_dec, out, in); 57 55 } 58 - EXPORT_SYMBOL_GPL(crypto_sm4_decrypt); 59 56 60 57 static struct crypto_alg sm4_alg = { 61 58 .cra_name = "sm4", ··· 60 63 .cra_priority = 100, 61 64 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 62 65 .cra_blocksize = SM4_BLOCK_SIZE, 63 - .cra_ctxsize = sizeof(struct crypto_sm4_ctx), 66 + .cra_ctxsize = sizeof(struct sm4_ctx), 64 67 .cra_module = THIS_MODULE, 65 68 .cra_u = { 66 69 .cipher = { 67 70 .cia_min_keysize = SM4_KEY_SIZE, 68 71 .cia_max_keysize = SM4_KEY_SIZE, 69 - .cia_setkey = crypto_sm4_set_key, 70 - .cia_encrypt = crypto_sm4_encrypt, 71 - .cia_decrypt = crypto_sm4_decrypt 72 + .cia_setkey = sm4_setkey, 73 + .cia_encrypt = sm4_encrypt, 74 + .cia_decrypt = sm4_decrypt 72 75 } 73 76 } 74 77 };
+2 -7
include/crypto/sm4.h
··· 16 16 #define SM4_BLOCK_SIZE 16 17 17 #define SM4_RKEY_WORDS 32 18 18 19 - struct crypto_sm4_ctx { 19 + struct sm4_ctx { 20 20 u32 rkey_enc[SM4_RKEY_WORDS]; 21 21 u32 rkey_dec[SM4_RKEY_WORDS]; 22 22 }; ··· 30 30 * Returns 0 on success. The function fails only if an invalid key size (or 31 31 * pointer) is supplied. 32 32 */ 33 - int sm4_expandkey(struct crypto_sm4_ctx *ctx, const u8 *in_key, 33 + int sm4_expandkey(struct sm4_ctx *ctx, const u8 *in_key, 34 34 unsigned int key_len); 35 35 36 36 /** ··· 40 40 * @in: Buffer containing the input data 41 41 */ 42 42 void sm4_crypt_block(const u32 *rk, u8 *out, const u8 *in); 43 - 44 - int crypto_sm4_set_key(struct crypto_tfm *tfm, const u8 *in_key, 45 - unsigned int key_len); 46 - void crypto_sm4_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in); 47 - void crypto_sm4_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in); 48 43 49 44 #endif
+1 -1
lib/crypto/sm4.c
··· 108 108 * Returns 0 on success. The function fails only if an invalid key size (or 109 109 * pointer) is supplied. 110 110 */ 111 - int sm4_expandkey(struct crypto_sm4_ctx *ctx, const u8 *in_key, 111 + int sm4_expandkey(struct sm4_ctx *ctx, const u8 *in_key, 112 112 unsigned int key_len) 113 113 { 114 114 u32 rk[4];