You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "PruteanuVlad (via GitHub)" <gi...@apache.org> on 2026/03/25 22:47:17 UTC
[PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
PruteanuVlad opened a new pull request, #18608:
URL: https://github.com/apache/nuttx/pull/18608
## Summary
This adds support for PBKDF2 (SHA1 and SHA256) while leveraging the existing infrastructure for HMAC.
I tried to take advantage of the existing HMAC code as much as possible.
Test app has been added in this PR: https://github.com/apache/nuttx-apps/pull/3437
## Modified files:
boards/xtensa/esp32/esp32-devkitc/configs/crypto/defconfig - enables the test app
crypto/cryptodev.c - treats the new PBKDF2 cases and handles new struct field
crypto/cryptosoft.c - handles the actual algorithm implementation
include/crypto/cryptodev.h - new defines for pbkdf2
## Impact
This allows users to derive keys using PBKDF2.
##Testing
Development was done using ESP32 DevkitC.
Building was done on Ubuntu 24.04 VM.
For testing, I ran the PBKDF2 test from the PR mentioned above.
```
nsh> pbkdf2
hmac PBKDF2 SHA1 success
hmac PBKDF2 SHA1 success
hmac PBKDF2 SHA1 success
hmac PBKDF2 SHA1 success
hmac PBKDF2 SHA1 success
hmac PBKDF2 SHA1 success
hmac PBKDF2 SHA256 success
hmac PBKDF2 SHA256 success
hmac PBKDF2 SHA256 success
hmac PBKDF2 SHA256 success
hmac PBKDF2 SHA256 success
hmac PBKDF2 SHA256 success
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "ThePassionate (via GitHub)" <gi...@apache.org>.
ThePassionate commented on code in PR #18608:
URL: https://github.com/apache/nuttx/pull/18608#discussion_r2992737945
##########
include/crypto/cryptodev.h:
##########
@@ -408,6 +411,8 @@ struct crypt_op
*/
uint16_t flags;
+ uint32_t iterations;
+ unsigned targetlen;
Review Comment:
remove unused param
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "PruteanuVlad (via GitHub)" <gi...@apache.org>.
PruteanuVlad commented on PR #18608:
URL: https://github.com/apache/nuttx/pull/18608#issuecomment-4138435019
Thanks for the review 😄
I went through a few revisions so there were some missed leftovers, but I cleaned it up now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "PruteanuVlad (via GitHub)" <gi...@apache.org>.
PruteanuVlad commented on code in PR #18608:
URL: https://github.com/apache/nuttx/pull/18608#discussion_r3003439191
##########
boards/xtensa/esp32/esp32-devkitc/configs/crypto/defconfig:
##########
@@ -44,6 +44,7 @@ CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
+CONFIG_TESTING_CRYPTO_PBKDF2=y
Review Comment:
My bad, this shouldn't even be included since this defconfig is for hardware-backed crypto. PBKDF2 isn't supported yet (I'll add it in a future PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on code in PR #18608:
URL: https://github.com/apache/nuttx/pull/18608#discussion_r3000443215
##########
boards/xtensa/esp32/esp32-devkitc/configs/crypto/defconfig:
##########
@@ -44,6 +44,7 @@ CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
+CONFIG_TESTING_CRYPTO_PBKDF2=y
Review Comment:
@xiaoxiang781216 good finding!
@PruteanuVlad defconfig files shouldn't be manually edited, please read the header info
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #18608:
URL: https://github.com/apache/nuttx/pull/18608#issuecomment-4133314774
Hi @PruteanuVlad please fix
```
====================================================================================
Configuration/Tool: sim/crypto
2026-03-25 22:54:34
------------------------------------------------------------------------------------
Cleaning...
Configuring...
Building NuttX...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 36922 0 36922 0 0 51101 0 --:--:-- --:--:-- --:--:-- 51101
100 143k 0 143k 0 0 192k 0 --:--:-- --:--:-- --:--:-- 560k
100 5740k 0 5740k 0 0 4058k 0 --:--:-- 0:00:01 --:--:-- 8255k
cryptosoft.c: In function 'swcr_process':
Error: cryptosoft.c:2057:13: error: implicit declaration of function 'swcr_pbkdf2' [-Werror=implicit-function-declaration]
2057 | swcr_pbkdf2(crp, crd, sw, crp->crp_buf);
| ^~~~~~~~~~~
cryptosoft.c: In function 'swcr_pbkdf2':
Error: cryptosoft.c:2119:21: error: pointer targets in assignment from 'uint8_t *' {aka 'unsigned char *'} to 'caddr_t' {aka 'char *'} differ in signedness [-Werror=pointer-sign]
2119 | crp_dummy.crp_mac = macbuf;
| ^
Error: cryptosoft.c:2126:48: error: implicit declaration of function 'htonl' [-Werror=implicit-function-declaration]
2126 | *(uint32_t *)(saltblk + crp->crp_ilen) = htonl(blocknum);
| ^~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:98: cryptosoft.o] Error 1
make[1]: Target 'libcrypto.a' not remade because of errors.
make: *** [tools/LibTargets.mk:95: crypto/libcrypto.a] Error 2
make: Target 'all' not remade because of errors.
/github/workspace/sources/nuttx/tools/testbuild.sh: line 385: /github/workspace/sources/nuttx/../nuttx/nuttx.manifest: No such file or directory
[1/1] Normalize sim/crypto
====================================================================================
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "ThePassionate (via GitHub)" <gi...@apache.org>.
ThePassionate commented on PR #18608:
URL: https://github.com/apache/nuttx/pull/18608#issuecomment-4132006968
Hi, thanks for adding PBKDF2 support — this is a useful addition to the crypto stack! I have a few suggestions below, mostly around cleanup.
1. swcr_freesession: missing PBKDF2 — memory leak
swcr_freesession() does not handle CRYPTO_PBKDF2_HMAC_SHA1 / CRYPTO_PBKDF2_HMAC_SHA256. These algorithms go through the authcommon path in swcr_newsession(), which allocates both sw_ictx and sw_octx. Without corresponding cases in swcr_freesession(), neither buffer is freed on session teardown — this is a memory leak.
2. **targetlen** added to struct crypt_op but never referenced
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #18608:
URL: https://github.com/apache/nuttx/pull/18608
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] crypto/cryptosoft: Add support for PBKDF2 [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18608:
URL: https://github.com/apache/nuttx/pull/18608#discussion_r2998556787
##########
crypto/cryptosoft.c:
##########
@@ -2090,6 +2101,71 @@ int swcr_process(struct cryptop *crp)
return 0;
}
+int swcr_pbkdf2(FAR struct cryptop *crp,
+ FAR struct cryptodesc *crd,
+ FAR struct swcr_data *swd,
+ caddr_t buf)
+{
+ uint8_t U[64];
+ uint8_t T[64];
+ uint8_t macbuf[64];
+ uint8_t ictx[256];
+ struct cryptop crp_dummy;
+ struct cryptodesc crd_dummy;
+
+ size_t generated = 0;
+ uint32_t blocknum;
+ uint32_t i;
+ uint32_t j;
+
+ crp_dummy.crp_mac = (caddr_t)macbuf;
+
+ for (blocknum = 1; generated < crp->crp_olen; blocknum++)
+ {
+ uint8_t saltblk[crp->crp_ilen + 4];
+
+ memcpy(saltblk, crp->crp_buf, crp->crp_ilen);
+ *(uint32_t *)(saltblk + crp->crp_ilen) = htobe32(blocknum);
Review Comment:
```suggestion
*(FAR uint32_t *)(saltblk + crp->crp_ilen) = htobe32(blocknum);
```
##########
crypto/cryptosoft.c:
##########
@@ -2090,6 +2101,71 @@ int swcr_process(struct cryptop *crp)
return 0;
}
+int swcr_pbkdf2(FAR struct cryptop *crp,
+ FAR struct cryptodesc *crd,
+ FAR struct swcr_data *swd,
+ caddr_t buf)
+{
+ uint8_t U[64];
+ uint8_t T[64];
+ uint8_t macbuf[64];
+ uint8_t ictx[256];
+ struct cryptop crp_dummy;
+ struct cryptodesc crd_dummy;
+
+ size_t generated = 0;
+ uint32_t blocknum;
+ uint32_t i;
+ uint32_t j;
+
+ crp_dummy.crp_mac = (caddr_t)macbuf;
+
+ for (blocknum = 1; generated < crp->crp_olen; blocknum++)
+ {
+ uint8_t saltblk[crp->crp_ilen + 4];
+
+ memcpy(saltblk, crp->crp_buf, crp->crp_ilen);
+ *(uint32_t *)(saltblk + crp->crp_ilen) = htobe32(blocknum);
+
+ memcpy(ictx, swd->sw_ictx, swd->sw_axf->ctxsize);
+ memcpy(&swd->sw_ctx, ictx, swd->sw_axf->ctxsize);
+
+ crd_dummy.crd_skip = 0;
+ crd_dummy.crd_flags = 0;
+
+ /* U1 */
+
+ crd_dummy.crd_len = crp->crp_ilen + 4;
+ swcr_authcompute(&crp_dummy, &crd_dummy, swd, (caddr_t)saltblk);
+
+ memcpy(U, macbuf, swd->sw_axf->hashsize);
+ memcpy(T, U, swd->sw_axf->hashsize);
+
+ /* U2..Uc */
+
+ for (i = 1; i < crp->crp_iter; i++)
+ {
+ memcpy(&swd->sw_ctx, ictx, swd->sw_axf->ctxsize);
+
+ crd_dummy.crd_len = swd->sw_axf->hashsize;
+ swcr_authcompute(&crp_dummy, &crd_dummy, swd, (caddr_t)U);
+
+ memcpy(U, macbuf, swd->sw_axf->hashsize);
+
+ for (j = 0; j < swd->sw_axf->hashsize; j++)
+ T[j] ^= U[j];
Review Comment:
add {}
##########
boards/xtensa/esp32/esp32-devkitc/configs/crypto/defconfig:
##########
@@ -44,6 +44,7 @@ CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
+CONFIG_TESTING_CRYPTO_PBKDF2=y
Review Comment:
need keep the order
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org