crypto:support nuttx /dev/crypto

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao
2022-07-28 17:52:21 +08:00
committed by Xiang Xiao
parent 82956a2894
commit 3d2f0c0e27
45 changed files with 1782 additions and 1086 deletions

View File

@@ -37,6 +37,7 @@ endif # CRYPTO_ALGTEST
config CRYPTO_CRYPTODEV
bool "cryptodev support"
depends on ALLOW_BSD_COMPONENTS
default n
config CRYPTO_SW_AES

View File

@@ -30,12 +30,27 @@ CRYPTO_CSRCS += crypto.c testmngr.c
ifeq ($(CONFIG_CRYPTO_CRYPTODEV),y)
CRYPTO_CSRCS += cryptodev.c
endif
# Software AES library
ifeq ($(CONFIG_CRYPTO_SW_AES),y)
CRYPTO_CSRCS += cryptosoft.c
CRYPTO_CSRCS += xform.c
CRYPTO_CSRCS += aes.c
CRYPTO_CSRCS += blf.c
CRYPTO_CSRCS += cast.c
CRYPTO_CSRCS += chachapoly.c
CRYPTO_CSRCS += ecb_enc.c
CRYPTO_CSRCS += ecb3_enc.c
CRYPTO_CSRCS += set_key.c
CRYPTO_CSRCS += md5.c
CRYPTO_CSRCS += poly1305.c
CRYPTO_CSRCS += rijndael.c
CRYPTO_CSRCS += rmd160.c
CRYPTO_CSRCS += sha1.c
CRYPTO_CSRCS += sha2.c
CRYPTO_CSRCS += gmac.c
CRYPTO_CSRCS += cmac.c
CRYPTO_CSRCS += hmac.c
CRYPTO_CSRCS += idgen.c
CRYPTO_CSRCS += key_wrap.c
CRYPTO_CSRCS += siphash.c
endif
# BLAKE2s hash algorithm

View File

@@ -31,9 +31,8 @@
* Included Files
****************************************************************************/
#include <string.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/stdint.h>
#include <crypto/aes.h>
/****************************************************************************

View File

@@ -42,7 +42,6 @@
****************************************************************************/
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/blf.h>

View File

@@ -12,9 +12,10 @@
* Included Files
****************************************************************************/
#include <string.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <crypto/cast.h>
#include "castsb.h"
/* Macros to access 8-bit bytes out of a 32-bit word */

View File

@@ -11,7 +11,8 @@
* Included Files
****************************************************************************/
#include <sys/systm.h>
#include <string.h>
#include <sys/types.h>
typedef struct
{

View File

@@ -21,9 +21,8 @@
* Included Files
****************************************************************************/
#include <endian.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <lib/libkern/libkern.h>
#include <crypto/poly1305.h>
#include <crypto/chachapoly.h>

View File

@@ -26,12 +26,15 @@
* Included Files
****************************************************************************/
#include <string.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/aes.h>
#include <crypto/cmac.h>
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#define LSHIFT(v, r) do \
{ \
int i; \

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -59,7 +59,6 @@
****************************************************************************/
#include <sys/types.h>
#include <sys/systm.h>
typedef unsigned char des_cblock[8];
typedef struct des_ks_struct

View File

@@ -28,9 +28,9 @@
* Included Files
****************************************************************************/
#include <endian.h>
#include <strings.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/aes.h>
#include <crypto/gmac.h>

View File

@@ -26,8 +26,9 @@
* Included Files
****************************************************************************/
#include <string.h>
#include <strings.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/md5.h>
#include <crypto/sha1.h>

View File

@@ -26,8 +26,11 @@
* Included Files
****************************************************************************/
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <nuttx/clock.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/time.h>
#include <crypto/idgen.h>
@@ -119,7 +122,8 @@ static void idgen32_rekey(FAR struct idgen32_ctx *ctx)
ctx->id32_hibit ^= 0x80000000;
ctx->id32_offset = arc4random();
arc4random_buf(ctx->id32_key, sizeof(ctx->id32_key));
ctx->id32_rekey_time = getuptime() + IDGEN32_REKEY_TIME;
ctx->id32_rekey_time = TICK2SEC(clock_systime_ticks()) +
IDGEN32_REKEY_TIME;
}
/****************************************************************************
@@ -142,7 +146,7 @@ uint32_t idgen32(FAR struct idgen32_ctx *ctx)
/* Rekey a little early to avoid "card counting" attack */
if (ctx->id32_counter > IDGEN32_REKEY_LIMIT ||
ctx->id32_rekey_time < getuptime())
ctx->id32_rekey_time < TICK2SEC(clock_systime_ticks()))
{
idgen32_rekey(ctx);
}

View File

@@ -23,9 +23,9 @@
* Included Files
****************************************************************************/
#include <endian.h>
#include <string.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/aes.h>
#include <crypto/key_wrap.h>

View File

@@ -22,8 +22,9 @@
* Included Files
****************************************************************************/
#include <endian.h>
#include <string.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/md5.h>
#define PUT_64BIT_LE(cp, value) \

View File

@@ -12,7 +12,6 @@
****************************************************************************/
#include <sys/types.h>
#include <sys/systm.h>
#include <crypto/poly1305.h>

View File

@@ -32,7 +32,6 @@
****************************************************************************/
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/rijndael.h>

View File

@@ -35,8 +35,8 @@
****************************************************************************/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/endian.h>
#include <endian.h>
#include <string.h>
#include <crypto/rmd160.h>
#define PUT_64BIT_LE(cp, value) \

View File

@@ -61,6 +61,8 @@
* Included Files
****************************************************************************/
#include <strings.h>
#include "des_locl.h"
#include "podd.h"
#include "sk.h"

View File

@@ -20,8 +20,9 @@
* Included Files
****************************************************************************/
#include <endian.h>
#include <string.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/sha1.h>

View File

@@ -38,8 +38,9 @@
* Included Files
****************************************************************************/
#include <endian.h>
#include <string.h>
#include <sys/time.h>
#include <sys/systm.h>
#include <crypto/sha2.h>
/* UNROLLED TRANSFORM LOOP NOTE:

View File

@@ -48,8 +48,9 @@
* Included Files
****************************************************************************/
#include <endian.h>
#include <string.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/siphash.h>

View File

@@ -51,6 +51,12 @@
* [including the GNU Public Licence.]
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/types.h>
static const uint32_t des_skb[8][64] =
{
{

View File

@@ -50,6 +50,12 @@
* [including the GNU Public Licence.]
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/types.h>
static const uint32_t des_sptrans[8][64] =
{
{

View File

@@ -53,12 +53,11 @@
* Included Files
****************************************************************************/
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <machine/cpu.h>
#include <crypto/md5.h>
#include <crypto/sha1.h>
@@ -118,9 +117,6 @@ int sha256update_int(FAR void *, FAR const uint8_t *, uint16_t);
int sha384update_int(FAR void *, FAR const uint8_t *, uint16_t);
int sha512update_int(FAR void *, FAR const uint8_t *, uint16_t);
uint32_t deflate_compress(FAR uint8_t *, uint32_t, FAR uint8_t **);
uint32_t deflate_decompress(FAR uint8_t *, uint32_t, FAR uint8_t **);
struct aes_ctr_ctx
{
AES_CTX ac_key;
@@ -337,15 +333,6 @@ const struct auth_hash auth_hash_chacha20_poly1305 =
chacha20_poly1305_final
};
/* Compression instance */
const struct comp_algo comp_algo_deflate =
{
CRYPTO_DEFLATE_COMP, "Deflate",
90, deflate_compress,
deflate_decompress
};
/* Encryption wrapper routines. */
void des3_encrypt(caddr_t key, FAR uint8_t *blk)
@@ -633,28 +620,3 @@ int sha512update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
sha512update(ctx, buf, len);
return 0;
}
uint32_t deflate_global(FAR uint8_t *, uint32_t, int, FAR uint8_t **);
struct deflate_buf
{
FAR uint8_t *out;
uint32_t size;
int flag;
};
/* And compression */
uint32_t deflate_compress(FAR uint8_t *data,
uint32_t size,
FAR uint8_t **out)
{
return deflate_global(data, size, 0, out);
}
uint32_t deflate_decompress(FAR uint8_t *data,
uint32_t size,
FAR uint8_t **out)
{
return deflate_global(data, size, 1, out);
}