Skip to contentSkip to conversation

Add cryptographic hash and signature verification kfuncs to BPF

PATCH Superseded Daniel Hodges 4 participants 8 messages Feb 2 – Feb 4

Subsystems (6)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#3 lore raw

PATCH v7 3/4 bpf: Add signature verification kfuncs

In reply to Daniel Hodges

Add a bpf_crypto_sig module that registers signature verification algorithms with the BPF crypto type system. This enables signature operations (like ECDSA) to use the unified bpf_crypto_ctx structure.

The module provides:
- alloc_tfm/free_tfm for crypto_sig transform lifecycle
- has_algo to check algorithm availability
- setkey for public key configuration
- verify for signature verification
- get_flags for crypto API flags

Introduce bpf_sig_verify, bpf_sig_keysize, bpf_sig_digestsize, and bpf_sig_maxsize kfuncs enabling BPF programs to verify digital signatures using the kernel's crypto infrastructure.

Add enum bpf_crypto_type_id for runtime type checking to ensure operations are performed on the correct crypto context type. The enum values are assigned to all crypto type modules (skcipher, hash, sig).

The verify kfunc takes a crypto context (initialized with the sig type and appropriate algorithm like "ecdsa-nist-p256"), a message digest, and a signature. These kfuncs support any signature algorithm registered with the crypto subsystem (e.g., ECDSA, RSA).

---
 MAINTAINERS                |   1 +
 crypto/Makefile            |   3 +
 crypto/bpf_crypto_sig.c    |  89 ++++++++++++++++++++++++++++
 include/linux/bpf_crypto.h |   4 ++
 kernel/bpf/crypto.c        | 117 +++++++++++++++++++++++++++++++++++++
 5 files changed, 214 insertions(+)
 create mode 100644 crypto/bpf_crypto_sig.c
MAINTAINERS +1 -0
index 9602b6216ab9..d23ea38b606f 100644
@@ -4714,6 +4714,7 @@ M:	Vadim Fedorenko <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	crypto/bpf_crypto_shash.c
+F:	crypto/bpf_crypto_sig.c
 F:	crypto/bpf_crypto_skcipher.c
 F:	include/linux/bpf_crypto.h
 F:	kernel/bpf/crypto.c
crypto/Makefile +3 -0
index 853dff375906..c9ab98b57bc0 100644
@@ -36,6 +36,9 @@ endif
 
 obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o
 obj-$(CONFIG_CRYPTO_SIG2) += sig.o
+ifeq ($(CONFIG_BPF_SYSCALL),y)
+obj-$(CONFIG_CRYPTO_SIG2) += bpf_crypto_sig.o
+endif
 obj-$(CONFIG_CRYPTO_KPP2) += kpp.o
 obj-$(CONFIG_CRYPTO_HKDF) += hkdf.o
 
crypto/bpf_crypto_sig.c new file +89 -0

89 lines not on this page · raw message

include/linux/bpf_crypto.h +4 -0
index cf2c66f9782b..e0f946926f69 100644
@@ -18,9 +18,13 @@ struct bpf_crypto_type {
 	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);
 	int (*hash)(void *tfm, const u8 *data, u8 *out, unsigned int len);
+	int (*verify)(void *tfm, const u8 *sig, unsigned int sig_len,
+		      const u8 *msg, unsigned int msg_len);
 	unsigned int (*ivsize)(void *tfm);
 	unsigned int (*statesize)(void *tfm);
 	unsigned int (*digestsize)(void *tfm);
+	unsigned int (*keysize)(void *tfm);
+	unsigned int (*maxsize)(void *tfm);
 	u32 (*get_flags)(void *tfm);
 	struct module *owner;
 	enum bpf_crypto_type_id type_id;
kernel/bpf/crypto.c +117 -0

129 lines not on this page · raw message

Signature · 1 line
2.52.0
#1 lore raw

PATCH v7 1/4 bpf: Add hash kfunc for cryptographic hashing

In reply to Daniel Hodges

Add bpf_crypto_shash module that registers a hash type with the BPF crypto infrastructure, enabling BPF programs to access kernel hash algorithms through a unified interface.

The bpf_crypto_type interface is extended with hash-specific callbacks:
- alloc_tfm: Allocates crypto_shash context with proper descriptor size
- free_tfm: Releases hash transform and context memory
- has_algo: Checks algorithm availability via crypto_has_shash()
- hash: Performs single-shot hashing via crypto_shash_digest()
- digestsize: Returns the output size for the hash algorithm
- get_flags: Exposes transform flags to BPF programs

Add bpf_crypto_hash() kfunc that works with any hash algorithm registered in the kernel's crypto API through the BPF crypto type system. This enables BPF programs to compute cryptographic hashes for use cases such as content verification, integrity checking, and data authentication.

Update bpf_crypto_ctx_create() to support keyless operations:
- Hash algorithms don't require keys, unlike ciphers
- Only validates key presence if type->setkey is defined
- Conditionally sets IV/state length for cipher operations only

---
 MAINTAINERS                  |  1 +
 crypto/Makefile              |  3 ++
 crypto/bpf_crypto_shash.c    | 96 ++++++++++++++++++++++++++++++++++++
 crypto/bpf_crypto_skcipher.c |  1 +
 include/linux/bpf_crypto.h   |  9 ++++
 kernel/bpf/crypto.c          | 93 ++++++++++++++++++++++++++++++----
 6 files changed, 194 insertions(+), 9 deletions(-)
 create mode 100644 crypto/bpf_crypto_shash.c
MAINTAINERS +1 -0
index 491d567f7dc8..4e9b369acd1c 100644
@@ -4713,6 +4713,7 @@ BPF [CRYPTO]
 M:	Vadim Fedorenko <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	crypto/bpf_crypto_shash.c
 F:	crypto/bpf_crypto_skcipher.c
 F:	include/linux/bpf_crypto.h
 F:	kernel/bpf/crypto.c
crypto/Makefile +3 -0
index 16a35649dd91..853dff375906 100644
@@ -30,6 +30,9 @@ obj-$(CONFIG_CRYPTO_ECHAINIV) += echainiv.o
 crypto_hash-y += ahash.o
 crypto_hash-y += shash.o
 obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
+ifeq ($(CONFIG_BPF_SYSCALL),y)
+obj-$(CONFIG_CRYPTO_HASH2) += bpf_crypto_shash.o
+endif
 
 obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o
 obj-$(CONFIG_CRYPTO_SIG2) += sig.o
crypto/bpf_crypto_shash.c new file +96 -0

96 lines not on this page · raw message

crypto/bpf_crypto_skcipher.c +1 -0
index a88798d3e8c8..79d310fbcc48 100644
@@ -63,6 +63,7 @@ static const struct bpf_crypto_type bpf_crypto_lskcipher_type = {
 	.statesize	= bpf_crypto_lskcipher_statesize,
 	.get_flags	= bpf_crypto_lskcipher_get_flags,
 	.owner		= THIS_MODULE,
+	.type_id	= BPF_CRYPTO_TYPE_SKCIPHER,
 	.name		= "skcipher",
 };
 
include/linux/bpf_crypto.h +9 -0
index a41e71d4e2d9..cf2c66f9782b 100644
@@ -3,6 +3,12 @@
 #ifndef _BPF_CRYPTO_H
 #define _BPF_CRYPTO_H
 
+enum bpf_crypto_type_id {
+	BPF_CRYPTO_TYPE_SKCIPHER = 1,
+	BPF_CRYPTO_TYPE_HASH,
+	BPF_CRYPTO_TYPE_SIG,
+};
+
 struct bpf_crypto_type {
 	void *(*alloc_tfm)(const char *algo);
 	void (*free_tfm)(void *tfm);
@@ -11,10 +17,13 @@ struct bpf_crypto_type {
 	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);
+	int (*hash)(void *tfm, const u8 *data, u8 *out, unsigned int len);
 	unsigned int (*ivsize)(void *tfm);
 	unsigned int (*statesize)(void *tfm);
+	unsigned int (*digestsize)(void *tfm);
 	u32 (*get_flags)(void *tfm);
 	struct module *owner;
+	enum bpf_crypto_type_id type_id;
 	char name[14];
 };
 
kernel/bpf/crypto.c +84 -9

141 lines not on this page · raw message

Signature · 1 line
2.52.0
#0 lore raw

v7 cover Add cryptographic hash and signature verification kfuncs to BPF

This patch series enhances BPF's cryptographic functionality by introducing kernel functions for SHA hashing and ECDSA signature verification. The changes enable BPF programs to verify data integrity and authenticity across networking, security, and observability use cases.

The series addresses two gaps in BPF's cryptographic toolkit:

1. Cryptographic hashing - supports content verification and message digest preparation
2. Asymmetric signature verification - allows validation of signed data without requiring private keys in the datapath

Use cases include:
- Verifying signed network packets or application data in XDP/TC programs
- Integrity checks within tracing and security monitoring
- Zero-trust security models with BPF-based credential verification
- Content-addressed storage in BPF-based filesystems

The implementation leverages existing BPF patterns: it uses bpf_dynptr for memory safety, reuses kernel crypto libraries (lib/crypto/sha256.c and crypto/ecdsa.c) rather than reimplementing algorithms, and provides context-based APIs supporting multiple program types.

v1: https://lore.kernel.org/bpf/[email protected]/

v2: https://lore.kernel.org/bpf/[email protected]/
- Fixed redundant __bpf_dynptr_is_rdonly() checks (Vadim)
- Added BPF hash algorithm type registration module in crypto/ subsystem
- Added CONFIG_CRYPTO_HASH2 guards around bpf_crypto_hash() kfunc and its BTF registration, matching the pattern used for CONFIG_CRYPTO_ECDSA
- Added mandatory digestsize validation for hash operations

v3: https://lore.kernel.org/bpf/[email protected]/
- Fixed patch ordering - header changes now in separate first commit before crypto module to ensure bisectability (bot+bpf-ci)
- Fixed type mismatch - changed u32 to u64 for dynptr sizes in bpf_crypto_hash() to match __bpf_dynptr_size() return type (Mykyta)
- Added CONFIG_CRYPTO_ECDSA to selftest config (Song)
- Refactored test code duplication with setup_skel() helper (Song)
- Added copyright notices to all new files

v4: https://lore.kernel.org/bpf/[email protected]/
- Reused common bpf_crypto_ctx structure for hash and signature operations instead of separate context types (Song)
- Fixed integer truncation in bpf_crypto_hash when data_len > UINT_MAX
- Corrected KF_RCU flags for ECDSA kfuncs (only bpf_ecdsa_verify needs KF_RCU)
- Updated MAINTAINERS file in test patches
- Refactored selftests to use crypto_common.h for kfunc declarations

v5: https://lore.kernel.org/bpf/[email protected]/
- Fixed bisectability: moved bpf_crypto_type_id enum and type_id field introduction to the hash module commit, before it's used by hash kfunc
- Renamed kfuncs from bpf_ecdsa_* to bpf_sig_* since signature verification is not ECDSA-specific (Vadim)
- Added NULL checks in bpf_crypto_sig wrapper functions for optional digest_size and max_size callbacks to prevent NULL pointer dereference
- Added extra validation in bpf_sig_digestsize/bpf_sig_maxsize kfuncs to return -EOPNOTSUPP when underlying algorithm returns 0
- Renamed test files from ecdsa_verify to sig_verify for consistency

v6: https://lore.kernel.org/bpf/[email protected]/
- Fixed bisectability issue flagged by CI: squash hash module and hash kfunc commits so NULL checks in bpf_crypto_ctx_create() are present before the hash type is registered (bot+bpf-ci)
- Squash signature module and signature kfunc commits for the same reason
- This reduces the series from 7 to 4 commits while preserving all functionality
- Added type_id checks to bpf_crypto_encrypt() and bpf_crypto_decrypt() to prevent NULL pointer dereference when called with non-skcipher contexts

v7: https://github.com/kernel-patches/bpf/pull/10922
- Moved crypto/bpf_crypto_skcipher.c type_id assignment from signature patch to hash patch for better logical organization
- Added missing CONFIG_CRYPTO_SIG, CONFIG_CRYPTO_SIG2, CONFIG_CRYPTO_ECDSA, and CONFIG_CRYPTO_ECRDSA to selftest config to ensure signature verification tests can build properly

Daniel Hodges (4):
bpf: Add hash kfunc for cryptographic hashing selftests/bpf: Add tests for bpf_crypto_hash kfunc
bpf: Add signature verification kfuncs selftests/bpf: Add tests for signature verification kfuncs

 MAINTAINERS                                   |   6 +
 crypto/Makefile                               |   6 +
 crypto/bpf_crypto_shash.c                     |  96 ++++++
 crypto/bpf_crypto_sig.c                       |  89 ++++++
 crypto/bpf_crypto_skcipher.c                  |   1 +
 include/linux/bpf_crypto.h                    |  13 +
 kernel/bpf/crypto.c                           | 210 ++++++++++++-
 tools/testing/selftests/bpf/config            |   6 +
 .../selftests/bpf/prog_tests/crypto_hash.c    | 210 +++++++++++++
 .../selftests/bpf/prog_tests/sig_verify.c     | 163 ++++++++++
 .../selftests/bpf/progs/crypto_common.h       |   8 +
 .../testing/selftests/bpf/progs/crypto_hash.c | 231 ++++++++++++++
 .../testing/selftests/bpf/progs/sig_verify.c  | 286 ++++++++++++++++++
 13 files changed, 1316 insertions(+), 9 deletions(-)
 create mode 100644 crypto/bpf_crypto_shash.c
 create mode 100644 crypto/bpf_crypto_sig.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/crypto_hash.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/sig_verify.c
 create mode 100644 tools/testing/selftests/bpf/progs/crypto_hash.c
 create mode 100644 tools/testing/selftests/bpf/progs/sig_verify.c
Signature · 1 line
2.52.0
#2 lore raw

PATCH v7 2/4 selftests/bpf: Add tests for bpf_crypto_hash kfunc

Add selftests to validate the bpf_crypto_hash works properly. The tests verify both correct functionality and proper error handling.

Test Data:
All tests use the well-known NIST test vector input "abc" and validate against the standardized expected outputs for each algorithm. This ensures the BPF kfunc wrappers correctly delegate to the kernel crypto library.

---
 MAINTAINERS                                   |   2 +
 tools/testing/selftests/bpf/config            |   2 +
 .../selftests/bpf/prog_tests/crypto_hash.c    | 210 ++++++++++++++++
 .../selftests/bpf/progs/crypto_common.h       |   2 +
 .../testing/selftests/bpf/progs/crypto_hash.c | 231 ++++++++++++++++++
 5 files changed, 447 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/crypto_hash.c
 create mode 100644 tools/testing/selftests/bpf/progs/crypto_hash.c
MAINTAINERS +2 -0
index 4e9b369acd1c..9602b6216ab9 100644
@@ -4717,6 +4717,8 @@ F:	crypto/bpf_crypto_shash.c
 F:	crypto/bpf_crypto_skcipher.c
 F:	include/linux/bpf_crypto.h
 F:	kernel/bpf/crypto.c
+F:	tools/testing/selftests/bpf/prog_tests/crypto_hash.c
+F:	tools/testing/selftests/bpf/progs/crypto_hash.c
 
 BPF [DOCUMENTATION] (Related to Standardization)
 R:	David Vernet <[email protected]>
tools/testing/selftests/bpf/config +2 -0
index 558839e3c185..814804f71780 100644
@@ -13,6 +13,8 @@ CONFIG_BPF_SYSCALL=y
 CONFIG_CGROUP_BPF=y
 CONFIG_CRYPTO_HMAC=y
 CONFIG_CRYPTO_SHA256=y
+CONFIG_CRYPTO_SHA512=y
+CONFIG_CRYPTO_HASH2=y
 CONFIG_CRYPTO_USER_API=y
 CONFIG_CRYPTO_USER_API_HASH=y
 CONFIG_CRYPTO_USER_API_SKCIPHER=y
tools/testing/selftests/bpf/prog_tests/crypto_hash.c new file +210 -0

210 lines not on this page · raw message

tools/testing/selftests/bpf/progs/crypto_common.h +2 -0
index 57dd7a68a8c3..2f04f08f890b 100644
@@ -15,6 +15,8 @@ int bpf_crypto_encrypt(struct bpf_crypto_ctx *ctx, const struct bpf_dynptr *src,
 		       const struct bpf_dynptr *dst, const struct bpf_dynptr *iv) __ksym;
 int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx, const struct bpf_dynptr *src,
 		       const struct bpf_dynptr *dst, const struct bpf_dynptr *iv) __ksym;
+int bpf_crypto_hash(struct bpf_crypto_ctx *ctx, const struct bpf_dynptr *data,
+		    const struct bpf_dynptr *out) __ksym;
 
 struct __crypto_ctx_value {
 	struct bpf_crypto_ctx __kptr * ctx;
tools/testing/selftests/bpf/progs/crypto_hash.c new file +231 -0

231 lines not on this page · raw message

Signature · 1 line
2.52.0
#7 lore raw

PATCH v7 4/4 selftests/bpf: Add tests for signature verification kfuncs

In reply to Daniel Hodges

Add tests for the signature verification kfuncs:

1. test_ecdsa_verify_valid_signature: Verifies that a valid ECDSA signature over a known message hash is correctly verified using the P-256 curve with a test vector.

2. test_ecdsa_verify_invalid_signature: Verifies that an invalid signature (with modified r component) is correctly rejected.

3. test_ecdsa_size_queries: Tests the bpf_sig_keysize(), bpf_sig_digestsize(), and bpf_sig_maxsize() kfuncs to ensure they return valid positive values for a P-256 ECDSA context.

4. test_ecdsa_on_hash_ctx: Tests that calling bpf_sig_verify on a hash context fails with -EINVAL due to type mismatch.

5. test_ecdsa_keysize_on_hash_ctx: Tests that calling bpf_sig_keysize on a hash context fails with -EINVAL due to type mismatch.

6. test_ecdsa_zero_len_msg: Tests that zero-length message is rejected.

7. test_ecdsa_zero_len_sig: Tests that zero-length signature is rejected.

The test uses the p1363(ecdsa-nist-p256) algorithm with a known NIST P-256 test vector for reliable and reproducible testing.

---
 MAINTAINERS                                   |   2 +
 tools/testing/selftests/bpf/config            |   4 +
 .../selftests/bpf/prog_tests/sig_verify.c     | 163 ++++++++++
 .../selftests/bpf/progs/crypto_common.h       |   6 +
 .../testing/selftests/bpf/progs/sig_verify.c  | 286 ++++++++++++++++++
 5 files changed, 461 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/sig_verify.c
 create mode 100644 tools/testing/selftests/bpf/progs/sig_verify.c
MAINTAINERS +2 -0
index d23ea38b606f..e297cc18c5f6 100644
@@ -4719,7 +4719,9 @@ F:	crypto/bpf_crypto_skcipher.c
 F:	include/linux/bpf_crypto.h
 F:	kernel/bpf/crypto.c
 F:	tools/testing/selftests/bpf/prog_tests/crypto_hash.c
+F:	tools/testing/selftests/bpf/prog_tests/sig_verify.c
 F:	tools/testing/selftests/bpf/progs/crypto_hash.c
+F:	tools/testing/selftests/bpf/progs/sig_verify.c
 
 BPF [DOCUMENTATION] (Related to Standardization)
 R:	David Vernet <[email protected]>
tools/testing/selftests/bpf/config +4 -0
index 814804f71780..6db8b648cdd8 100644
@@ -21,6 +21,10 @@ CONFIG_CRYPTO_USER_API_SKCIPHER=y
 CONFIG_CRYPTO_SKCIPHER=y
 CONFIG_CRYPTO_ECB=y
 CONFIG_CRYPTO_AES=y
+CONFIG_CRYPTO_SIG=y
+CONFIG_CRYPTO_SIG2=y
+CONFIG_CRYPTO_ECDSA=y
+CONFIG_CRYPTO_ECRDSA=y
 CONFIG_DEBUG_INFO=y
 CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_DWARF4=y
tools/testing/selftests/bpf/prog_tests/sig_verify.c new file +163 -0

163 lines not on this page · raw message

tools/testing/selftests/bpf/progs/crypto_common.h +6 -0
index 2f04f08f890b..3849083f2d23 100644
@@ -17,6 +17,12 @@ int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx, const struct bpf_dynptr *src,
 		       const struct bpf_dynptr *dst, const struct bpf_dynptr *iv) __ksym;
 int bpf_crypto_hash(struct bpf_crypto_ctx *ctx, const struct bpf_dynptr *data,
 		    const struct bpf_dynptr *out) __ksym;
+int bpf_sig_verify(struct bpf_crypto_ctx *ctx,
+		     const struct bpf_dynptr *message,
+		     const struct bpf_dynptr *signature) __ksym;
+int bpf_sig_keysize(struct bpf_crypto_ctx *ctx) __ksym;
+int bpf_sig_digestsize(struct bpf_crypto_ctx *ctx) __ksym;
+int bpf_sig_maxsize(struct bpf_crypto_ctx *ctx) __ksym;
 
 struct __crypto_ctx_value {
 	struct bpf_crypto_ctx __kptr * ctx;
tools/testing/selftests/bpf/progs/sig_verify.c new file +286 -0

286 lines not on this page · raw message

Signature · 1 line
2.52.0
#4 lore raw

Re: [PATCH bpf-next v7 3/4] bpf: Add signature verification kfuncs

In reply to Daniel Hodges
The underlying crypto_sig_keysize() function in include/crypto/sig.h returns the key size in bits, not bytes:
Quoted 4 lines
kernel/bpf/crypto.c +0 -0
index bf14856ab5..b763a6c5cd 100644

[ ... ]

Quoted 6 lines

+/**
+ * bpf_sig_keysize() - Get the key size for signature context
+ * @ctx: The crypto context being used. The ctx must be a trusted pointer.
+ *
+ * Return: The key size in bytes, or negative error code on failure.
+ */

                         ^^^^^^^^

The underlying crypto_sig_keysize() function in include/crypto/sig.h returns the key size in bits, not bytes:

/**
* crypto_sig_keysize() - Get key size
*
* Function returns the key size in bits.

Should this documentation say "in bits" instead of "in bytes"?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21595105586

AI-authorship-score: low
AI-authorship-explanation: The code follows established kernel patterns and the documentation error is equally likely a human oversight.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Documentation comment states wrong units (bytes instead of bits) for bpf_sig_keysize return value, which could mislead BPF program developers.

#5 lore raw

Re: [PATCH bpf-next v7 3/4] bpf: Add signature verification kfuncs

In reply to Daniel Hodges
Quoted 26 lines · Daniel Hodges

Add a bpf_crypto_sig module that registers signature verification algorithms with the BPF crypto type system. This enables signature operations (like ECDSA) to use the unified bpf_crypto_ctx structure.

The module provides:
- alloc_tfm/free_tfm for crypto_sig transform lifecycle
- has_algo to check algorithm availability
- setkey for public key configuration
- verify for signature verification
- get_flags for crypto API flags

Introduce bpf_sig_verify, bpf_sig_keysize, bpf_sig_digestsize, and bpf_sig_maxsize kfuncs enabling BPF programs to verify digital signatures using the kernel's crypto infrastructure.

Add enum bpf_crypto_type_id for runtime type checking to ensure operations are performed on the correct crypto context type. The enum values are assigned to all crypto type modules (skcipher, hash, sig).

The verify kfunc takes a crypto context (initialized with the sig type and appropriate algorithm like "ecdsa-nist-p256"), a message digest, and a signature. These kfuncs support any signature algorithm registered with the crypto subsystem (e.g., ECDSA, RSA).

Quoted 8 lines
---
 MAINTAINERS                |   1 +
 crypto/Makefile            |   3 +
 crypto/bpf_crypto_sig.c    |  89 ++++++++++++++++++++++++++++
 include/linux/bpf_crypto.h |   4 ++
 kernel/bpf/crypto.c        | 117 +++++++++++++++++++++++++++++++++++++
 5 files changed, 214 insertions(+)
 create mode 100644 crypto/bpf_crypto_sig.c

Other than the issue spotted by AI the patches look fine, but we need Ack from crypto maintainers.

pw-bot: cr

#6 lore raw

Re: [PATCH bpf-next v7 3/4] bpf: Add signature verification kfuncs

Quoted 36 lines · Alexei Starovoitov
Quoted 26 lines · Daniel Hodges

Add a bpf_crypto_sig module that registers signature verification algorithms with the BPF crypto type system. This enables signature operations (like ECDSA) to use the unified bpf_crypto_ctx structure.

The module provides:
- alloc_tfm/free_tfm for crypto_sig transform lifecycle
- has_algo to check algorithm availability
- setkey for public key configuration
- verify for signature verification
- get_flags for crypto API flags

Introduce bpf_sig_verify, bpf_sig_keysize, bpf_sig_digestsize, and bpf_sig_maxsize kfuncs enabling BPF programs to verify digital signatures using the kernel's crypto infrastructure.

Add enum bpf_crypto_type_id for runtime type checking to ensure operations are performed on the correct crypto context type. The enum values are assigned to all crypto type modules (skcipher, hash, sig).

The verify kfunc takes a crypto context (initialized with the sig type and appropriate algorithm like "ecdsa-nist-p256"), a message digest, and a signature. These kfuncs support any signature algorithm registered with the crypto subsystem (e.g., ECDSA, RSA).

Quoted 8 lines
---
 MAINTAINERS                |   1 +
 crypto/Makefile            |   3 +
 crypto/bpf_crypto_sig.c    |  89 ++++++++++++++++++++++++++++
 include/linux/bpf_crypto.h |   4 ++
 kernel/bpf/crypto.c        | 117 +++++++++++++++++++++++++++++++++++++
 5 files changed, 214 insertions(+)
 create mode 100644 crypto/bpf_crypto_sig.c
Quoted 2 lines

Other than the issue spotted by AI the patches look fine, but we need Ack from crypto maintainers.

Sounds good, I'll wait to hear from them before sending anything else.