Commit Graph

112 Commits

Author SHA1 Message Date
yinshengkai d0a5489ac5 sched: explicitly select the cpuload clock source configuration
Different configurations require different dependencies.
Explicitly select dependencies to avoid automatically selecting inappropriate configurations.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-11-01 09:27:56 +08:00
makejian 3dbe2d790e crypto/rsa_verify: export rsa verify via /dev/crypto
kernel supports asymmetric encryption RSA signature verification
Signed-off-by: makejian <makejian@xiaomi.com>
2023-10-18 12:23:13 +08:00
makejian aeac109e50 crypto/bn:Add exponentiation algorithm in bignum
add exponentiation algorithm: pow_mod_faster
Signed-off-by: makejian <makejian@xiaomi.com>
2023-10-18 12:23:13 +08:00
makejian 12935f2d33 crypto/bn: porting tiny-Bignum-C into nuttx crypto
porting from https://github.com/kokke/tiny-bignum-c commit ac136565378c624365e0f5f556d386b3966bff32 and adapting to the nuttx
Signed-off-by: makejian <makejian@xiaomi.com>
2023-10-18 12:23:13 +08:00
makejian cb3abc48d7 crypto/cryptodev: expansion hash operation
(1) remove size restriction for single hash operation
(2) support hash operation to update uint32_t data
Signed-off-by: makejian <makejian@xiaomi.com>
2023-09-24 03:49:33 +08:00
Xiang Xiao c27b470d39 Fix error: implicit declaration of function 'arc4random'; did you mean 'random'? [-Werror=implicit-function-declaration]
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-12 10:02:50 +08:00
Xiang Xiao 4f5a177eef board/sim/crypto: Enable CONFIG_CRYPTO_SW_AES
to fix the following linker error:
/usr/bin/ld: nuttx.rel: in function `aes_encrypt_xform':
/github/workspace/sources/nuttx/crypto/xform.c:509: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_decrypt_xform':
/github/workspace/sources/nuttx/crypto/xform.c:514: undefined reference to `aes_decrypt'
/usr/bin/ld: nuttx.rel: in function `aes_setkey_xform':
/github/workspace/sources/nuttx/crypto/xform.c:519: undefined reference to `aes_setkey'
/usr/bin/ld: nuttx.rel: in function `aes_ctr_crypt':
/github/workspace/sources/nuttx/crypto/xform.c:566: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_ctr_setkey':
/github/workspace/sources/nuttx/crypto/xform.c:585: undefined reference to `aes_setkey'
/usr/bin/ld: nuttx.rel: in function `aes_ofb_encrypt':
/github/workspace/sources/nuttx/crypto/xform.c:694: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_ofb_setkey':
/github/workspace/sources/nuttx/crypto/xform.c:706: undefined reference to `aes_setkey'
/usr/bin/ld: nuttx.rel: in function `aes_cfb8_encrypt':
/github/workspace/sources/nuttx/crypto/xform.c:733: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_cfb8_decrypt':
/github/workspace/sources/nuttx/crypto/xform.c:751: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_cfb128_encrypt':
/github/workspace/sources/nuttx/crypto/xform.c:765: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_cfb128_decrypt':
/github/workspace/sources/nuttx/crypto/xform.c:781: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_gmac_setkey':
/github/workspace/sources/nuttx/crypto/gmac.c:135: undefined reference to `aes_setkey'
/usr/bin/ld: /github/workspace/sources/nuttx/crypto/gmac.c:143: undefined reference to `aes_encrypt'
/usr/bin/ld: nuttx.rel: in function `aes_gmac_final':
/github/workspace/sources/nuttx/crypto/gmac.c:195: undefined reference to `aes_encrypt'

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-11 14:17:07 +08:00
Xiang Xiao dec99c0c97 crypto: Remove CRYPTO_BLAKE2S Kconfig
since it's more simple to let linker remove the unused functions from the final image

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-10 18:27:03 +08:00
makejian f4f2c9ed49 crypto: fix multiple definition of `poly1305_init'
apps/crypto/libtomcrypt/libtomcrypt/src/mac/poly1305/poly1305.c:90: multiple definition of `poly1305_init';
nuttx/crypto/poly1305.c:51: first defined here
Signed-off-by: makejian <makejian@xiaomi.com>
2023-09-07 17:02:08 -03:00
makejian afbe6239ae crypto: update aes algorithm process
(1)update iv in each encryption process
(2)support aes-ofb/aes-cfb128/aes-cfb8
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-21 13:05:19 +08:00
makejian 120aaf27b3 crypto: remove software algorithm coupling in cryptodev
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-17 13:12:36 +08:00
makejian ac76a8fe0f crypto: export SHA224/SHA384 via /dev/crypto
(1)add sha224 algorithm in sha2.c
(2)export sha224/sha384
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-10 13:36:19 +08:00
anjiahao 319e8d66f6 crypto:fix typo for blake2s
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-10 13:35:44 +08:00
makejian 775d9de30a crypto: export MD5/SHA1/SHA256/SHA512 via /dev/crypto
refer to commit 649dc2d985
(1) import hash method
(2) separate the update and finish processes

Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 22:37:30 -07:00
makejian 4e70d59c3b crypto: reduce software algorithm size
not compile the software algorithm file when CONFIG_CRYPTO_CRYPTODEV_SOFTWARE not set
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 10:14:38 -07:00
makejian 6676853589 crypto: add config of software algorithm
software algorithm not used by default and managed by respective config
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 10:14:38 -07:00
makejian d5041420a3 crypto: porting Curve25519 algorithm into nuttx crypto
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 03:20:13 -07:00
makejian b6c2362c6a crypto: fix above array bounds warning in nuttx crypto
crypto.c:440:38: warning: array subscript 24 is above array bounds of 'int[24]' [-Warray-bounds]
  440 |       crypto_drivers[driverid].cc_alg[alg] == 0)
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from crypto.c:37:
nuttx/include/crypto/cryptodev.h:269:7: note: while referencing 'cc_alg'
  269 |   int cc_alg[CRYPTO_ALGORITHM_MAX + 1];

following commit cbf8475b93
(1)alg need to blong to [1, CRYPTO_ALGORITHM_MAX + 1] in sanity checks
(2)clear alg algorithm when alg blongs to [1, CRYPTO_ALGORITHM_MAX + 1)
(3)clear all algorithms when alg equals to CRYPTO_ALGORITHM_MAX + 1
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 03:14:46 -07:00
makejian 5e0e027880 crypto: memory requested by asymmetric encryption is not initialized
Using uninitialized memory for output parameters is at risk of error in asymmetric encryption process
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 03:14:46 -07:00
makejian a5dc00f941 crypto: fix bug in the asymmetric encryption process
(1)uninitialized memory cause release failure
(2)wrong release timing
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 03:14:46 -07:00
makejian e0fa78f8f3 crypto: fix aesxts and hmac crash bug
(1)aesxts uses correct size to memcpy
(2)prevent hmac null pointer of struct crde
Signed-off-by: makejian <makejian@xiaomi.com>
2023-08-03 03:14:46 -07:00
simbit18 9681c52517 Fix nuttx coding style
Remove TABs
Fix indentation
2023-07-11 23:32:17 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Fotis Panagiotopoulos 85ceb7920e Typo fixes. 2023-02-17 11:17:11 -03:00
chao an 3a0fdb019d nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:05:44 +08:00
Gustavo Henrique Nihei e6b204f438 nuttx: Use MIN/MAX definitions from "sys/param.h"
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-02-01 23:47:44 +08:00
anjiahao 43d2c595b1 crypto:support crypto can handle streaming data
in user space
Use the flag (COP_FLAG_UPDATE)structure member to mark
whether it is just input data.
like this:
can do manys times,just input data
....

  cryp.ses = session.ses;
  cryp.op = COP_ENCRYPT;
  cryp.src = (caddr_t) s;
  cryp.len = len;
  cryp.flags = COP_FLAG_UPDATE;
  cryp.dst = 0;
  cryp.mac = (caddr_t) out;
  cryp.iv = 0;
  if (ioctl(cryptodev_fd, CIOCCRYPT, &cryp) == -1)
    {
      warn("CIOCCRYPT");
      goto err;
    }

can do manys times like frist...

then,the last time

Don't use any flay structure member to mark
this is last time,need get final result
....
  cryp.ses = session.ses;
  cryp.op = COP_ENCRYPT;
  cryp.src = (caddr_t) s;
  cryp.len = len;
  cryp.flags = 0;
  cryp.dst = 0;
  cryp.mac = (caddr_t) out;
  cryp.iv = 0;
  if (ioctl(cryptodev_fd, CIOCCRYPT, &cryp) == -1)
    {
      warn("CIOCCRYPT");
      goto err;
    }
....
that will get last result.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-17 01:19:38 +08:00
anjiahao 86609246e3 crypto:add read & write function aviod check flag failed
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-16 19:26:19 +08:00
Xiang Xiao b0a0ba3ad7 fs: Move mmap callback before truncate in [file|mountpt]_operations
since mmap may exist in block_operations, but truncate may not,
moving mmap beforee truncate could make three struct more compatible

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-04 17:43:59 +02:00
Jukka Laitinen f33dc4df3f Change FIOC_MMAP into file operation call
- Add mmap into file_operations and remove it from ioctl definitions.
- Add mm_map structure definitions to support future unmapping
- Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-02 11:23:20 -03:00
Jukka Laitinen 41e9df2f3e Add ftruncate into file operation calls
- Add truncate into file_operations
- Move truncate to be common for mountpt_operations and file_operations
- Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-02 11:23:20 -03:00
anjiahao bc0fe0ea16 crypto:add some hardware support
esp32c3: aes hmac-sha1 hmac-sha256
stm32f0l0g0 stm32l1 : aes
sam34: aes
lpc43: aes
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-12-14 02:33:56 +08:00
anjiahao 3d2f0c0e27 crypto:support nuttx /dev/crypto
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-12-14 02:33:56 +08:00
anjiahao 82956a2894 crypto:convert code style form openbsd to nuttx
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-12-14 02:33:56 +08:00
anjiahao acd3350554 crypto:Sync version differences
1.fix type warning for compile
2.hamc key can less than specified length
3.add new version algorithms to cryptodev
    sha256hmac
    sha384hmac
    sha512hmac
    aes128gmac

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-12-14 02:33:56 +08:00
anjiahao c7d347c7f0 crypto: Initial copy from https://github.com/openbsd/sys/crypto
public header files put into include/crpyto
private header/source files put into crpyto

crypto.c cryptodev.[c|h] cryptosoft.[c|h] come from:
commit id is f245bed2a7593bf0decce50caaed4ce05fefd6cf

the rest come from:
commit id is 61b0e532b2dce0a91cf3ea67d346645a61a88cdd

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-12-14 02:33:56 +08:00
anjiahao a4563b8744 Fix the coding style and typo issue
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-14 09:34:04 +09:00
anjiahao d07792a343 Initialize global mutext/sem by NXMUTEX_INITIALIZER and SEM_INITIALIZER
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-14 09:34:04 +09:00
anjiahao 0c26658906 random_pool:add a new api arc4random
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-11-09 06:41:19 +01:00
Xiang Xiao d0bd68b35e Fix random_pool.c:214:13: error: conflicting types for 'getentropy'
214 | static void getentropy(FAR blake2s_state *S)
       |             ^~~~~~~~~~
 In file included from /home/work/ssd1/workspace/MiRTOS-CI@2/out/miwear/ap/.unionfs/nuttx/include/nuttx/mutex.h:31,
                  from random_pool.c:37:
 /home/work/ssd1/workspace/MiRTOS-CI@2/out/miwear/ap/.unionfs/nuttx/include/unistd.h:428:9: note: previous declaration of 'getentropy' was here
   428 | int     getentropy(FAR void *buffer, size_t length);
       |         ^~~~~~~~~~

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-22 20:52:19 +02:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
Xiang Xiao 01cb137277 crypto/random_pool: Remove the unused header file(unistd.h and nuttx/arch.h)
and include the used header files(nuttx/clock.h and nuttx/semaphore.h)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-27 14:27:11 +03:00
Xiang Xiao d7fe0127b0 Replece clock_gettime(CLOCK_REALTIME) with clock_systime_timespec if suitable
it's better to call the kernrel api insteaad user space api in kernel

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-24 01:06:36 +08:00
Juha Niskanen 62e1821ca0 crypto: apply BSD barrier only to SW AES library
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2022-01-13 16:27:52 +01:00
Alin Jerpelea 7597b8e471 crypto: Haltian Ltd: update licenses to Apache
Gregory Nutt has submitted the SGA
Haltian Ltd has submitted the SGA

as a result we can migrate the licenses to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-11-15 06:49:32 -06:00
Alin Jerpelea ae3088c501 crypto: add BSD barrier for AES crypto
add BSD barrier for AES crypto

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-09-02 21:56:05 +08:00
ligd ec042c3dc7 crypto: fix asan report error
random_pool.c:466:14: runtime error: left shift of 305919453 by 17 places cannot be represented in type 'long int'
random_pool.c:178:11: runtime error: shift exponent 32 is too large for 32-bit type 'unsigned int'

Change-Id: I714f42b68f4af43249946aed8537cd848e569194
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-02 07:58:45 -07:00
Jukka Laitinen cdb1b00f34 crypto/random_pool.c: Correct indexing on void pointer
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2021-06-11 10:58:06 -05:00
Xiang Xiao d7f96003cf Don't include debug.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-01 06:42:02 +09:00
Alin Jerpelea cddde2459b crypto: update licenses to Apache
Gregory Nutt is the copyright holder for those files and he has submitted the
SGA as a result we can migrate the licenses to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-05-27 08:07:25 +09:00