mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	bpf: crypto: add skcipher to bpf crypto
Implement skcipher crypto in BPF crypto framework. Signed-off-by: Vadim Fedorenko <vadfed@meta.com> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Link: https://lore.kernel.org/r/20240422225024.2847039-3-vadfed@meta.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
		
							parent
							
								
									3e1c6f3540
								
							
						
					
					
						commit
						fda4f71282
					
				
					 3 changed files with 93 additions and 0 deletions
				
			
		|  | @ -3822,6 +3822,14 @@ F:	kernel/bpf/tnum.c | ||||||
| F:	kernel/bpf/trampoline.c | F:	kernel/bpf/trampoline.c | ||||||
| F:	kernel/bpf/verifier.c | F:	kernel/bpf/verifier.c | ||||||
| 
 | 
 | ||||||
|  | BPF [CRYPTO] | ||||||
|  | M:	Vadim Fedorenko <vadim.fedorenko@linux.dev> | ||||||
|  | L:	bpf@vger.kernel.org | ||||||
|  | S:	Maintained | ||||||
|  | F:	crypto/bpf_crypto_skcipher.c | ||||||
|  | F:	include/linux/bpf_crypto.h | ||||||
|  | F:	kernel/bpf/crypto.c | ||||||
|  | 
 | ||||||
| BPF [DOCUMENTATION] (Related to Standardization) | BPF [DOCUMENTATION] (Related to Standardization) | ||||||
| R:	David Vernet <void@manifault.com> | R:	David Vernet <void@manifault.com> | ||||||
| L:	bpf@vger.kernel.org | L:	bpf@vger.kernel.org | ||||||
|  |  | ||||||
|  | @ -20,6 +20,9 @@ crypto_skcipher-y += lskcipher.o | ||||||
| crypto_skcipher-y += skcipher.o | crypto_skcipher-y += skcipher.o | ||||||
| 
 | 
 | ||||||
| obj-$(CONFIG_CRYPTO_SKCIPHER2) += crypto_skcipher.o | obj-$(CONFIG_CRYPTO_SKCIPHER2) += crypto_skcipher.o | ||||||
|  | ifeq ($(CONFIG_BPF_SYSCALL),y) | ||||||
|  | obj-$(CONFIG_CRYPTO_SKCIPHER2) += bpf_crypto_skcipher.o | ||||||
|  | endif | ||||||
| 
 | 
 | ||||||
| obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o | obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o | ||||||
| obj-$(CONFIG_CRYPTO_ECHAINIV) += echainiv.o | obj-$(CONFIG_CRYPTO_ECHAINIV) += echainiv.o | ||||||
|  |  | ||||||
							
								
								
									
										82
									
								
								crypto/bpf_crypto_skcipher.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								crypto/bpf_crypto_skcipher.c
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,82 @@ | ||||||
|  | // SPDX-License-Identifier: GPL-2.0-only
 | ||||||
|  | /* Copyright (c) 2024 Meta, Inc */ | ||||||
|  | #include <linux/types.h> | ||||||
|  | #include <linux/module.h> | ||||||
|  | #include <linux/bpf_crypto.h> | ||||||
|  | #include <crypto/skcipher.h> | ||||||
|  | 
 | ||||||
|  | static void *bpf_crypto_lskcipher_alloc_tfm(const char *algo) | ||||||
|  | { | ||||||
|  | 	return crypto_alloc_lskcipher(algo, 0, 0); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void bpf_crypto_lskcipher_free_tfm(void *tfm) | ||||||
|  | { | ||||||
|  | 	crypto_free_lskcipher(tfm); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static int bpf_crypto_lskcipher_has_algo(const char *algo) | ||||||
|  | { | ||||||
|  | 	return crypto_has_skcipher(algo, CRYPTO_ALG_TYPE_LSKCIPHER, CRYPTO_ALG_TYPE_MASK); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static int bpf_crypto_lskcipher_setkey(void *tfm, const u8 *key, unsigned int keylen) | ||||||
|  | { | ||||||
|  | 	return crypto_lskcipher_setkey(tfm, key, keylen); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static u32 bpf_crypto_lskcipher_get_flags(void *tfm) | ||||||
|  | { | ||||||
|  | 	return crypto_lskcipher_get_flags(tfm); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static unsigned int bpf_crypto_lskcipher_ivsize(void *tfm) | ||||||
|  | { | ||||||
|  | 	return crypto_lskcipher_ivsize(tfm); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static unsigned int bpf_crypto_lskcipher_statesize(void *tfm) | ||||||
|  | { | ||||||
|  | 	return crypto_lskcipher_statesize(tfm); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static int bpf_crypto_lskcipher_encrypt(void *tfm, const u8 *src, u8 *dst, | ||||||
|  | 					unsigned int len, u8 *siv) | ||||||
|  | { | ||||||
|  | 	return crypto_lskcipher_encrypt(tfm, src, dst, len, siv); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static int bpf_crypto_lskcipher_decrypt(void *tfm, const u8 *src, u8 *dst, | ||||||
|  | 					unsigned int len, u8 *siv) | ||||||
|  | { | ||||||
|  | 	return crypto_lskcipher_decrypt(tfm, src, dst, len, siv); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static const struct bpf_crypto_type bpf_crypto_lskcipher_type = { | ||||||
|  | 	.alloc_tfm	= bpf_crypto_lskcipher_alloc_tfm, | ||||||
|  | 	.free_tfm	= bpf_crypto_lskcipher_free_tfm, | ||||||
|  | 	.has_algo	= bpf_crypto_lskcipher_has_algo, | ||||||
|  | 	.setkey		= bpf_crypto_lskcipher_setkey, | ||||||
|  | 	.encrypt	= bpf_crypto_lskcipher_encrypt, | ||||||
|  | 	.decrypt	= bpf_crypto_lskcipher_decrypt, | ||||||
|  | 	.ivsize		= bpf_crypto_lskcipher_ivsize, | ||||||
|  | 	.statesize	= bpf_crypto_lskcipher_statesize, | ||||||
|  | 	.get_flags	= bpf_crypto_lskcipher_get_flags, | ||||||
|  | 	.owner		= THIS_MODULE, | ||||||
|  | 	.name		= "skcipher", | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static int __init bpf_crypto_skcipher_init(void) | ||||||
|  | { | ||||||
|  | 	return bpf_crypto_register_type(&bpf_crypto_lskcipher_type); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void __exit bpf_crypto_skcipher_exit(void) | ||||||
|  | { | ||||||
|  | 	int err = bpf_crypto_unregister_type(&bpf_crypto_lskcipher_type); | ||||||
|  | 	WARN_ON_ONCE(err); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | module_init(bpf_crypto_skcipher_init); | ||||||
|  | module_exit(bpf_crypto_skcipher_exit); | ||||||
|  | MODULE_LICENSE("GPL"); | ||||||
		Loading…
	
		Reference in a new issue
	
	 Vadim Fedorenko
						Vadim Fedorenko