mirror of
https://github.com/apache/nuttx.git
synced 2025-12-17 10:16:49 +08:00
crypto:support nuttx /dev/crypto
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
@@ -37,6 +37,7 @@ endif # CRYPTO_ALGTEST
|
||||
|
||||
config CRYPTO_CRYPTODEV
|
||||
bool "cryptodev support"
|
||||
depends on ALLOW_BSD_COMPONENTS
|
||||
default n
|
||||
|
||||
config CRYPTO_SW_AES
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <crypto/blf.h>
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/systm.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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; \
|
||||
|
||||
252
crypto/crypto.c
252
crypto/crypto.c
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
@@ -59,7 +59,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
typedef unsigned char des_cblock[8];
|
||||
typedef struct des_ks_struct
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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) \
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <crypto/poly1305.h>
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <crypto/rijndael.h>
|
||||
|
||||
|
||||
@@ -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) \
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
#include "des_locl.h"
|
||||
#include "podd.h"
|
||||
#include "sk.h"
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <endian.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <crypto/sha1.h>
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -48,8 +48,9 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <endian.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <crypto/siphash.h>
|
||||
|
||||
|
||||
@@ -51,6 +51,12 @@
|
||||
* [including the GNU Public Licence.]
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
static const uint32_t des_skb[8][64] =
|
||||
{
|
||||
{
|
||||
|
||||
@@ -50,6 +50,12 @@
|
||||
* [including the GNU Public Licence.]
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
static const uint32_t des_sptrans[8][64] =
|
||||
{
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user