Skip to content

netutils/dropbear: back hmac-sha2-256 with NuttX /dev/crypto#3640

Open
FelipeMdeO wants to merge 1 commit into
apache:masterfrom
FelipeMdeO:feature/dropbear-nuttx-hmac-sha256
Open

netutils/dropbear: back hmac-sha2-256 with NuttX /dev/crypto#3640
FelipeMdeO wants to merge 1 commit into
apache:masterfrom
FelipeMdeO:feature/dropbear-nuttx-hmac-sha256

Conversation

@FelipeMdeO

@FelipeMdeO FelipeMdeO commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace Dropbear's bundled libtomcrypt HMAC modules with an adapter that
computes the hmac-sha2-256 packet MAC through the NuttX crypto device
(/dev/crypto) using CRYPTO_SHA2_256_HMAC sessions: hmac_init opens the
session with the MAC key, hmac_process feeds data with COP_FLAG_UPDATE
and hmac_done reads the tag and frees the session.

The upstream Dropbear hmac_state is reused as-is, so no source patch is
needed: the existing hash field keeps the hash index and the /dev/crypto
session id is stored in the otherwise unused md buffer. The bundled
hmac_init.c/hmac_process.c/hmac_done.c are dropped from the build and
NETUTILS_DROPBEAR depends on CRYPTO_CRYPTODEV and
CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO.

Only the HMAC is offloaded, not the plain SHA-256 hash: Dropbear's key
derivation (hashkeys() in common-kex.c) memcpy-clones a
partially-updated hash_state, which a kernel crypto session cannot
represent, so the SHA-256 descriptor stays on libtomcrypt.

Impact

  • Users: none unless NETUTILS_DROPBEAR is enabled;

Testing

sim:dropbear on the NuttX simulator. Dropbear is started by NSH, a user is
created, and a host OpenSSH client connects forcing hmac-sha2-256 as the
MAC (with aes128-ctr, so the HMAC runs on every packet):

console Board side:

➜  nuttx git:(fix/dropbear-cryptodev-defconfigs) ./nuttx

dropbear [6:100]

NuttShell (NSH) NuttX-13.0.0
nsh> [6] Jun 01 00:00:00 using NuttX passwd auth at /tmp/passwd
dropbear: listening on port 2222
useradd felipe Testpass123
nsh> 
nsh> [6] Jun 01 00:01:22 connection from 192.168.15.8:47198
[6] Jun 01 00:01:30 Password auth succeeded for 'felipe' from 192.168.15.8:47198
[6] Jun 01 00:01:30 NSH PTY session started


console PC side:

➜  ~ ssh-keygen -R '[10.0.1.2]:2222'   # host key nova a cada boot do sim
ssh -p 2222 -c aes128-ctr -m hmac-sha2-256 felipe@10.0.1.2

# Host [10.0.1.2]:2222 found: line 9
/home/felipe-moura/.ssh/known_hosts updated.
Original contents retained as /home/felipe-moura/.ssh/known_hosts.old
The authenticity of host '[10.0.1.2]:2222 ([10.0.1.2]:2222)' can't be established.
ECDSA key fingerprint is <*************>
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[10.0.1.2]:2222' (ECDSA) to the list of known hosts.
felipe@10.0.1.2's password: 
nsh> ls
/:
 bin/
 dev/
 etc/
 proc/
 tmp/
 var/
nsh> ps
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069584 Idle_Task
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067456 sim_loop_wq 0x7879368003f0 0x787936800470
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 hpwork 0x40109020 0x401090a0
    3     0     0 100 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 lpwork 0x401090e0 0x40109160
    5     5     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 nsh_main
    6     6     5 100 FIFO     Task      - Ready              0000000000000000 0130984 dropbear
    7     7     6 100 FIFO     Task      - Running            0000000000000000 0073648 dropbear_nsh
    8     6     5 100 FIFO     pthread   - Waiting  Signal    0000000000000000 0067528 dropbear 0x40095843 0x7879369398b0
nsh> 

Test using STM32F7 DISCO:

Board Side:

nsh: �: command not found
nsh> ls /data
/data:
 .
 ..
 dropbear_ecdsa_host_key
 passwd
nsh> [4] Jan 14 00:00:18 connection from 192.168.15.8:45388
[4] Jan 14 00:00:24 passwd_verify failed for 'felipe': -14
[4] Jan 14 00:00:24 Bad password attempt for 'felipe' from 192.168.15.8:45388
[4] Jan 14 00:00:32 Password auth succeeded for 'felipe' from 192.168.15.8:45388
[4] Jan 14 00:00:32 NSH PTY session started
[4] Jan 14 00:01:57 Exit (felipe) from <192.168.15.8:45388>: Disconnect received

PC side:

➜  ~ ssh -p 2222 -c aes128-ctr -m hmac-sha2-256 felipe@192.168.15.155

felipe@192.168.15.155's password: 
Permission denied, please try again.
felipe@192.168.15.155's password: 
nsh> ls
/:
 data/
 dev/
 proc/
 var/
nsh> exit
Connection to 192.168.15.155 closed.
➜  ~ 

@FelipeMdeO
FelipeMdeO force-pushed the feature/dropbear-nuttx-hmac-sha256 branch from d3a0507 to 2e1eef2 Compare July 20, 2026 21:20
@FelipeMdeO
FelipeMdeO marked this pull request as ready for review July 20, 2026 21:20
Replace the bundled libtomcrypt HMAC modules with an adapter that
computes the hmac-sha2-256 packet MAC through the NuttX crypto device
using CRYPTO_SHA2_256_HMAC sessions.

NETUTILS_DROPBEAR depends
on CRYPTO_CRYPTODEV and CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO instead of
selecting them.

Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
@FelipeMdeO
FelipeMdeO force-pushed the feature/dropbear-nuttx-hmac-sha256 branch from 2e1eef2 to 52b0fdc Compare July 21, 2026 11:10
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