Skip to contentSkip to conversation

bpf: add skcipher API support to TC/XDP programs

PATCH In review Vadim Fedorenko 3 participants 12 messages Nov 18, 2023 – Nov 20, 2023

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/2 bpf: add skcipher API support to TC/XDP programs

Add crypto API support to BPF to be able to decrypt or encrypt packets in TC/XDP BPF programs. Only symmetric key ciphers are supported for now. Special care should be taken for initialization part of crypto algo because crypto_alloc_sync_skcipher() doesn't work with preemtion disabled, it can be run only in sleepable BPF program. Also async crypto is not supported because of the very same issue - TC/XDP BPF programs are not sleepable.

---
v4 -> v5:
- replace crypto API to use lskcipher (suggested by Herbert Xu)
- remove SG list usage and provide raw buffers
v3 -> v4:
- reuse __bpf_dynptr_data and remove own implementation
- use const __str to provide algorithm name
- use kfunc macroses to avoid compilator warnings
v2 -> v3:
- fix kdoc issues
v1 -> v2:
- use kmalloc in sleepable func, suggested by Alexei
- use __bpf_dynptr_is_rdonly() to check destination, suggested by Jakub
- use __bpf_dynptr_data_ptr() for all dynptr accesses

---
 include/linux/bpf.h   |   1 +
 kernel/bpf/Makefile   |   3 +
 kernel/bpf/crypto.c   | 258 ++++++++++++++++++++++++++++++++++++++++++
 kernel/bpf/helpers.c  |   2 +-
 kernel/bpf/verifier.c |   1 +
 5 files changed, 264 insertions(+), 1 deletion(-)
 create mode 100644 kernel/bpf/crypto.c
include/linux/bpf.h +1 -0
index 4001d11be151..77934ab7421d 100644
@@ -1224,6 +1224,7 @@ int bpf_dynptr_check_size(u32 size);
 u32 __bpf_dynptr_size(const struct bpf_dynptr_kern *ptr);
 const void *__bpf_dynptr_data(const struct bpf_dynptr_kern *ptr, u32 len);
 void *__bpf_dynptr_data_rw(const struct bpf_dynptr_kern *ptr, u32 len);
+bool __bpf_dynptr_is_rdonly(const struct bpf_dynptr_kern *ptr);
 
 #ifdef CONFIG_BPF_JIT
 int bpf_trampoline_link_prog(struct bpf_tramp_link *link, struct bpf_trampoline *tr);
kernel/bpf/Makefile +3 -0
index f526b7573e97..e14b5834c477 100644
@@ -41,6 +41,9 @@ obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o
 obj-$(CONFIG_BPF_SYSCALL) += cpumask.o
 obj-${CONFIG_BPF_LSM} += bpf_lsm.o
 endif
+ifeq ($(CONFIG_CRYPTO_SKCIPHER),y)
+obj-$(CONFIG_BPF_SYSCALL) += crypto.o
+endif
 obj-$(CONFIG_BPF_PRELOAD) += preload/
 
 obj-$(CONFIG_BPF_SYSCALL) += relo_core.o
kernel/bpf/crypto.c new file +258 -0

258 lines not on this page · raw message

kernel/bpf/helpers.c +1 -1
index b45a8381f9bd..b73314c0124e 100644
@@ -1436,7 +1436,7 @@ static const struct bpf_func_proto bpf_kptr_xchg_proto = {
 #define DYNPTR_SIZE_MASK	0xFFFFFF
 #define DYNPTR_RDONLY_BIT	BIT(31)
 
-static bool __bpf_dynptr_is_rdonly(const struct bpf_dynptr_kern *ptr)
+bool __bpf_dynptr_is_rdonly(const struct bpf_dynptr_kern *ptr)
 {
 	return ptr->size & DYNPTR_RDONLY_BIT;
 }
kernel/bpf/verifier.c +1 -0
index 7c3461b89513..a20324ea990b 100644
@@ -5558,6 +5558,7 @@ BTF_ID(struct, cgroup)
 #endif
 BTF_ID(struct, bpf_cpumask)
 BTF_ID(struct, task_struct)
+BTF_ID(struct, bpf_crypto_lskcipher_ctx)
 BTF_SET_END(rcu_protected_types)
 
 static bool rcu_protected_object(const struct btf *btf, u32 btf_id)
Signature · 1 line
2.39.3
#1 lore raw

PATCH v5 2/2 selftests: bpf: crypto skcipher algo selftests

Add simple tc hook selftests to show the way to work with new crypto BPF API. Some weird structre and map are added to setup program to make verifier happy about dynptr initialization from memory. Simple AES-ECB algo is used to demonstrate encryption and decryption of fixed size buffers.

---
v4 -> v5:
- adjust selftests to use new naming
- restore tests on aarch64 and s390 as no sg lists are used v3 -> v4:
- adjust selftests to use new syntax of helpers
- add tests for acquire and release
v2 -> v3:
- disable tests on s390 and aarch64 because of unknown Fatal exception in sg_init_one
v1 -> v2:
- add CONFIG_CRYPTO_AES and CONFIG_CRYPTO_ECB to selftest build config suggested by Daniel

---
 tools/testing/selftests/bpf/config            |   3 +
 .../selftests/bpf/prog_tests/crypto_sanity.c  | 148 ++++++++++++++
 .../selftests/bpf/progs/crypto_common.h       |  69 +++++++
 .../selftests/bpf/progs/crypto_sanity.c       | 193 ++++++++++++++++++
 4 files changed, 413 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/crypto_sanity.c
 create mode 100644 tools/testing/selftests/bpf/progs/crypto_common.h
 create mode 100644 tools/testing/selftests/bpf/progs/crypto_sanity.c
tools/testing/selftests/bpf/config +3 -0
index 3ec5927ec3e5..81e521e9c0e9 100644
@@ -14,6 +14,9 @@ CONFIG_CGROUP_BPF=y
 CONFIG_CRYPTO_HMAC=y
 CONFIG_CRYPTO_SHA256=y
 CONFIG_CRYPTO_USER_API_HASH=y
+CONFIG_CRYPTO_SKCIPHER=y
+CONFIG_CRYPTO_ECB=y
+CONFIG_CRYPTO_AES=y
 CONFIG_DEBUG_INFO=y
 CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_DWARF4=y
tools/testing/selftests/bpf/prog_tests/crypto_sanity.c new file +148 -0

148 lines not on this page · raw message

tools/testing/selftests/bpf/progs/crypto_common.h new file +69 -0

69 lines not on this page · raw message

tools/testing/selftests/bpf/progs/crypto_sanity.c new file +193 -0

193 lines not on this page · raw message

Signature · 1 line
2.39.3
#2 lore raw

Re: [PATCH bpf-next v5 2/2] selftests: bpf: crypto skcipher algo selftests

tools/testing/selftests/bpf/progs/crypto_sanity.c line 60

Quoted 13 lines · Vadim Fedorenko
tools/testing/selftests/bpf/progs/crypto_sanity.c new file +12 -0
+
+SEC("fentry.s/bpf_fentry_test1")
+int BPF_PROG(skb_crypto_setup)
+{
+       struct bpf_crypto_lskcipher_ctx *cctx;
+       struct bpf_dynptr key = {};
+       int err = 0;
+
+       status = 0;
+
+       bpf_dynptr_from_mem(crypto_key, sizeof(crypto_key), 0, &key);
+       cctx = bpf_crypto_lskcipher_ctx_create(crypto_algo, &key, &err);

Direct string will work here, right?
What's the reason to use global var?

maintainer
#3 lore raw

Re: [PATCH bpf-next v5 2/2] selftests: bpf: crypto skcipher algo selftests

Quoted 17 lines · Alexei Starovoitov

tools/testing/selftests/bpf/progs/crypto_sanity.c line 60

Quoted 13 lines · Vadim Fedorenko
tools/testing/selftests/bpf/progs/crypto_sanity.c new file +12 -0
+
+SEC("fentry.s/bpf_fentry_test1")
+int BPF_PROG(skb_crypto_setup)
+{
+       struct bpf_crypto_lskcipher_ctx *cctx;
+       struct bpf_dynptr key = {};
+       int err = 0;
+
+       status = 0;
+
+       bpf_dynptr_from_mem(crypto_key, sizeof(crypto_key), 0, &key);
+       cctx = bpf_crypto_lskcipher_ctx_create(crypto_algo, &key, &err);

Direct string will work here, right?
What's the reason to use global var?

Mmm, yeah, should work. I'll update the test, thanks!

#4 lore raw
In reply to Vadim Fedorenko
Quoted 9 lines · Vadim Fedorenko
kernel/bpf/crypto.c new file +8 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */

kernel/bpf/crypto.c line 29

Quoted 10 lines
kernel/bpf/crypto.c new file +10 -0
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

maintainer
#5 lore raw
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · Vadim Fedorenko
kernel/bpf/crypto.c new file +14 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
Quoted 8 lines

kernel/bpf/crypto.c line 29

Quoted 4 lines
kernel/bpf/crypto.c new file +4 -0
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

The only reason I added it was the existence of AEAD subset of crypto API. And this subset can also be implemented in bpf later, and there will be inconsistency in naming then if we add aead in future names. WDYT?

#6 lore raw
Quoted 27 lines · Vadim Fedorenko
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · Vadim Fedorenko
kernel/bpf/crypto.c new file +14 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
Quoted 8 lines

kernel/bpf/crypto.c line 29

Quoted 4 lines
kernel/bpf/crypto.c new file +4 -0
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

Quoted 4 lines

The only reason I added it was the existence of AEAD subset of crypto API. And this subset can also be implemented in bpf later, and there will be inconsistency in naming then if we add aead in future names. WDYT?

You mean future async apis ? Just bpf_crypto_encrypt_async() ?

maintainer
#7 lore raw
Quoted 29 lines · Alexei Starovoitov
Quoted 27 lines · Vadim Fedorenko
Quoted 24 lines · Alexei Starovoitov
Quoted 9 lines · Vadim Fedorenko
kernel/bpf/crypto.c new file +8 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */

kernel/bpf/crypto.c line 29

Quoted 10 lines
kernel/bpf/crypto.c new file +10 -0
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

Quoted 6 lines
Quoted 4 lines

The only reason I added it was the existence of AEAD subset of crypto API. And this subset can also be implemented in bpf later, and there will be inconsistency in naming then if we add aead in future names. WDYT?

You mean future async apis ? Just bpf_crypto_encrypt_async() ?

Well, not only async. It's about Authenticated Encryption With Associated Data (AEAD) Cipher API defined in crypto/aead.h. It's ciphers with additional hmac function, like 'authenc(hmac(sha256),cbc(aes))'. It has very similar API with only difference of having Authenticated data in the encrypted block.

I'm not sure though if there is explicit sync implementation, but I do believe async ciphers can be filtered out for this interface too.

#8 lore raw
Quoted 36 lines · Vadim Fedorenko
Quoted 34 lines · Alexei Starovoitov
Quoted 31 lines · Vadim Fedorenko
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · Vadim Fedorenko
kernel/bpf/crypto.c new file +14 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
Quoted 8 lines

kernel/bpf/crypto.c line 29

Quoted 4 lines
kernel/bpf/crypto.c new file +4 -0
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

The only reason I added it was the existence of AEAD subset of crypto API. And this subset can also be implemented in bpf later, and there will be inconsistency in naming then if we add aead in future names. WDYT?

Quoted 7 lines
Quoted 1 line

You mean future async apis ? Just bpf_crypto_encrypt_async() ?

Well, not only async. It's about Authenticated Encryption With Associated Data (AEAD) Cipher API defined in crypto/aead.h. It's ciphers with additional hmac function, like 'authenc(hmac(sha256),cbc(aes))'. It has very similar API with only difference of having Authenticated data in the encrypted block.

and ? I'm not following what you're trying to say.
Where is the inconsistency ?
My point again is that lskcipher vs skcipher vs foo is an implementation detail that shouldn't be exposed in the name.

maintainer
#9 lore raw
Quoted 46 lines · Alexei Starovoitov
Quoted 36 lines · Vadim Fedorenko
Quoted 34 lines · Alexei Starovoitov
Quoted 31 lines · Vadim Fedorenko
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · Vadim Fedorenko
kernel/bpf/crypto.c new file +14 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
Quoted 8 lines

kernel/bpf/crypto.c line 29

Quoted 4 lines
kernel/bpf/crypto.c new file +4 -0
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

The only reason I added it was the existence of AEAD subset of crypto API. And this subset can also be implemented in bpf later, and there will be inconsistency in naming then if we add aead in future names. WDYT?

Quoted 7 lines
Quoted 1 line

You mean future async apis ? Just bpf_crypto_encrypt_async() ?

Well, not only async. It's about Authenticated Encryption With Associated Data (AEAD) Cipher API defined in crypto/aead.h. It's ciphers with additional hmac function, like 'authenc(hmac(sha256),cbc(aes))'. It has very similar API with only difference of having Authenticated data in the encrypted block.

Quoted 4 lines

and ? I'm not following what you're trying to say.
Where is the inconsistency ?
My point again is that lskcipher vs skcipher vs foo is an implementation detail that shouldn't be exposed in the name.

Well, I was trying to follow crypto subsystem naming. It might be easier for users to understand what part of crypto API is supported by BPF kfuncs.

At the same we can agree that current implementation will be used for simple
buffer encryption/decryption and any further implementations will have additions in the name of functions (like bpf_crypto_aead_crypt/bpf_crypto_shash_final/bpf_crypto_scomp_compress). It will be slightly inconsistent, but we will have to expose some implementation
details unfortunately. If you are ok with this way, I'm ok to implement it.

#10 lore raw
Quoted 56 lines · Vadim Fedorenko
Quoted 46 lines · Alexei Starovoitov
Quoted 36 lines · Vadim Fedorenko
Quoted 34 lines · Alexei Starovoitov
Quoted 31 lines · Vadim Fedorenko
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · Vadim Fedorenko
(quoted diff) +14 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

The only reason I added it was the existence of AEAD subset of crypto API. And this subset can also be implemented in bpf later, and there will be inconsistency in naming then if we add aead in future names. WDYT?

Quoted 7 lines
Quoted 1 line

You mean future async apis ? Just bpf_crypto_encrypt_async() ?

Well, not only async. It's about Authenticated Encryption With Associated Data (AEAD) Cipher API defined in crypto/aead.h. It's ciphers with additional hmac function, like 'authenc(hmac(sha256),cbc(aes))'. It has very similar API with only difference of having Authenticated data in the encrypted block.

Quoted 4 lines

and ? I'm not following what you're trying to say.
Where is the inconsistency ?
My point again is that lskcipher vs skcipher vs foo is an implementation detail that shouldn't be exposed in the name.

Well, I was trying to follow crypto subsystem naming. It might be easier for users to understand what part of crypto API is supported by BPF kfuncs.

Quoted 6 lines

At the same we can agree that current implementation will be used for simple buffer encryption/decryption and any further implementations will have additions in the name of functions (like bpf_crypto_aead_crypt/bpf_crypto_shash_final/bpf_crypto_scomp_compress). It will be slightly inconsistent, but we will have to expose some implementation details unfortunately. If you are ok with this way, I'm ok to implement it.

but shash vs scomp is the name of the algo ? Didn't you use it as the 1st arg to bpf_crypto_create() ?
Take a look at AF_ALG. It's able to express all kinds of cryptos through the same socket abstraction without creating a new name for every algo. Everything is read/write through the socket fd. In our case it will be bpf_crypto_encrypt/decrypt() kfuncs.

maintainer
#11 lore raw
Quoted 65 lines · Alexei Starovoitov
Quoted 56 lines · Vadim Fedorenko
Quoted 46 lines · Alexei Starovoitov
Quoted 36 lines · Vadim Fedorenko
Quoted 34 lines · Alexei Starovoitov
Quoted 31 lines · Vadim Fedorenko
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · Vadim Fedorenko
(quoted diff) +14 -0
+/**
+ * struct bpf_crypto_lskcipher_ctx - refcounted BPF sync skcipher context structure
+ * @tfm:       The pointer to crypto_sync_skcipher struct.
+ * @rcu:       The RCU head used to free the crypto context with RCU safety.
+ * @usage:     Object reference counter. When the refcount goes to 0, the
+ *             memory is released back to the BPF allocator, which provides
+ *             RCU safety.
+ */
+struct bpf_crypto_lskcipher_ctx {
+       struct crypto_lskcipher *tfm;
+       struct rcu_head rcu;
+       refcount_t usage;
+};
+
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_crypto_lskcipher_ctx_create() - Create a mutable BPF crypto context.

Let's drop 'lskcipher' from the kfunc names and ctx struct. bpf users don't need to know the internal implementation details. bpf_crypto_encrypt/decrypt() is clear enough.

The only reason I added it was the existence of AEAD subset of crypto API. And this subset can also be implemented in bpf later, and there will be inconsistency in naming then if we add aead in future names. WDYT?

Quoted 7 lines
Quoted 1 line

You mean future async apis ? Just bpf_crypto_encrypt_async() ?

Well, not only async. It's about Authenticated Encryption With Associated Data (AEAD) Cipher API defined in crypto/aead.h. It's ciphers with additional hmac function, like 'authenc(hmac(sha256),cbc(aes))'. It has very similar API with only difference of having Authenticated data in the encrypted block.

Quoted 4 lines

and ? I'm not following what you're trying to say.
Where is the inconsistency ?
My point again is that lskcipher vs skcipher vs foo is an implementation detail that shouldn't be exposed in the name.

Well, I was trying to follow crypto subsystem naming. It might be easier for users to understand what part of crypto API is supported by BPF kfuncs.

Quoted 6 lines

At the same we can agree that current implementation will be used for simple buffer encryption/decryption and any further implementations will have additions in the name of functions (like bpf_crypto_aead_crypt/bpf_crypto_shash_final/bpf_crypto_scomp_compress). It will be slightly inconsistent, but we will have to expose some implementation details unfortunately. If you are ok with this way, I'm ok to implement it.

Quoted 6 lines

but shash vs scomp is the name of the algo ? Didn't you use it as the 1st arg to bpf_crypto_create() ?
Take a look at AF_ALG. It's able to express all kinds of cryptos through the same socket abstraction without creating a new name for every algo. Everything is read/write through the socket fd. In our case it will be bpf_crypto_encrypt/decrypt() kfuncs.

Ok, I got the idea. I'll make v6 more general, like AF_ALG, but it will support only one type (skcipher) for now. Thanks!