Skip to content

Conversation

@kernel-patches-daemon-bpf-rc
Copy link

Pull request for series with
subject: libbpf: Don't use AF_ALG for SHA-256
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1006805

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 0e8e60e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1006805
version: 1

Reimplement libbpf_sha256() using some basic SHA-256 C code.  This
eliminates the newly-added dependency on AF_ALG, which is a problematic
UAPI that is not supported by all kernels.

Make libbpf_sha256() return void, since it can no longer fail.  This
simplifies some callers.  Also drop the unnecessary 'sha_out_sz'
parameter.  Finally, also fix the typo in "compute_sha_udpate_offsets".

Tested by uncommenting the included test code and running
'make -C tools/bpf/bpftool', which causes the test to be executed.

Fixes: c297fe3 ("libbpf: Implement SHA256 internal helper")
Signed-off-by: Eric Biggers <[email protected]>
@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 15cf392
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1006805
version: 1

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 4ef77dd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1006805
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=1006805
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: libbpf: Don't use AF_ALG for SHA-256
Using index info to reconstruct a base tree...
M	tools/lib/bpf/gen_loader.c
M	tools/lib/bpf/libbpf.c
M	tools/lib/bpf/libbpf_internal.h
Falling back to patching base and 3-way merge...
Auto-merging tools/lib/bpf/libbpf.c
CONFLICT (content): Merge conflict in tools/lib/bpf/libbpf.c
Patch failed at 0001 libbpf: Don't use AF_ALG for SHA-256'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"'

conflict:

diff --cc tools/lib/bpf/libbpf.c
index f92083f51bdb,f804c7b3fa8a..000000000000
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@@ -14381,4 -14381,30 +14381,33 @@@ void libbpf_sha256(const void *data, si
  
  	for (i = 0; i < ARRAY_SIZE(state); i++)
  		put_unaligned_be32(state[i], &out[4 * i]);
++<<<<<<< HEAD
++=======
  }
+ 
+ #if 0 /* To test libbpf_sha256(), uncomment this.  Requires -lcrypto. */
+ #include <openssl/sha.h>
+ 
+ /* Test libbpf_sha256() for all lengths from 0 to 4096 bytes inclusively. */
+ static void __attribute__((constructor)) test_libbpf_sha256(void)
+ {
+ 	__u8 data[4096];
+ 	__u8 hash1[SHA256_DIGEST_LENGTH];
+ 	__u8 hash2[SHA256_DIGEST_LENGTH];
+ 	size_t i;
+ 
+ 	for (i = 0; i < sizeof(data); i++)
+ 		data[i] = rand();
+ 
+ 	for (i = 0; i <= sizeof(data); i++) {
+ 		libbpf_sha256(data, i, hash1);
+ 		SHA256(data, i, hash2); /* Uses OpenSSL */
+ 		if (memcmp(hash1, hash2, sizeof(hash1)) != 0) {
+ 			pr_warn("libbpf_sha256() test failed\n");
+ 			abort();
+ 		}
+ 	}
+ 	pr_info("libbpf_sha256() test passed\n");
++>>>>>>> libbpf: Don't use AF_ALG for SHA-256
+ }
+ #endif

@kernel-patches-daemon-bpf-rc
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1006805 irrelevant now. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant