178 Commits

Author SHA1 Message Date
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.

A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
karaketir16 b843d9192e crypto: decouple curve25519 and idgen from random pool
This commit modularizes the curve25519 and idgen implementations in the
crypto subsystem.

Previously, curve25519.c and idgen.c were only compiled when
CONFIG_CRYPTO_RANDOM_POOL was enabled. However, cryptosoft.c (used by
software cipher support) has a direct dependency on curve25519 functions.
This caused linker errors (undefined reference to curve25519) when
software crypto was enabled but the random pool was disabled.

Changes:
- Introduce hidden Kconfig options CRYPTO_CURVE25519 and CRYPTO_IDGEN.
- Make CRYPTO_RANDOM_POOL select both CRYPTO_IDGEN and CRYPTO_CURVE25519.
- Make CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO/KEYMGMT select CRYPTO_CURVE25519.
- Update CMakeLists.txt and Makefile to use the new config flags.

This ensures that required algorithms are automatically included in the
build regardless of whether the entropy pool is enabled.

Signed-off-by: karaketir16 <osmankaraketir@gmail.com>
2026-04-07 09:33:34 +08:00
Vlad Pruteanu 3039184806 crypto/cryptosoft: Add support for PBKDF2
This adds support for PBKDF2 (SHA1 and SHA256) while leveraging
the existing infrastructure for HMAC.

Signed-off-by: Vlad Pruteanu <pruteanuvlad1611@yahoo.com>
2026-03-29 17:23:03 -03:00
SPRESENSE 72b67832ea Makefile: Remove make depend files by make distclean
Intermediate files of make depend like .ddc and .dds may remain
when make is interrupted. Remove them using make distclean.

Signed-off-by: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com>
2026-02-16 16:27:57 +01:00
Vlad Pruteanu 17393df52a crypto/cryptosoft: Fix HMAC-SHA when a long key is used
When using a key that is longer than the block size of the hashing
algorithm used, the key must be hashed before it is used.

Signed-off-by: Vlad Pruteanu <pruteanuvlad1611@yahoo.com>
2026-01-28 13:14:05 -03:00
makejian b663bfed8e crypto/keymgmt: return actual length if key exported successfully
When a key is successfully exported, the return value should reflect the actual length of the exported key data.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-28 11:52:12 +08:00
makejian 3271427959 crypto/swkey: support generating ECC P-256 keys
Add support for generating ECC secp256r1 (P-256) key pairs using the software key management backend.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-28 11:52:12 +08:00
makejian 17b7c77d3a crypto/swkey: support generating AES keys
Add support for generating AES keys (128/192/256 bits) using the software key management backend.

The generated keys are random numbers produced by the system PRNG.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-28 11:52:12 +08:00
makejian c8145313ae crypto: support software key management based on MTD
This patch adds support for managing cryptographic keys using MTD storage.

It enables the persistence of keys across reboots using a software-based key management system.

Includes fixes for compilation warnings and validation logic.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-28 11:52:12 +08:00
makejian eea0f45e04 crypto: remove release process in close
The callback parameters are currently passed in by the upper layer, so the release process in close should not be performed here.

This prevents double-free issues and ensures proper resource management.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-27 19:30:14 +08:00
makejian 3b151ae44b crypto/cryptodev: fix async callback
Fix incorrect memory management for asynchronous process callbacks.

Ensure callback memory is self-managed to prevent leaks or use-after-free issues.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-27 19:30:14 +08:00
makejian 791e223001 crypto/cryptosoft: fix buffer pointer
Fix issue where input buffer pointer was modified during crypto operations.

Ensures original buffer pointer remains valid for the caller.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-27 19:30:14 +08:00
makejian 2878fa3c38 crypto: export rsa with pkcs1.5 and pss mode
Add support for exporting RSA operations with PKCS#1 v1.5 and PSS padding schemes through the cryptodev interface.

This enables both traditional and modern RSA signature schemes:
- CRK_RSA_PKCS15_SIGN/VERIFY for PKCS#1 v1.5 padding
- CRK_RSA_PSS_SIGN/VERIFY for PSS padding

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-27 19:30:14 +08:00
makejian 85ba80a90e crypto/ecc: add SPDX license identifier
Add BSD-2-Clause SPDX license identifier to ECC source and header files.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-26 10:55:57 +08:00
makejian 79863bb140 crypto/ecc: fix static check in using uninitilized params
1. p.x uninitialized in line 1643
2. l_public.y uninitialized in line 1579
3. l_public.y uninitialized in line 1533
Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-26 10:55:57 +08:00
makejian e2a7656eee crypto/ecc: fix warning in tasing compile
typedef uint redefined and uint hash been defined in sys/types.h

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-26 10:55:57 +08:00
makejian c6d1bed4d1 cryptosoft: support ecdsa cmd in software
Add ECDSA sign and verify operations support in cryptosoft backend.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-26 10:55:57 +08:00
makejian be2e72dac2 crypto/ecc: supports exporting generated keys in uncompressed form
Export public keys as separate X and Y coordinates for uncompressed format.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-26 10:55:57 +08:00
makejian 3f0cc5f09c crypto: export algorithm about ecc
Transplanting the ECC algorithm from https://github.com/jestan/easy-ecc

which is BSD lisence

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-26 10:55:57 +08:00
makejian 5b52a32f5a crypto/crypto.c: Determine the order of obtained crypto drivers
After adding the cross-core crypto driver, there are now three encryption modes:
1. Hardware driver in local core
2. Crypto driver in remote core
3. Software encryption in local core

This prioritizes local hardware driver first, then remote driver (typically hardware),
and finally local software encryption as a fallback.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-21 00:25:07 +08:00
makejian e23dd613c9 crypto/cryptodev: optimize without dynamic memory in crypto process
Replace dynamic memory allocation with stack-based variables in cryptodev_op().
This eliminates kmm_malloc/kmm_free overhead and simplifies error handling
by removing the need for goto bail cleanup paths.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-21 00:25:07 +08:00
makejian 66f9329839 crypto/cryptodev: export ivlen to support different cipher algs
Add ivlen field to crypt_op and crp_ivlen to cryptop structure to support
cipher algorithms with different IV lengths.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-21 00:25:07 +08:00
makejian 143547128b crypto/cryptodev: add encrypt op and olen for support virtio mode
Add olen field to crypt_op structure and crp_olen to cryptop structure
to support output length tracking in virtio crypto mode.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-21 00:25:07 +08:00
makejian cdfe81ff4c crypto/siphash: avoid redefine name issue
Rename siphash related symbols to avoid conflicts with compiler-generated
section names. Tricore-gcc produces function sections with '_end' suffix,
which conflicts with siphash_end symbol.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-19 23:25:37 +08:00
makejian d15081838b crypto/cryptodev: support private data in driver
Add support for storing driver-specific private data in the crypto
driver structure. This allows crypto drivers to maintain session
state and other driver-specific information.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-19 14:17:38 +08:00
makejian 043ef0dd3a crypto/cryptosoft: replace macro howmany with common macro div_round_up
Replace the non-standard howmany macro with the common div_round_up macro
for consistency and better code maintainability.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-19 14:16:00 +08:00
makejian b11901ffaf crypto: add key management and RSA/ECDSA keypair generation
Add key management interfaces and support for generating key pairs in RSA and ECDSA cryptographic processes to the cryptodev module.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-17 11:41:23 +08:00
makejian a55119ccfe crypto/cryptodev: fix memory leak when failed to open /dev/crypto
Free the allocated fcrypt structure when opening /dev/crypto device fails, preventing memory leak.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-16 20:31:43 +08:00
makejian 539c8f4ab2 crypto: add support for AES-CBC with 192/256-bit key sizes
Extend AES-CBC algorithm support to include 192-bit and 256-bit key sizes in addition to the existing 128-bit support. This enables broader compatibility with cryptographic standards and provides applications with additional key length options for enhanced security requirements.

Signed-off-by: makejian <makejian@xiaomi.com>
2026-01-15 16:11:19 -03:00
Alin Jerpelea 4a069358b6 LICENSE: update NuttX-PublicDomain SPDX identifier
Build Documentation / build-html (push) Has been cancelled
According to the feedback from SPDX community we should use
LicenseRef-NuttX-PublicDomain because NuttX-PublicDomain
is not a valid SPDX id, so it will fail tests for SPDX spec compliance.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2025-12-26 19:46:12 +08:00
Niccolò Maggioni 83dd57a488 crypto/hmac: Fix typo in function implementation names
"hmac" was mistyped as "hmca", breaking linking to some prototype
functions. Also, a couple of includes were missing.

Signed-off-by: Niccolò Maggioni <nicco.maggioni+nuttx@gmail.com>
2025-08-13 23:11:02 +08:00
makejian ac54fe8875 crypto/cryptosoft: fix aadlen used uninitialized warning
Signed-off-by: makejian <makejian@xiaomi.com>
2025-07-25 08:59:53 -03:00
Ville Juven b8e30b54ec fs/vfs: Separate file descriptors from file descriptions
This patch is a rework of the NuttX file descriptor implementation. The
goal is two-fold:

1. Improve POSIX compliance. The old implementation tied file description
to inode only, not the file struct. POSIX however dictates otherwise.
2. Fix a bug with descriptor duplication (dup2() and dup3()). There is
an existing race condition with this POSIX API that currently results
in a kernel side crash.

The crash occurs when a partially open / closed file descriptor is
duplicated. The reason for the crash is that even if the descriptor is
closed, the file might still be in use by the kernel (due to e.g. ongoing
write to file). The open file data is changed by file_dup3() and this
causes a crash in the device / drivers themselves as they lose access to
the inode and private data.

The fix is done by separating struct file into file and file descriptor
structs. The file struct can live on even if the descriptor is closed,
fixing the crash. This also fixes the POSIX issue, as two descriptors
can now point to the same file.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
raiden00pl 6d6d965700 crypto: unify Private Types banners
unify Private Types banners according to NuttX coding standard

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-05-28 10:17:15 +08:00
Lars Kruse 3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Alin Jerpelea d700641921 crypto/xform.c: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

NOTE
The code was reported as GPL by FOSS ID
and Xiaomi scanned the file xform.c with Black Duck Security and it showed
that the license was BSD-3-Clause and no risk was reported.

Since there is no clause on the license it was concluded as 0BSD

Refference
https://github.com/apache/nuttx/pull/15252

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-19 14:48:18 +08:00
Alin Jerpelea 6e92920464 crypto/sha1: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

define NuttX local NuttX-PublicDomain identifier

 “Public Domain” is a concept distinct from copyright licensing;
it generally means that the work no longer has any copyright protection
or ownership, and therefore requires no license permission in order to
use, copy, modify, distribute, perform, display, etc.
In the United States – and many jurisdictions – copyright protections
attach automatically to creative works upon creation if they satisfy
certain minimum criteria.
“Public Domain” would thus represent a significant change to the legal
status of the work.
The rules around “Public Domain” often vary or are unspecified
jurisdiction to jurisdiction. Adding to the confusion, some
jurisdictions may not even recognize the concept of “Public Domain”
(or similar). As such, a license may nevertheless be required or implied
in these cases. Even in the U.S., there is no clear,
officially-sanctioned procedure for affirmatively placing
copyright-eligible works into the “Public Domain” aside from natural
statutory expiration of copyright. The bottom-line is, there are few if
any objective, brightline rules for proactively placing
copyright-eligible works into the Public Domain that we can broadly
rely on.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-16 14:18:35 +08:00
Alin Jerpelea 1ee8fdbad0 crypto/rijndael: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

define NuttX local NuttX-PublicDomain identifier

 “Public Domain” is a concept distinct from copyright licensing;
it generally means that the work no longer has any copyright protection
or ownership, and therefore requires no license permission in order to
use, copy, modify, distribute, perform, display, etc.
In the United States – and many jurisdictions – copyright protections
attach automatically to creative works upon creation if they satisfy
certain minimum criteria.
“Public Domain” would thus represent a significant change to the legal
status of the work.
The rules around “Public Domain” often vary or are unspecified
jurisdiction to jurisdiction. Adding to the confusion, some
jurisdictions may not even recognize the concept of “Public Domain”
(or similar). As such, a license may nevertheless be required or implied
in these cases. Even in the U.S., there is no clear,
officially-sanctioned procedure for affirmatively placing
copyright-eligible works into the “Public Domain” aside from natural
statutory expiration of copyright. The bottom-line is, there are few if
any objective, brightline rules for proactively placing
copyright-eligible works into the Public Domain that we can broadly
rely on.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-16 14:18:35 +08:00
Alin Jerpelea c3a044b548 crypto/poly1305: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

define NuttX local NuttX-PublicDomain identifier

 “Public Domain” is a concept distinct from copyright licensing;
it generally means that the work no longer has any copyright protection
or ownership, and therefore requires no license permission in order to
use, copy, modify, distribute, perform, display, etc.
In the United States – and many jurisdictions – copyright protections
attach automatically to creative works upon creation if they satisfy
certain minimum criteria.
“Public Domain” would thus represent a significant change to the legal
status of the work.
The rules around “Public Domain” often vary or are unspecified
jurisdiction to jurisdiction. Adding to the confusion, some
jurisdictions may not even recognize the concept of “Public Domain”
(or similar). As such, a license may nevertheless be required or implied
in these cases. Even in the U.S., there is no clear,
officially-sanctioned procedure for affirmatively placing
copyright-eligible works into the “Public Domain” aside from natural
statutory expiration of copyright. The bottom-line is, there are few if
any objective, brightline rules for proactively placing
copyright-eligible works into the Public Domain that we can broadly
rely on.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-16 14:18:35 +08:00
Alin Jerpelea ca3cfbac99 crypto/md5: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

define NuttX local NuttX-PublicDomain identifier

 “Public Domain” is a concept distinct from copyright licensing;
it generally means that the work no longer has any copyright protection
or ownership, and therefore requires no license permission in order to
use, copy, modify, distribute, perform, display, etc.
In the United States – and many jurisdictions – copyright protections
attach automatically to creative works upon creation if they satisfy
certain minimum criteria.
“Public Domain” would thus represent a significant change to the legal
status of the work.
The rules around “Public Domain” often vary or are unspecified
jurisdiction to jurisdiction. Adding to the confusion, some
jurisdictions may not even recognize the concept of “Public Domain”
(or similar). As such, a license may nevertheless be required or implied
in these cases. Even in the U.S., there is no clear,
officially-sanctioned procedure for affirmatively placing
copyright-eligible works into the “Public Domain” aside from natural
statutory expiration of copyright. The bottom-line is, there are few if
any objective, brightline rules for proactively placing
copyright-eligible works into the Public Domain that we can broadly
rely on.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-16 14:18:35 +08:00
Alin Jerpelea 2503b36b71 crypto/chacha: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

define NuttX local NuttX-PublicDomain identifier

 “Public Domain” is a concept distinct from copyright licensing;
it generally means that the work no longer has any copyright protection
or ownership, and therefore requires no license permission in order to
use, copy, modify, distribute, perform, display, etc.
In the United States – and many jurisdictions – copyright protections
attach automatically to creative works upon creation if they satisfy
certain minimum criteria.
“Public Domain” would thus represent a significant change to the legal
status of the work.
The rules around “Public Domain” often vary or are unspecified
jurisdiction to jurisdiction. Adding to the confusion, some
jurisdictions may not even recognize the concept of “Public Domain”
(or similar). As such, a license may nevertheless be required or implied
in these cases. Even in the U.S., there is no clear,
officially-sanctioned procedure for affirmatively placing
copyright-eligible works into the “Public Domain” aside from natural
statutory expiration of copyright. The bottom-line is, there are few if
any objective, brightline rules for proactively placing
copyright-eligible works into the Public Domain that we can broadly
rely on.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-16 14:18:35 +08:00
Alin Jerpelea 4c48884ddf crypto/cast: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

define NuttX local NuttX-PublicDomain identifier

 “Public Domain” is a concept distinct from copyright licensing;
it generally means that the work no longer has any copyright protection
or ownership, and therefore requires no license permission in order to
use, copy, modify, distribute, perform, display, etc.
In the United States – and many jurisdictions – copyright protections
attach automatically to creative works upon creation if they satisfy
certain minimum criteria.
“Public Domain” would thus represent a significant change to the legal
status of the work.
The rules around “Public Domain” often vary or are unspecified
jurisdiction to jurisdiction. Adding to the confusion, some
jurisdictions may not even recognize the concept of “Public Domain”
(or similar). As such, a license may nevertheless be required or implied
in these cases. Even in the U.S., there is no clear,
officially-sanctioned procedure for affirmatively placing
copyright-eligible works into the “Public Domain” aside from natural
statutory expiration of copyright. The bottom-line is, there are few if
any objective, brightline rules for proactively placing
copyright-eligible works into the Public Domain that we can broadly
rely on.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-16 14:18:35 +08:00
Alin Jerpelea f2db470415 crypto: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-11-06 20:10:37 +08:00
ouyangxiangzhen 17c51c0667 userspace: Exclude nuttx/arch.h
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-11-01 16:59:37 +08:00
Xiang Xiao 32784b0898 libc: Refine the arc4random_buf implementation
fill the buffer with getrandom instead random pool
and move the implementation to from crypto to libc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-26 18:04:21 -03:00
makejian 5b1d910ec6 nuttx/crypto: export asynchronous calling process
Signed-off-by: makejian <makejian@xiaomi.com>
2024-09-28 13:05:28 +08:00
guoshichao 0da40c5d65 greenhills: fix the arc4random_buf implicit declaration build error
"/home/guoshichao/work_profile/vela_os/vela_car_5/nuttx/include/crypto/curve25519.h", line 44: error #223-D:
          function arc4random_buf declared implicitly
      arc4random_buf(secret, CURVE25519_KEY_SIZE);
      ^

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-09-26 22:52:28 +08:00
chenrun1 03f215b374 nuttx/atomic.h:fix Fixed the pragma of ATOMIC_VAR_INIT in clang
Error: vfs/fs_epoll.c:126:3: error: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Werror,-Wdeprecated-pragma]
  ATOMIC_VAR_INIT(1),     /* i_crefs */
  ^
/Applications/Xcode_15.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/stdatomic.h:54:41: note: macro marked 'deprecated' here
                                        ^
1 error generated.
make[1]: *** [fs_epoll.o] Error 1
Error: socket/socket.c:78:3: error: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Werror,-Wdeprecated-pragma]
  ATOMIC_VAR_INIT(1),     /* i_crefs */

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-23 14:07:03 +08:00
chenrun1 4cec713dbf fs_inode:Change the type of i_crefs to atomic_int
Summary:
  1.Modified the i_crefs from int16_t to atomic_int
  2.Modified the i_crefs add, delete, read, and initialize interfaces to atomic operations
The purpose of this change is to avoid deadlock in cross-core scenarios, where A Core blocks B Core’s request for a write operation to A Core when A Core requests a read operation to B Core.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-23 14:07:03 +08:00
Masayuki Ishikawa df298c186f Revert "build depend:Revert Make.dep intermediate ddc file"
This reverts commit ddc3119c4e.
2024-09-15 19:29:47 +08:00