aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/linux/bpf_crypto.h
diff options
context:
space:
mode:
authorVadim Fedorenko <vadfed@meta.com>2024-04-22 15:50:21 -0700
committerMartin KaFai Lau <martin.lau@kernel.org>2024-04-24 16:01:10 -0700
commit3e1c6f35409f9e447bf37f64840f5b65576bfb78 (patch)
tree6ff5c59d598f975728cfdd1f4d29407d4b6cae01 /include/linux/bpf_crypto.h
parentbpf: update the comment for BTF_FIELDS_MAX (diff)
downloadwireguard-linux-3e1c6f35409f9e447bf37f64840f5b65576bfb78.tar.xz
wireguard-linux-3e1c6f35409f9e447bf37f64840f5b65576bfb78.zip
bpf: make common crypto API for TC/XDP programs
Add crypto API support to BPF to be able to decrypt or encrypt packets in TC/XDP BPF programs. Special care should be taken for initialization part of crypto algo because crypto alloc) 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. Signed-off-by: Vadim Fedorenko <vadfed@meta.com> Link: https://lore.kernel.org/r/20240422225024.2847039-2-vadfed@meta.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'include/linux/bpf_crypto.h')
-rw-r--r--include/linux/bpf_crypto.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/bpf_crypto.h b/include/linux/bpf_crypto.h
new file mode 100644
index 000000000000..a41e71d4e2d9
--- /dev/null
+++ b/include/linux/bpf_crypto.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+#ifndef _BPF_CRYPTO_H
+#define _BPF_CRYPTO_H
+
+struct bpf_crypto_type {
+ void *(*alloc_tfm)(const char *algo);
+ void (*free_tfm)(void *tfm);
+ int (*has_algo)(const char *algo);
+ int (*setkey)(void *tfm, const u8 *key, unsigned int keylen);
+ int (*setauthsize)(void *tfm, unsigned int authsize);
+ int (*encrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);
+ int (*decrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);
+ unsigned int (*ivsize)(void *tfm);
+ unsigned int (*statesize)(void *tfm);
+ u32 (*get_flags)(void *tfm);
+ struct module *owner;
+ char name[14];
+};
+
+int bpf_crypto_register_type(const struct bpf_crypto_type *type);
+int bpf_crypto_unregister_type(const struct bpf_crypto_type *type);
+
+#endif /* _BPF_CRYPTO_H */