Skip to contentSkip to conversation

Bluetooth: Use AES-CMAC library API

PATCH In review Eric Biggers 3 participants 7 messages Apr 21 – Apr 23

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

v2 cover Bluetooth: Use AES-CMAC library API

This series removes unnecessary kconfig selections from CONFIG_BT, then converts net/bluetooth/smp.c to use the AES-CMAC library API (which was introduced in 7.1) instead of the crypto_shash API. This makes the code simpler and more efficient.

This series is intended to be taken through the bluetooth tree and can be applied for either 7.1 or 7.2, depending on maintainer preference.

These patches were originally sent as
https://lore.kernel.org/r/[email protected] and
https://lore.kernel.org/r/[email protected]/

Eric Biggers (2):
Bluetooth: Remove unneeded crypto kconfig selections
Bluetooth: SMP: Use AES-CMAC library API

 net/bluetooth/Kconfig |   6 +-
 net/bluetooth/smp.c   | 180 +++++++++++++++---------------------------
 2 files changed, 65 insertions(+), 121 deletions(-)

base-commit: d46dd0d88341e45f8e0226fdef5462f5270898fc

Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/2 Bluetooth: Remove unneeded crypto kconfig selections

Remove several kconfig selections that are no longer needed:

- CRYPTO_SKCIPHER and CRYPTO_ECB have been unneeded since

    commit a4770e1117f1 ("Bluetooth: Switch SMP to
    crypto_cipher_encrypt_one()") in 2016.

- CRYPTO_SHA256 has been unneeded since

    commit e7b02296fb40 ("Bluetooth: Remove BT_HS") in 2024.
---
 net/bluetooth/Kconfig | 3 ---
 1 file changed, 3 deletions(-)
net/bluetooth/Kconfig +0 -3
index 6b2b65a66700..8bd0f2891161 100644
@@ -7,16 +7,13 @@ menuconfig BT
 	tristate "Bluetooth subsystem support"
 	depends on !S390
 	depends on RFKILL || !RFKILL
 	select CRC16
 	select CRYPTO
-	select CRYPTO_SKCIPHER
 	select CRYPTO_LIB_AES
 	imply CRYPTO_AES
 	select CRYPTO_CMAC
-	select CRYPTO_ECB
-	select CRYPTO_SHA256
 	select CRYPTO_ECDH
 	help
 	  Bluetooth is low-cost, low-power, short-range wireless technology.
 	  It was designed as a replacement for cables and other short-range
 	  technologies like IrDA.  Bluetooth operates in personal area range
Signature · 1 line
2.53.0
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1084071

---Test result---

Test Summary:

CheckPatch                    PASS      1.56 seconds
GitLint                       PASS      0.49 seconds
SubjectPrefix                 PASS      0.17 seconds
BuildKernel                   FAIL      20.93 seconds
CheckAllWarning               FAIL      23.01 seconds
CheckSparse                   FAIL      22.09 seconds
BuildKernel32                 FAIL      20.31 seconds
TestRunnerSetup               FAIL      488.99 seconds
TestRunner_l2cap-tester       FAIL      0.11 seconds
TestRunner_iso-tester         FAIL      0.11 seconds
TestRunner_bnep-tester        FAIL      0.53 seconds
TestRunner_mgmt-tester        FAIL      0.11 seconds
TestRunner_rfcomm-tester      FAIL      0.11 seconds
TestRunner_sco-tester         FAIL      0.11 seconds
TestRunner_ioctl-tester       FAIL      0.11 seconds
TestRunner_mesh-tester        FAIL      0.11 seconds
TestRunner_smp-tester         FAIL      0.10 seconds
TestRunner_userchan-tester    FAIL      0.10 seconds
TestRunner_6lowpan-tester     FAIL      0.11 seconds
IncrementalBuild              FAIL      26.35 seconds

Details
##############################
Test: BuildKernel - FAIL
Desc: Build Kernel for Bluetooth
Output:

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[4]: *** [scripts/Makefile.build:289: net/bluetooth/smp.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:548: net/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:548: net] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2105: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
##############################
Test: CheckAllWarning - FAIL
Desc: Run linux kernel with all warning enabled
Output:

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[4]: *** [scripts/Makefile.build:289: net/bluetooth/smp.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:548: net/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:548: net] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2105: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
##############################
Test: CheckSparse - FAIL
Desc: Run sparse tool with linux kernel
Output:

/github/workspace/src/src/Makefile:1208: C=1 specified, but sparse is not available or not up to date /github/workspace/src/src/Makefile:1208: C=1 specified, but sparse is not available or not up to date net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[4]: *** [scripts/Makefile.build:289: net/bluetooth/smp.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:548: net/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:548: net] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2105: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
##############################
Test: BuildKernel32 - FAIL
Desc: Build 32bit Kernel for Bluetooth
Output:

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[4]: *** [scripts/Makefile.build:289: net/bluetooth/smp.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:548: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:548: net] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2105: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
##############################
Test: TestRunnerSetup - FAIL
Desc: Setup kernel and bluez for test-runner
Output:
Kernel:
net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[4]: *** [scripts/Makefile.build:289: net/bluetooth/smp.o] Error 1 make[3]: *** [scripts/Makefile.build:548: net/bluetooth] Error 2 make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:548: net] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2105: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_bnep-tester - FAIL
Desc: Run bnep-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_rfcomm-tester - FAIL
Desc: Run rfcomm-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_ioctl-tester - FAIL
Desc: Run ioctl-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_smp-tester - FAIL
Desc: Run smp-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_userchan-tester - FAIL
Desc: Run userchan-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: TestRunner_6lowpan-tester - FAIL
Desc: Run 6lowpan-tester with test-runner
Output:

Could not access KVM kernel module: No such file or directory
qemu-system-x86_64: failed to initialize KVM: No such file or directory
qemu-system-x86_64: Back to tcg accelerator
qemu: could not open kernel file '/github/workspace/src/src/arch/x86/boot/bzImage': No such file or directory
##############################
Test: IncrementalBuild - FAIL
Desc: Incremental build with the patches in the series
Output:

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[4]: *** [scripts/Makefile.build:289: net/bluetooth/smp.o] Error 1 make[3]: *** [scripts/Makefile.build:548: net/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:548: net] Error 2 make[1]: *** [/github/workspace/src/src/Makefile:2105: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
[v2,2/2] Bluetooth: SMP: Use AES-CMAC library API

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[4]: *** [scripts/Makefile.build:289: net/bluetooth/smp.o] Error 1 make[3]: *** [scripts/Makefile.build:548: net/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:548: net] Error 2 make[1]: *** [/github/workspace/src/src/Makefile:2105: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2

https://github.com/bluez/bluetooth-next/pull/114

---
Regards,
Linux Bluetooth

#3 lore raw

Hi Eric,

Quoted 39 lines · On Tue, Apr 21, 2026 at 8:10 PM <[email protected]> wrote:

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1084071

---Test result---

Test Summary:

CheckPatch                    PASS      1.56 seconds
GitLint                       PASS      0.49 seconds
SubjectPrefix                 PASS      0.17 seconds
BuildKernel                   FAIL      20.93 seconds
CheckAllWarning               FAIL      23.01 seconds
CheckSparse                   FAIL      22.09 seconds
BuildKernel32                 FAIL      20.31 seconds
TestRunnerSetup               FAIL      488.99 seconds
TestRunner_l2cap-tester       FAIL      0.11 seconds
TestRunner_iso-tester         FAIL      0.11 seconds
TestRunner_bnep-tester        FAIL      0.53 seconds
TestRunner_mgmt-tester        FAIL      0.11 seconds
TestRunner_rfcomm-tester      FAIL      0.11 seconds
TestRunner_sco-tester         FAIL      0.11 seconds
TestRunner_ioctl-tester       FAIL      0.11 seconds
TestRunner_mesh-tester        FAIL      0.11 seconds
TestRunner_smp-tester         FAIL      0.10 seconds
TestRunner_userchan-tester    FAIL      0.10 seconds
TestRunner_6lowpan-tester     FAIL      0.11 seconds
IncrementalBuild              FAIL      26.35 seconds

Details
##############################
Test: BuildKernel - FAIL
Desc: Build Kernel for Bluetooth
Output:

Quoted 3 lines

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

I guess this is expected since rc1 wasn't tagged yet, right? In that case we will probably need to rebase once rc1 is tagged to integrate these changes.

#4 lore raw
Quoted 7 lines · Luiz Augusto von Dentz
Quoted 3 lines

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~

I guess this is expected since rc1 wasn't tagged yet, right? In that case we will probably need to rebase once rc1 is tagged to integrate these changes.

Well, the bluez.test.bot seems to have ignored the "base-commit: d46dd0d88341e45f8e0226fdef5462f5270898fc" and applied the series to something a bit older. In that case, yes this is expected. Once the bluetooth branch has been updated to v7.1-rc1 or another commit that has the prerequisite, this can be applied. Thanks,

- Eric

#5 lore raw

Hi Eric,

Quoted 6 lines · Eric Biggers
Quoted 4 lines · Luiz Augusto von Dentz
Quoted 3 lines

net/bluetooth/smp.c:25:10: fatal error: crypto/aes-cbc-macs.h: No such file or directory
25 | #include <crypto/aes-cbc-macs.h>

      |          ^~~~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines
Quoted 3 lines

I guess this is expected since rc1 wasn't tagged yet, right? In that case we will probably need to rebase once rc1 is tagged to integrate these changes.

Well, the bluez.test.bot seems to have ignored the "base-commit: d46dd0d88341e45f8e0226fdef5462f5270898fc" and applied the series to something a bit older. In that case, yes this is expected.

I don't see that on pw:
https://patchwork.kernel.org/project/bluetooth/list/?series=1084071,
and even if we did support passing a base-commit that could create other problems since the test cases (which comes from BlueZ userspace) are only meant to be stable against trees other than bluetooth-next so we might be able to build but fail test cases that were recently introduced.

Quoted 2 lines

Once the bluetooth branch has been updated to v7.1-rc1 or another commit that has the prerequisite, this can be applied. Thanks,

Ok, I think we are still in the merging window so tagging RC1 will probably need a week or more.

Signature · 1 line
Luiz Augusto von Dentz
#6 lore raw

PATCH v2 2/2 Bluetooth: SMP: Use AES-CMAC library API

In reply to Eric Biggers

Now that AES-CMAC has a library API, convert net/bluetooth/smp.c to use it instead of the "cmac(aes)" crypto_shash. Since the library API doesn't require dynamic memory allocation, we no longer need to pass a crypto_shash object down the call stack and can simply allocate the aes_cmac_key on the stack in smp_aes_cmac() (renamed from aes_cmac()).

The result is simpler and faster code that no longer relies on the error-prone loading of algorithms by name.

Note that the maximum stack usage actually decreases slightly, despite the expanded AES key being moved to the stack. This is because the old code called crypto_shash_tfm_digest(), which allocates 384 bytes on the stack for a maximally-sized hash descriptor for any algorithm. The new code instead declares a 288-byte aes_cmac_key, then calls aes_cmac() which declares a 32-byte aes_cmac_ctx. Since 288 + 32 < 384, the maximum stack usage decreases. I.e. the entire expanded AES key easily fits in the space that the generic crypto API was wasting before.

I didn't add zeroization of the aes_cmac_key, since smp_aes_cmac() already copies the raw key to the stack without zeroizing it.

---
 net/bluetooth/Kconfig |   3 +-
 net/bluetooth/smp.c   | 180 +++++++++++++++---------------------------
 2 files changed, 65 insertions(+), 118 deletions(-)
net/bluetooth/Kconfig +1 -2
index 8bd0f2891161..884356938d74 100644
@@ -8,12 +8,11 @@ menuconfig BT
 	depends on !S390
 	depends on RFKILL || !RFKILL
 	select CRC16
 	select CRYPTO
 	select CRYPTO_LIB_AES
-	imply CRYPTO_AES
-	select CRYPTO_CMAC
+	select CRYPTO_LIB_AES_CBC_MACS
 	select CRYPTO_ECDH
 	help
 	  Bluetooth is low-cost, low-power, short-range wireless technology.
 	  It was designed as a replacement for cables and other short-range
 	  technologies like IrDA.  Bluetooth operates in personal area range
net/bluetooth/smp.c +64 -116

739 lines not on this page · raw message

Signature · 1 line
2.53.0