crypto:support nuttx /dev/crypto
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
parent
82956a2894
commit
3d2f0c0e27
45 changed files with 1782 additions and 1086 deletions
72
boards/sim/sim/sim/configs/crypto/defconfig
Normal file
72
boards/sim/sim/sim/configs/crypto/defconfig
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
CONFIG_ALLOW_BSD_COMPONENTS=y
|
||||
CONFIG_ALLSYMS=y
|
||||
CONFIG_ARCH="sim"
|
||||
CONFIG_ARCH_BOARD="sim"
|
||||
CONFIG_ARCH_BOARD_SIM=y
|
||||
CONFIG_ARCH_CHIP="sim"
|
||||
CONFIG_ARCH_SIM=y
|
||||
CONFIG_BOARDCTL_APP_SYMTAB=y
|
||||
CONFIG_BOARDCTL_POWEROFF=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=0
|
||||
CONFIG_BOOT_RUNFROMEXTSRAM=y
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_CRYPTO=y
|
||||
CONFIG_CRYPTO_CRYPTODEV=y
|
||||
CONFIG_CRYPTO_RANDOM_POOL=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_DEV_GPIO=y
|
||||
CONFIG_DEV_LOOP=y
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_EXAMPLES_GPIO=y
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
CONFIG_FAT_LCNAMES=y
|
||||
CONFIG_FAT_LFN=y
|
||||
CONFIG_FSUTILS_PASSWD=y
|
||||
CONFIG_FSUTILS_PASSWD_READONLY=y
|
||||
CONFIG_FS_BINFS=y
|
||||
CONFIG_FS_FAT=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_RAMMAP=y
|
||||
CONFIG_FS_ROMFS=y
|
||||
CONFIG_GPIO_LOWER_HALF=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=4096
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_IOEXPANDER=y
|
||||
CONFIG_IOEXPANDER_DUMMY=y
|
||||
CONFIG_LIBC_ENVPATH=y
|
||||
CONFIG_LIBC_EXECFUNCS=y
|
||||
CONFIG_LIBC_LOCALE=y
|
||||
CONFIG_LIBC_LOCALE_CATALOG=y
|
||||
CONFIG_LIBC_LOCALE_GETTEXT=y
|
||||
CONFIG_LIBC_MAX_EXITFUNS=1
|
||||
CONFIG_LIBC_NUMBERED_ARGS=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_ARCHROMFS=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FATDEVNO=2
|
||||
CONFIG_NSH_FILE_APPS=y
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NSH_ROMFSDEVNO=1
|
||||
CONFIG_NSH_ROMFSETC=y
|
||||
CONFIG_PATH_INITIAL="/bin"
|
||||
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=2048
|
||||
CONFIG_PSEUDOFS_ATTRIBUTES=y
|
||||
CONFIG_PSEUDOFS_SOFTLINKS=y
|
||||
CONFIG_READLINE_TABCOMPLETION=y
|
||||
CONFIG_SCHED_BACKTRACE=y
|
||||
CONFIG_SCHED_HAVE_PARENT=y
|
||||
CONFIG_SCHED_HPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_START_MONTH=6
|
||||
CONFIG_START_YEAR=2008
|
||||
CONFIG_SYSTEM_DUMPSTACK=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TESTING_CRYPTO=y
|
||||
|
|
@ -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
|
|
@ -26,31 +26,36 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/pool.h>
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
#include <crypto/cryptodev.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void crypto_init(void);
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/mutex.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/crypto/crypto.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
FAR static struct cryptocap *crypto_drivers = NULL;
|
||||
FAR struct cryptocap *crypto_drivers = NULL;
|
||||
int crypto_drivers_num = 0;
|
||||
|
||||
struct pool cryptop_pool;
|
||||
struct pool cryptodesc_pool;
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct taskq *crypto_taskq;
|
||||
static mutex_t g_crypto_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Create a new session. */
|
||||
|
||||
|
|
@ -65,14 +70,13 @@ int crypto_newsession(FAR uint64_t *sid,
|
|||
FAR struct cryptoini *cr;
|
||||
int turn = 0;
|
||||
int err;
|
||||
int s;
|
||||
|
||||
if (crypto_drivers == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
/* The algorithm we use here is pretty stupid; just use the
|
||||
* first driver that supports all the algorithms we need. Do
|
||||
|
|
@ -196,8 +200,8 @@ int crypto_newsession(FAR uint64_t *sid,
|
|||
|
||||
if (hid == -1)
|
||||
{
|
||||
splx(s);
|
||||
return EINVAL;
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Call the driver initialization routine. */
|
||||
|
|
@ -212,7 +216,7 @@ int crypto_newsession(FAR uint64_t *sid,
|
|||
crypto_drivers[hid].cc_sessions++;
|
||||
}
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -223,12 +227,11 @@ int crypto_newsession(FAR uint64_t *sid,
|
|||
int crypto_freesession(uint64_t sid)
|
||||
{
|
||||
int err = 0;
|
||||
int s;
|
||||
uint32_t hid;
|
||||
|
||||
if (crypto_drivers == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Determine two IDs. */
|
||||
|
|
@ -237,10 +240,10 @@ int crypto_freesession(uint64_t sid)
|
|||
|
||||
if (hid >= crypto_drivers_num)
|
||||
{
|
||||
return ENOENT;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
if (crypto_drivers[hid].cc_sessions)
|
||||
{
|
||||
|
|
@ -264,7 +267,7 @@ int crypto_freesession(uint64_t sid)
|
|||
explicit_bzero(&crypto_drivers[hid], sizeof(struct cryptocap));
|
||||
}
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -274,20 +277,18 @@ int crypto_get_driverid(uint8_t flags)
|
|||
{
|
||||
FAR struct cryptocap *newdrv;
|
||||
int i;
|
||||
int s;
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
if (crypto_drivers_num == 0)
|
||||
{
|
||||
crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
|
||||
crypto_drivers = mallocarray(crypto_drivers_num,
|
||||
sizeof(struct cryptocap),
|
||||
M_CRYPTO_DATA, M_NOWAIT);
|
||||
crypto_drivers = kmm_calloc(crypto_drivers_num,
|
||||
sizeof(struct cryptocap));
|
||||
if (crypto_drivers == NULL)
|
||||
{
|
||||
crypto_drivers_num = 0;
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +304,7 @@ int crypto_get_driverid(uint8_t flags)
|
|||
{
|
||||
crypto_drivers[i].cc_sessions = 1; /* Mark */
|
||||
crypto_drivers[i].cc_flags = flags;
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
@ -314,16 +315,15 @@ int crypto_get_driverid(uint8_t flags)
|
|||
{
|
||||
if (crypto_drivers_num >= CRYPTO_DRIVERS_MAX)
|
||||
{
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
newdrv = mallocarray(crypto_drivers_num,
|
||||
2 * sizeof(struct cryptocap),
|
||||
M_CRYPTO_DATA, M_NOWAIT);
|
||||
newdrv = kmm_calloc(crypto_drivers_num * 2,
|
||||
sizeof(struct cryptocap));
|
||||
if (newdrv == NULL)
|
||||
{
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -336,15 +336,15 @@ int crypto_get_driverid(uint8_t flags)
|
|||
newdrv[i].cc_flags = flags;
|
||||
crypto_drivers_num *= 2;
|
||||
|
||||
free(crypto_drivers, M_CRYPTO_DATA, 0);
|
||||
kmm_free(crypto_drivers);
|
||||
crypto_drivers = newdrv;
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Shouldn't really get here... */
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -355,16 +355,15 @@ int crypto_get_driverid(uint8_t flags)
|
|||
int crypto_kregister(uint32_t driverid, FAR int *kalg,
|
||||
CODE int (*kprocess)(FAR struct cryptkop *))
|
||||
{
|
||||
int s;
|
||||
int i;
|
||||
|
||||
if (driverid >= crypto_drivers_num || kalg == NULL ||
|
||||
crypto_drivers == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
for (i = 0; i <= CRK_ALGORITHM_MAX; i++)
|
||||
{
|
||||
|
|
@ -378,7 +377,7 @@ int crypto_kregister(uint32_t driverid, FAR int *kalg,
|
|||
|
||||
crypto_drivers[driverid].cc_kprocess = kprocess;
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -390,16 +389,15 @@ int crypto_register(uint32_t driverid, FAR int *alg,
|
|||
CODE int (*freeses)(uint64_t),
|
||||
CODE int (*process)(FAR struct cryptop *))
|
||||
{
|
||||
int s;
|
||||
int i;
|
||||
|
||||
if (driverid >= crypto_drivers_num || alg == NULL ||
|
||||
crypto_drivers == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
for (i = 0; i <= CRYPTO_ALGORITHM_MAX; i++)
|
||||
{
|
||||
|
|
@ -416,7 +414,7 @@ int crypto_register(uint32_t driverid, FAR int *alg,
|
|||
crypto_drivers[driverid].cc_freesession = freeses;
|
||||
crypto_drivers[driverid].cc_sessions = 0; /* Unmark */
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -430,10 +428,9 @@ int crypto_register(uint32_t driverid, FAR int *alg,
|
|||
int crypto_unregister(uint32_t driverid, int alg)
|
||||
{
|
||||
int i = CRYPTO_ALGORITHM_MAX + 1;
|
||||
int s;
|
||||
uint32_t ses;
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
/* Sanity checks. */
|
||||
|
||||
|
|
@ -442,8 +439,8 @@ int crypto_unregister(uint32_t driverid, int alg)
|
|||
alg != CRYPTO_ALGORITHM_MAX + 1) ||
|
||||
crypto_drivers[driverid].cc_alg[alg] == 0)
|
||||
{
|
||||
splx(s);
|
||||
return EINVAL;
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (alg != CRYPTO_ALGORITHM_MAX + 1)
|
||||
|
|
@ -478,39 +475,7 @@ int crypto_unregister(uint32_t driverid, int alg)
|
|||
}
|
||||
}
|
||||
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add crypto request to a queue, to be processed by a kernel thread. */
|
||||
|
||||
int crypto_dispatch(FAR struct cryptop *crp)
|
||||
{
|
||||
if (crypto_taskq && !(crp->crp_flags & CRYPTO_F_NOQUEUE))
|
||||
{
|
||||
task_set(&crp->crp_task, (void (*))crypto_invoke, crp, NULL);
|
||||
task_add(crypto_taskq, &crp->crp_task);
|
||||
}
|
||||
else
|
||||
{
|
||||
crypto_invoke(crp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypto_kdispatch(FAR struct cryptkop *krp)
|
||||
{
|
||||
if (crypto_taskq)
|
||||
{
|
||||
task_set(&krp->krp_task, (void (*))crypto_kinvoke, krp, NULL);
|
||||
task_add(crypto_taskq, &krp->krp_task);
|
||||
}
|
||||
else
|
||||
{
|
||||
crypto_kinvoke(krp);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -521,16 +486,15 @@ int crypto_kinvoke(FAR struct cryptkop *krp)
|
|||
extern int cryptodevallowsoft;
|
||||
uint32_t hid;
|
||||
int error;
|
||||
int s;
|
||||
|
||||
/* Sanity checks. */
|
||||
|
||||
if (krp == NULL || krp->krp_callback == NULL)
|
||||
if (krp == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
for (hid = 0; hid < crypto_drivers_num; hid++)
|
||||
{
|
||||
if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
|
||||
|
|
@ -555,9 +519,8 @@ int crypto_kinvoke(FAR struct cryptkop *krp)
|
|||
|
||||
if (hid == crypto_drivers_num)
|
||||
{
|
||||
krp->krp_status = ENODEV;
|
||||
crypto_kdone(krp);
|
||||
splx(s);
|
||||
krp->krp_status = -ENODEV;
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -569,10 +532,9 @@ int crypto_kinvoke(FAR struct cryptkop *krp)
|
|||
if (error)
|
||||
{
|
||||
krp->krp_status = error;
|
||||
crypto_kdone(krp);
|
||||
}
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -584,21 +546,19 @@ int crypto_invoke(FAR struct cryptop *crp)
|
|||
uint64_t nid;
|
||||
uint32_t hid;
|
||||
int error;
|
||||
int s;
|
||||
|
||||
/* Sanity checks. */
|
||||
|
||||
if (crp == NULL || crp->crp_callback == NULL)
|
||||
if (crp == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
if (crp->crp_desc == NULL || crypto_drivers == NULL)
|
||||
{
|
||||
crp->crp_etype = EINVAL;
|
||||
crypto_done(crp);
|
||||
splx(s);
|
||||
crp->crp_etype = -EINVAL;
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -625,7 +585,7 @@ int crypto_invoke(FAR struct cryptop *crp)
|
|||
error = crypto_drivers[hid].cc_process(crp);
|
||||
if (error)
|
||||
{
|
||||
if (error == ERESTART)
|
||||
if (error == -ERESTART)
|
||||
{
|
||||
/* Unregister driver and migrate session. */
|
||||
|
||||
|
|
@ -638,7 +598,7 @@ int crypto_invoke(FAR struct cryptop *crp)
|
|||
}
|
||||
}
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return 0;
|
||||
|
||||
migrate:
|
||||
|
|
@ -655,9 +615,8 @@ migrate:
|
|||
crp->crp_sid = nid;
|
||||
}
|
||||
|
||||
crp->crp_etype = EAGAIN;
|
||||
crypto_done(crp);
|
||||
splx(s);
|
||||
crp->crp_etype = -EAGAIN;
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -666,23 +625,22 @@ migrate:
|
|||
void crypto_freereq(FAR struct cryptop *crp)
|
||||
{
|
||||
FAR struct cryptodesc *crd;
|
||||
int s;
|
||||
|
||||
if (crp == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
while ((crd = crp->crp_desc) != NULL)
|
||||
{
|
||||
crp->crp_desc = crd->crd_next;
|
||||
pool_put(&cryptodesc_pool, crd);
|
||||
kmm_free(crd);
|
||||
}
|
||||
|
||||
pool_put(&cryptop_pool, crp);
|
||||
splx(s);
|
||||
kmm_free(crp);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
}
|
||||
|
||||
/* Acquire a set of crypto descriptors. */
|
||||
|
|
@ -691,14 +649,13 @@ FAR struct cryptop *crypto_getreq(int num)
|
|||
{
|
||||
FAR struct cryptodesc *crd;
|
||||
FAR struct cryptop *crp;
|
||||
int s;
|
||||
|
||||
s = splvm();
|
||||
nxmutex_lock(&g_crypto_lock);
|
||||
|
||||
crp = pool_get(&cryptop_pool, PR_NOWAIT);
|
||||
crp = kmm_malloc(sizeof(struct cryptop));
|
||||
if (crp == NULL)
|
||||
{
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -706,60 +663,22 @@ FAR struct cryptop *crypto_getreq(int num)
|
|||
|
||||
while (num--)
|
||||
{
|
||||
crd = pool_get(&cryptodesc_pool, PR_NOWAIT);
|
||||
crd = kmm_calloc(1, sizeof(struct cryptodesc));
|
||||
if (crd == NULL)
|
||||
{
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
crypto_freereq(crp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bzero(crd, sizeof(struct cryptodesc));
|
||||
crd->crd_next = crp->crp_desc;
|
||||
crp->crp_desc = crd;
|
||||
}
|
||||
|
||||
splx(s);
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return crp;
|
||||
}
|
||||
|
||||
void crypto_init(void)
|
||||
{
|
||||
crypto_taskq = taskq_create("crypto", 1, IPL_HIGH);
|
||||
|
||||
pool_init(&cryptop_pool, sizeof(struct cryptop), 0, 0,
|
||||
0, "cryptop", NULL);
|
||||
pool_init(&cryptodesc_pool, sizeof(struct cryptodesc), 0, 0,
|
||||
0, "cryptodesc", NULL);
|
||||
}
|
||||
|
||||
/* Invoke the callback on behalf of the driver. */
|
||||
|
||||
void crypto_done(FAR struct cryptop *crp)
|
||||
{
|
||||
crp->crp_flags |= CRYPTO_F_DONE;
|
||||
if (crp->crp_flags & CRYPTO_F_NOQUEUE)
|
||||
{
|
||||
/* not from the crypto queue, wakeup the userland process */
|
||||
|
||||
crp->crp_callback(crp);
|
||||
}
|
||||
else
|
||||
{
|
||||
task_set(&crp->crp_task, (void (*))crp->crp_callback,
|
||||
crp, NULL);
|
||||
task_add(crypto_taskq, &crp->crp_task);
|
||||
}
|
||||
}
|
||||
|
||||
/* Invoke the callback on behalf of the driver. */
|
||||
|
||||
void crypto_kdone(FAR struct cryptkop *krp)
|
||||
{
|
||||
task_set(&krp->krp_task, (void (*))krp->krp_callback, krp, NULL);
|
||||
task_add(crypto_taskq, &krp->krp_task);
|
||||
}
|
||||
|
||||
int crypto_getfeat(FAR int *featp)
|
||||
{
|
||||
extern int cryptodevallowsoft;
|
||||
|
|
@ -800,3 +719,22 @@ out:
|
|||
*featp = feat;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int up_cryptoinitialize(void)
|
||||
{
|
||||
#ifdef CONFIG_CRYPTO_ALGTEST
|
||||
int ret = crypto_test();
|
||||
if (ret)
|
||||
{
|
||||
crypterr("ERROR: crypto test failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
cryptinfo("crypto test OK\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,25 +33,23 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/pool.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/errno.h>
|
||||
#include <dev/rndvar.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/device.h>
|
||||
#include <crypto/md5.h>
|
||||
#include <crypto/sha1.h>
|
||||
#include <crypto/rmd160.h>
|
||||
#include <crypto/cast.h>
|
||||
#include <crypto/blf.h>
|
||||
#include <crypto/cryptodev.h>
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/queue.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/crypto/crypto.h>
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
|
||||
#include <crypto/xform.h>
|
||||
#include <crypto/cryptodev.h>
|
||||
#include <crypto/cryptosoft.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
|
|
@ -59,9 +57,11 @@
|
|||
|
||||
extern FAR struct cryptocap *crypto_drivers;
|
||||
extern int crypto_drivers_num;
|
||||
int usercrypto = 0; /* userland may do crypto requests */
|
||||
int userasymcrypto = 0; /* userland may do asymmetric crypto reqs */
|
||||
int cryptodevallowsoft = 0; /* only use hardware crypto */
|
||||
int usercrypto = 1; /* userland may do crypto requests */
|
||||
int userasymcrypto = 1; /* userland may do asymmetric crypto reqs */
|
||||
int cryptodevallowsoft = 1; /* 0 is only use hardware crypto
|
||||
* 1 is use hardware & software crypto
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
|
|
@ -84,8 +84,6 @@ struct csession
|
|||
|
||||
caddr_t mackey;
|
||||
int mackeylen;
|
||||
struct iovec iovec[IOV_MAX];
|
||||
struct uio uio;
|
||||
int error;
|
||||
};
|
||||
|
||||
|
|
@ -99,31 +97,52 @@ struct fcrypt
|
|||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
void cryptoattach(int);
|
||||
/* Character driver methods */
|
||||
|
||||
int cryptof_read(FAR struct file *, FAR off_t *,
|
||||
FAR struct uio *, FAR struct ucred *);
|
||||
int cryptof_write(FAR struct file *, FAR off_t *,
|
||||
FAR struct uio *, FAR struct ucred *);
|
||||
int cryptof_ioctl(FAR struct file *, u_long, caddr_t, FAR struct proc *p);
|
||||
int cryptof_poll(FAR struct file *, int, FAR struct proc *);
|
||||
int cryptof_kqfilter(FAR struct file *, FAR struct knote *);
|
||||
int cryptof_stat(FAR struct file *, FAR struct stat *, FAR struct proc *);
|
||||
int cryptof_close(FAR struct file *, FAR struct proc *);
|
||||
static ssize_t cryptof_read(FAR struct file *filep,
|
||||
FAR char *buffer, size_t len);
|
||||
static ssize_t cryptof_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t len);
|
||||
static int cryptof_ioctl(FAR struct file *filep,
|
||||
int cmd, unsigned long arg);
|
||||
static int cryptof_poll(FAR struct file *filep,
|
||||
struct pollfd *fds, bool setup);
|
||||
static int cryptof_close(FAR struct file *filep);
|
||||
|
||||
static int cryptoopen(FAR struct file *filep);
|
||||
static int cryptoclose(FAR struct file *filep);
|
||||
static int cryptoioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct fileops g_cryptofops =
|
||||
static const struct file_operations g_cryptofops =
|
||||
{
|
||||
cryptof_read,
|
||||
cryptof_write,
|
||||
cryptof_ioctl,
|
||||
cryptof_poll,
|
||||
cryptof_kqfilter,
|
||||
cryptof_stat,
|
||||
cryptof_close
|
||||
NULL, /* open */
|
||||
cryptof_close, /* close */
|
||||
cryptof_read, /* read */
|
||||
cryptof_write, /* write */
|
||||
NULL, /* seek */
|
||||
cryptof_ioctl, /* ioctl */
|
||||
cryptof_poll /* poll */
|
||||
};
|
||||
|
||||
static const struct file_operations g_cryptoops =
|
||||
{
|
||||
cryptoopen, /* open */
|
||||
cryptoclose, /* close */
|
||||
NULL, /* read */
|
||||
NULL, /* write */
|
||||
NULL, /* seek */
|
||||
cryptoioctl, /* ioctl */
|
||||
NULL /* poll */
|
||||
};
|
||||
|
||||
static struct inode g_cryptoinode =
|
||||
{
|
||||
.i_crefs = 1,
|
||||
.u.i_ops = &g_cryptofops
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -141,7 +160,7 @@ FAR struct csession *csecreate(FAR struct fcrypt *, uint64_t,
|
|||
int csefree(FAR struct csession *);
|
||||
|
||||
int cryptodev_op(FAR struct csession *,
|
||||
FAR struct crypt_op *, FAR struct proc *);
|
||||
FAR struct crypt_op *);
|
||||
int cryptodev_key(FAR struct crypt_kop *);
|
||||
int cryptodev_dokey(FAR struct crypt_kop *kop, FAR struct crparam *kvp);
|
||||
|
||||
|
|
@ -150,28 +169,28 @@ int cryptodevkey_cb(FAR struct cryptkop *);
|
|||
|
||||
/* ARGSUSED */
|
||||
|
||||
int cryptof_read(FAR struct file *fp, FAR off_t *poff,
|
||||
FAR struct uio *uio, FAR struct ucred *cred)
|
||||
static ssize_t cryptof_read(FAR struct file *filep,
|
||||
FAR char *buffer, size_t len)
|
||||
{
|
||||
return EIO;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
|
||||
int cryptof_write(FAR struct file *fp, FAR off_t *poff,
|
||||
FAR struct uio *uio, FAR struct ucred *cred)
|
||||
static ssize_t cryptof_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t len)
|
||||
{
|
||||
return EIO;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
|
||||
int cryptof_ioctl(FAR struct file *fp, u_long cmd,
|
||||
caddr_t data, FAR struct proc *p)
|
||||
static int cryptof_ioctl(FAR struct file *filep,
|
||||
int cmd, unsigned long arg)
|
||||
{
|
||||
struct cryptoini cria;
|
||||
struct cryptoini crie;
|
||||
FAR struct fcrypt *fcr = fp->f_data;
|
||||
FAR struct fcrypt *fcr = filep->f_priv;
|
||||
FAR struct csession *cse;
|
||||
FAR struct session_op *sop;
|
||||
FAR struct crypt_op *cop;
|
||||
|
|
@ -184,7 +203,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd,
|
|||
switch (cmd)
|
||||
{
|
||||
case CIOCGSESSION:
|
||||
sop = (FAR struct session_op *)data;
|
||||
sop = (FAR struct session_op *)arg;
|
||||
switch (sop->cipher)
|
||||
{
|
||||
case 0:
|
||||
|
|
@ -211,7 +230,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd,
|
|||
txform = &enc_xform_null;
|
||||
break;
|
||||
default:
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
switch (sop->mac)
|
||||
|
|
@ -240,7 +259,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd,
|
|||
thash = &auth_hash_gmac_aes_128;
|
||||
break;
|
||||
default:
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bzero(&crie, sizeof(crie));
|
||||
|
|
@ -253,18 +272,18 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd,
|
|||
if (sop->keylen > txform->maxkey ||
|
||||
sop->keylen < txform->minkey)
|
||||
{
|
||||
error = EINVAL;
|
||||
error = -EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
crie.cri_key = malloc(crie.cri_klen / 8, M_XDATA,
|
||||
M_WAITOK);
|
||||
if ((error = copyin(sop->key, crie.cri_key,
|
||||
crie.cri_klen / 8)))
|
||||
crie.cri_key = kmm_malloc(crie.cri_klen / 8);
|
||||
if (crie.cri_key == NULL)
|
||||
{
|
||||
error = -ENOMEM;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
memcpy(crie.cri_key, sop->key, crie.cri_klen / 8);
|
||||
if (thash)
|
||||
{
|
||||
crie.cri_next = &cria;
|
||||
|
|
@ -277,19 +296,20 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd,
|
|||
cria.cri_klen = sop->mackeylen * 8;
|
||||
if (sop->mackeylen > thash->keysize)
|
||||
{
|
||||
error = EINVAL;
|
||||
error = -EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (cria.cri_klen)
|
||||
{
|
||||
cria.cri_key = malloc(cria.cri_klen / 8,
|
||||
M_XDATA, M_WAITOK);
|
||||
if ((error = copyin(sop->mackey, cria.cri_key,
|
||||
cria.cri_klen / 8)))
|
||||
cria.cri_key = kmm_malloc(cria.cri_klen / 8);
|
||||
if (cria.cri_key == NULL)
|
||||
{
|
||||
error = -ENOMEM;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
memcpy(cria.cri_key, sop->mackey, cria.cri_klen / 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -308,7 +328,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd,
|
|||
if (cse == NULL)
|
||||
{
|
||||
crypto_freesession(sid);
|
||||
error = EINVAL;
|
||||
error = -EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
|
|
@ -320,92 +340,79 @@ bail:
|
|||
if (crie.cri_key)
|
||||
{
|
||||
explicit_bzero(crie.cri_key, crie.cri_klen / 8);
|
||||
free(crie.cri_key, M_XDATA, 0);
|
||||
kmm_free(crie.cri_key);
|
||||
}
|
||||
|
||||
if (cria.cri_key)
|
||||
{
|
||||
explicit_bzero(cria.cri_key, cria.cri_klen / 8);
|
||||
free(cria.cri_key, M_XDATA, 0);
|
||||
kmm_free(cria.cri_key);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case CIOCFSESSION:
|
||||
ses = *(FAR uint32_t *)data;
|
||||
ses = *(FAR uint32_t *)arg;
|
||||
cse = csefind(fcr, ses);
|
||||
if (cse == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
csedelete(fcr, cse);
|
||||
error = csefree(cse);
|
||||
break;
|
||||
case CIOCCRYPT:
|
||||
cop = (FAR struct crypt_op *)data;
|
||||
cop = (FAR struct crypt_op *)arg;
|
||||
cse = csefind(fcr, cop->ses);
|
||||
if (cse == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
error = cryptodev_op(cse, cop, p);
|
||||
error = cryptodev_op(cse, cop);
|
||||
break;
|
||||
case CIOCKEY:
|
||||
error = cryptodev_key((FAR struct crypt_kop *)data);
|
||||
error = cryptodev_key((FAR struct crypt_kop *)arg);
|
||||
break;
|
||||
case CIOCASYMFEAT:
|
||||
error = crypto_getfeat((FAR int *)data);
|
||||
error = crypto_getfeat((FAR int *)arg);
|
||||
break;
|
||||
default:
|
||||
error = EINVAL;
|
||||
error = -EINVAL;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int cryptodev_op(FAR struct csession *cse,
|
||||
FAR struct crypt_op *cop,
|
||||
FAR struct proc *p)
|
||||
FAR struct crypt_op *cop)
|
||||
{
|
||||
FAR struct cryptop *crp = NULL;
|
||||
FAR struct cryptodesc *crde = NULL;
|
||||
FAR struct cryptodesc *crda = NULL;
|
||||
int s;
|
||||
int error;
|
||||
int error = OK;
|
||||
uint32_t hid;
|
||||
|
||||
if (cop->len > 64 * 1024 - 4)
|
||||
{
|
||||
return E2BIG;
|
||||
return -E2BIG;
|
||||
}
|
||||
|
||||
if (cse->txform)
|
||||
{
|
||||
if (cop->len == 0 || (cop->len % cse->txform->blocksize) != 0)
|
||||
{
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
bzero(&cse->uio, sizeof(cse->uio));
|
||||
cse->uio.uio_iovcnt = 1;
|
||||
cse->uio.uio_segflg = UIO_SYSSPACE;
|
||||
cse->uio.uio_rw = UIO_WRITE;
|
||||
cse->uio.uio_procp = p;
|
||||
cse->uio.uio_iov = cse->iovec;
|
||||
bzero(&cse->iovec, sizeof(cse->iovec));
|
||||
cse->uio.uio_iov[0].iov_len = cop->len;
|
||||
cse->uio.uio_iov[0].iov_base = dma_alloc(cop->len, M_WAITOK);
|
||||
cse->uio.uio_resid = cse->uio.uio_iov[0].iov_len;
|
||||
|
||||
/* number of requests, not logical and */
|
||||
|
||||
crp = crypto_getreq((cse->txform != NULL) + (cse->thash != NULL));
|
||||
if (crp == NULL)
|
||||
{
|
||||
error = ENOMEM;
|
||||
error = -ENOMEM;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
|
|
@ -423,16 +430,11 @@ int cryptodev_op(FAR struct csession *cse,
|
|||
}
|
||||
else
|
||||
{
|
||||
error = EINVAL;
|
||||
error = -EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
|
||||
if ((error = copyin(cop->src, cse->uio.uio_iov[0].iov_base, cop->len)))
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (crda)
|
||||
{
|
||||
crda->crd_skip = 0;
|
||||
|
|
@ -463,8 +465,7 @@ int cryptodev_op(FAR struct csession *cse,
|
|||
}
|
||||
|
||||
crp->crp_ilen = cop->len;
|
||||
crp->crp_buf = (caddr_t)&cse->uio;
|
||||
crp->crp_callback = cryptodev_cb;
|
||||
crp->crp_buf = cop->src;
|
||||
crp->crp_sid = cse->sid;
|
||||
crp->crp_opaque = cse;
|
||||
|
||||
|
|
@ -472,15 +473,11 @@ int cryptodev_op(FAR struct csession *cse,
|
|||
{
|
||||
if (crde == NULL)
|
||||
{
|
||||
error = EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if ((error = copyin(cop->iv, cse->tmp_iv, cse->txform->blocksize)))
|
||||
{
|
||||
error = -EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
memcpy(cse->tmp_iv, cop->iv, cse->txform->blocksize);
|
||||
bcopy(cse->tmp_iv, crde->crd_iv, cse->txform->blocksize);
|
||||
crde->crd_flags |= CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT;
|
||||
crde->crd_skip = 0;
|
||||
|
|
@ -492,11 +489,22 @@ int cryptodev_op(FAR struct csession *cse,
|
|||
crde->crd_len -= cse->txform->blocksize;
|
||||
}
|
||||
|
||||
if (cop->dst)
|
||||
{
|
||||
if (crde == NULL)
|
||||
{
|
||||
error = -EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
crp->crp_dst = cop->dst;
|
||||
}
|
||||
|
||||
if (cop->mac)
|
||||
{
|
||||
if (crda == NULL)
|
||||
{
|
||||
error = EINVAL;
|
||||
error = -EINVAL;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
|
|
@ -534,21 +542,8 @@ int cryptodev_op(FAR struct csession *cse,
|
|||
goto processed;
|
||||
dispatch:
|
||||
crp->crp_flags = CRYPTO_F_IOV;
|
||||
crypto_dispatch(crp);
|
||||
crypto_invoke(crp);
|
||||
processed:
|
||||
s = splnet();
|
||||
while (!(crp->crp_flags & CRYPTO_F_DONE))
|
||||
{
|
||||
error = tsleep(cse, PSOCK, "crydev", 0);
|
||||
}
|
||||
|
||||
splx(s);
|
||||
if (error)
|
||||
{
|
||||
/* XXX can this happen? if so, how do we recover? */
|
||||
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (cse->error)
|
||||
{
|
||||
|
|
@ -562,57 +557,19 @@ processed:
|
|||
goto bail;
|
||||
}
|
||||
|
||||
if (cop->dst &&
|
||||
(error = copyout(cse->uio.uio_iov[0].iov_base, cop->dst, cop->len)))
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (cop->mac &&
|
||||
(error = copyout(crp->crp_mac, cop->mac, cse->thash->hashsize)))
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
|
||||
bail:
|
||||
if (crp)
|
||||
{
|
||||
crypto_freereq(crp);
|
||||
}
|
||||
|
||||
if (cse->uio.uio_iov[0].iov_base)
|
||||
{
|
||||
dma_free(cse->uio.uio_iov[0].iov_base, cop->len);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int cryptodev_cb(FAR struct cryptop *crp)
|
||||
{
|
||||
FAR struct csession *cse = crp->crp_opaque;
|
||||
|
||||
cse->error = crp->crp_etype;
|
||||
if (crp->crp_etype == EAGAIN)
|
||||
{
|
||||
crp->crp_flags = CRYPTO_F_IOV;
|
||||
return crypto_dispatch(crp);
|
||||
}
|
||||
|
||||
wakeup(cse);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int cryptodevkey_cb(FAR struct cryptkop *krp)
|
||||
{
|
||||
wakeup(krp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int cryptodev_key(FAR struct crypt_kop *kop)
|
||||
{
|
||||
FAR struct cryptkop *krp = NULL;
|
||||
int error = EINVAL;
|
||||
int error = -EINVAL;
|
||||
int in;
|
||||
int out;
|
||||
int size;
|
||||
|
|
@ -620,7 +577,7 @@ int cryptodev_key(FAR struct crypt_kop *kop)
|
|||
|
||||
if (kop->crk_iparams + kop->crk_oparams > CRK_MAXPARAM)
|
||||
{
|
||||
return EFBIG;
|
||||
return -EFBIG;
|
||||
}
|
||||
|
||||
in = kop->crk_iparams;
|
||||
|
|
@ -630,34 +587,33 @@ int cryptodev_key(FAR struct crypt_kop *kop)
|
|||
case CRK_MOD_EXP:
|
||||
if (in == 3 && out == 1)
|
||||
break;
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
case CRK_MOD_EXP_CRT:
|
||||
if (in == 6 && out == 1)
|
||||
break;
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
case CRK_DSA_SIGN:
|
||||
if (in == 5 && out == 2)
|
||||
break;
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
case CRK_DSA_VERIFY:
|
||||
if (in == 7 && out == 0)
|
||||
break;
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
case CRK_DH_COMPUTE_KEY:
|
||||
if (in == 3 && out == 1)
|
||||
break;
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
default:
|
||||
return EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
krp = malloc(sizeof *krp, M_XDATA, M_WAITOK | M_ZERO);
|
||||
krp = kmm_malloc(sizeof *krp);
|
||||
krp->krp_op = kop->crk_op;
|
||||
krp->krp_status = kop->crk_status;
|
||||
krp->krp_iparams = kop->crk_iparams;
|
||||
krp->krp_oparams = kop->crk_oparams;
|
||||
krp->krp_status = 0;
|
||||
krp->krp_callback = cryptodevkey_cb;
|
||||
|
||||
for (i = 0; i < CRK_MAXPARAM; i++)
|
||||
{
|
||||
|
|
@ -678,34 +634,25 @@ int cryptodev_key(FAR struct crypt_kop *kop)
|
|||
continue;
|
||||
}
|
||||
|
||||
krp->krp_param[i].crp_p = malloc(size, M_XDATA, M_WAITOK);
|
||||
krp->krp_param[i].crp_p = kmm_malloc(size);
|
||||
if (i >= krp->krp_iparams)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
error = copyin(kop->crk_param[i].crp_p,
|
||||
krp->krp_param[i].crp_p, size);
|
||||
memcpy(krp->krp_param[i].crp_p, kop->crk_param[i].crp_p, size);
|
||||
if (error)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
error = crypto_kdispatch(krp);
|
||||
error = crypto_kinvoke(krp);
|
||||
if (error)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
error = tsleep(krp, PSOCK, "crydev", 0);
|
||||
if (error)
|
||||
{
|
||||
/* XXX can this happen? if so, how do we recover? */
|
||||
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (krp->krp_status != 0)
|
||||
{
|
||||
error = krp->krp_status;
|
||||
|
|
@ -720,12 +667,8 @@ int cryptodev_key(FAR struct crypt_kop *kop)
|
|||
continue;
|
||||
}
|
||||
|
||||
error = copyout(krp->krp_param[i].crp_p,
|
||||
kop->crk_param[i].crp_p, size);
|
||||
if (error)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
memcpy(kop->crk_param[i].crp_p,
|
||||
krp->krp_param[i].crp_p, size);
|
||||
}
|
||||
|
||||
fail:
|
||||
|
|
@ -738,11 +681,11 @@ fail:
|
|||
{
|
||||
explicit_bzero(krp->krp_param[i].crp_p,
|
||||
(krp->krp_param[i].crp_nbits + 7) / 8);
|
||||
free(krp->krp_param[i].crp_p, M_XDATA, 0);
|
||||
kmm_free(krp->krp_param[i].crp_p);
|
||||
}
|
||||
}
|
||||
|
||||
free(krp, M_XDATA, 0);
|
||||
kmm_free(krp);
|
||||
}
|
||||
|
||||
return error;
|
||||
|
|
@ -750,32 +693,17 @@ fail:
|
|||
|
||||
/* ARGSUSED */
|
||||
|
||||
int cryptof_poll(FAR struct file *fp, int events, FAR struct proc *p)
|
||||
static int cryptof_poll(FAR struct file *filep,
|
||||
struct pollfd *fds, bool setup)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
|
||||
int cryptof_kqfilter(FAR struct file *fp, FAR struct knote *kn)
|
||||
static int cryptof_close(FAR struct file *filep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
|
||||
int cryptof_stat(FAR struct file *fp,
|
||||
FAR struct stat *sb,
|
||||
FAR struct proc *p)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
|
||||
int cryptof_close(FAR struct file *fp, FAR struct proc *p)
|
||||
{
|
||||
FAR struct fcrypt *fcr = fp->f_data;
|
||||
FAR struct fcrypt *fcr = filep->f_priv;
|
||||
FAR struct csession *cse;
|
||||
|
||||
while ((cse = TAILQ_FIRST(&fcr->csessions)))
|
||||
|
|
@ -784,38 +712,29 @@ int cryptof_close(FAR struct file *fp, FAR struct proc *p)
|
|||
(void)csefree(cse);
|
||||
}
|
||||
|
||||
free(fcr, M_XDATA, 0);
|
||||
fp->f_data = NULL;
|
||||
kmm_free(fcr);
|
||||
filep->f_priv = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cryptoattach(int n)
|
||||
{
|
||||
}
|
||||
|
||||
int cryptoopen(dev_t dev, int flag, int mode, FAR struct proc *p)
|
||||
static int cryptoopen(FAR struct file *filep)
|
||||
{
|
||||
if (usercrypto == 0)
|
||||
{
|
||||
return ENXIO;
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
#ifdef CRYPTO
|
||||
return 0;
|
||||
#else
|
||||
return ENXIO;
|
||||
#endif
|
||||
}
|
||||
|
||||
int cryptoclose(dev_t dev, int flag, int mode, FAR struct proc *p)
|
||||
static int cryptoclose(FAR struct file *filep)
|
||||
{
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cryptoioctl(dev_t dev, u_long cmd,
|
||||
caddr_t data, int flag, FAR struct proc *p)
|
||||
static int cryptoioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
FAR struct file *f;
|
||||
FAR struct fcrypt *fcr;
|
||||
int fd;
|
||||
int error = 0;
|
||||
|
|
@ -823,28 +742,22 @@ int cryptoioctl(dev_t dev, u_long cmd,
|
|||
switch (cmd)
|
||||
{
|
||||
case CRIOGET:
|
||||
fcr = malloc(sizeof(struct fcrypt), M_XDATA, M_WAITOK);
|
||||
fcr = kmm_malloc(sizeof(struct fcrypt));
|
||||
TAILQ_INIT(&fcr->csessions);
|
||||
fcr->sesn = 0;
|
||||
|
||||
fdplock(p->p_fd);
|
||||
error = falloc(p, &f, &fd);
|
||||
fdpunlock(p->p_fd);
|
||||
if (error)
|
||||
fd = file_allocate(&g_cryptoinode, 0,
|
||||
0, fcr, 0, true);
|
||||
if (fd < 0)
|
||||
{
|
||||
free(fcr, M_XDATA, 0);
|
||||
return error;
|
||||
kmm_free(fcr);
|
||||
return fd;
|
||||
}
|
||||
|
||||
f->f_flag = FREAD | FWRITE;
|
||||
f->f_type = DTYPE_CRYPTO;
|
||||
f->f_ops = &cryptofops;
|
||||
f->f_data = fcr;
|
||||
*(FAR uint32_t *)data = fd;
|
||||
FILE_SET_MATURE(f, p);
|
||||
fcr->sesn = 0;
|
||||
*(FAR uint32_t *)arg = fd;
|
||||
break;
|
||||
default:
|
||||
error = EINVAL;
|
||||
error = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -897,23 +810,22 @@ FAR struct csession *csecreate(FAR struct fcrypt *fcr, uint64_t sid,
|
|||
{
|
||||
FAR struct csession *cse;
|
||||
|
||||
cse = malloc(sizeof(struct csession), M_XDATA, M_NOWAIT);
|
||||
if (cse == NULL)
|
||||
cse = kmm_malloc(sizeof(struct csession));
|
||||
if (cse != NULL)
|
||||
{
|
||||
return NULL;
|
||||
cse->key = key;
|
||||
cse->keylen = keylen / 8;
|
||||
cse->mackey = mackey;
|
||||
cse->mackeylen = mackeylen / 8;
|
||||
cse->sid = sid;
|
||||
cse->cipher = cipher;
|
||||
cse->mac = mac;
|
||||
cse->txform = txform;
|
||||
cse->thash = thash;
|
||||
cse->error = 0;
|
||||
cseadd(fcr, cse);
|
||||
}
|
||||
|
||||
cse->key = key;
|
||||
cse->keylen = keylen / 8;
|
||||
cse->mackey = mackey;
|
||||
cse->mackeylen = mackeylen / 8;
|
||||
cse->sid = sid;
|
||||
cse->cipher = cipher;
|
||||
cse->mac = mac;
|
||||
cse->txform = txform;
|
||||
cse->thash = thash;
|
||||
cse->error = 0;
|
||||
cseadd(fcr, cse);
|
||||
return cse;
|
||||
}
|
||||
|
||||
|
|
@ -924,14 +836,28 @@ int csefree(FAR struct csession *cse)
|
|||
error = crypto_freesession(cse->sid);
|
||||
if (cse->key)
|
||||
{
|
||||
free(cse->key, M_XDATA, 0);
|
||||
kmm_free(cse->key);
|
||||
}
|
||||
|
||||
if (cse->mackey)
|
||||
{
|
||||
free(cse->mackey, M_XDATA, 0);
|
||||
kmm_free(cse->mackey);
|
||||
}
|
||||
|
||||
free(cse, M_XDATA, 0);
|
||||
kmm_free(cse);
|
||||
return error;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void devcrypto_register(void)
|
||||
{
|
||||
register_driver("/dev/crypto", &g_cryptoops, 0666, NULL);
|
||||
swcr_init();
|
||||
|
||||
#ifdef CONFIG_CRYPTO_CRYPTODEV_HARDWARE
|
||||
hwcr_init();
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_AES_H
|
||||
#define __INCLUDE_CRYPTO_AES_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef AES_MAXROUNDS
|
||||
# define AES_MAXROUNDS (14)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,6 +33,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_BLF_H
|
||||
#define __INCLUDE_CRYPTO_BLF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Schneier states the maximum key length to be 56 bytes.
|
||||
* The way how the subkeys are initialized by the key up
|
||||
* to (N+2)*4 i.e. 72 bytes are utilized.
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_CMAC_H_
|
||||
#define __INCLUDE_CRYPTO_CMAC_H_
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define AES_CMAC_KEY_LENGTH 16
|
||||
#define AES_CMAC_DIGEST_LENGTH 16
|
||||
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/task.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Some initial values */
|
||||
|
||||
|
|
@ -173,7 +172,6 @@ struct cryptodesc
|
|||
|
||||
struct cryptop
|
||||
{
|
||||
struct task crp_task;
|
||||
uint64_t crp_sid; /* Session ID */
|
||||
int crp_ilen; /* Input data total length */
|
||||
int crp_olen; /* Result total length */
|
||||
|
|
@ -202,6 +200,7 @@ struct cryptop
|
|||
CODE int (*crp_callback)(FAR struct cryptop *); /* Callback function */
|
||||
|
||||
caddr_t crp_mac;
|
||||
caddr_t crp_dst;
|
||||
};
|
||||
|
||||
#define CRYPTO_BUF_IOV 0x1
|
||||
|
|
@ -245,8 +244,6 @@ struct crypt_kop
|
|||
|
||||
struct cryptkop
|
||||
{
|
||||
struct task krp_task;
|
||||
|
||||
u_int krp_op; /* ie. CRK_MOD_EXP or other */
|
||||
u_int krp_status; /* return status */
|
||||
u_short krp_iparams; /* # of input parameters */
|
||||
|
|
@ -322,21 +319,18 @@ struct crypt_op
|
|||
* Please use F_SETFD against the cloned descriptor.
|
||||
*/
|
||||
|
||||
#define CRIOGET _IOWR('c', 100, uint32_t)
|
||||
#define CRIOGET 100
|
||||
|
||||
/* the following are done against the cloned descriptor */
|
||||
#define CIOCGSESSION _IOWR('c', 101, struct session_op)
|
||||
#define CIOCFSESSION _IOW('c', 102, uint32_t)
|
||||
#define CIOCCRYPT _IOWR('c', 103, struct crypt_op)
|
||||
#define CIOCKEY _IOWR('c', 104, struct crypt_kop)
|
||||
|
||||
#define CIOCASYMFEAT _IOR('c', 105, uint32_t)
|
||||
#define CIOCGSESSION 101
|
||||
#define CIOCFSESSION 102
|
||||
#define CIOCCRYPT 103
|
||||
#define CIOCKEY 104
|
||||
#define CIOCASYMFEAT 105
|
||||
|
||||
#ifdef _KERNEL
|
||||
int crypto_newsession(FAR uint64_t *, FAR struct cryptoini *, int);
|
||||
int crypto_freesession(uint64_t);
|
||||
int crypto_dispatch(FAR struct cryptop *);
|
||||
int crypto_kdispatch(FAR struct cryptkop *);
|
||||
int crypto_register(uint32_t, FAR int *,
|
||||
CODE int (*)(uint32_t *, struct cryptoini *),
|
||||
CODE int (*)(uint64_t),
|
||||
|
|
@ -346,17 +340,8 @@ int crypto_unregister(uint32_t, int);
|
|||
int crypto_get_driverid(uint8_t);
|
||||
int crypto_invoke(FAR struct cryptop *);
|
||||
int crypto_kinvoke(FAR struct cryptkop *);
|
||||
void crypto_done(FAR struct cryptop *);
|
||||
void crypto_kdone(FAR struct cryptkop *);
|
||||
int crypto_getfeat(FAR int *);
|
||||
|
||||
void cuio_copydata(FAR struct uio *, int, int, caddr_t);
|
||||
void cuio_copyback(FAR struct uio *, int, int, const void *);
|
||||
int cuio_getptr(FAR struct uio *, int, FAR int *);
|
||||
int cuio_apply(FAR struct uio *, int, int,
|
||||
CODE int (*f)(caddr_t, caddr_t, unsigned int), caddr_t);
|
||||
|
||||
FAR struct cryptop *crypto_getreq(int);
|
||||
void crypto_freereq(FAR struct cryptop *);
|
||||
#endif /* _KERNEL */
|
||||
#endif /* __INCLUDE_CRYPTO_CRYPTODEV_H */
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/queue.h>
|
||||
#include <crypto/cryptodev.h>
|
||||
|
||||
/* Software session entry */
|
||||
|
||||
struct swcr_data
|
||||
|
|
@ -70,14 +73,13 @@ struct swcr_data
|
|||
struct swcr_data *sw_next;
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
extern const uint8_t hmac_ipad_buffer[HMAC_MAX_BLOCK_LEN];
|
||||
extern const uint8_t hmac_opad_buffer[HMAC_MAX_BLOCK_LEN];
|
||||
|
||||
int swcr_encdec(FAR struct cryptodesc *,
|
||||
FAR struct swcr_data *, caddr_t, int);
|
||||
int swcr_encdec(FAR struct cryptop *, FAR struct cryptodesc *,
|
||||
FAR struct swcr_data *, caddr_t);
|
||||
int swcr_authcompute(FAR struct cryptop *, FAR struct cryptodesc *,
|
||||
FAR struct swcr_data *, caddr_t, int);
|
||||
FAR struct swcr_data *, caddr_t);
|
||||
int swcr_authenc(FAR struct cryptop *);
|
||||
int swcr_compdec(FAR struct cryptodesc *, FAR struct swcr_data *,
|
||||
caddr_t, int);
|
||||
|
|
@ -85,6 +87,5 @@ int swcr_process(FAR struct cryptop *);
|
|||
int swcr_newsession(FAR uint32_t *, FAR struct cryptoini *);
|
||||
int swcr_freesession(uint64_t);
|
||||
void swcr_init(void);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* __INCLUDE_CRYPTO_CRYPTOSOFT_H */
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <crypto/aes.h>
|
||||
|
||||
#define GMAC_BLOCK_LEN 16
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_HMAC_H_
|
||||
#define __INCLUDE_CRYPTO_HMAC_H_
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct _HMAC_MD5_CTX
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_KEY_WRAP_H_
|
||||
#define __INCLUDE_CRYPTO_KEY_WRAP_H_
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct _aes_key_wrap_ctx
|
||||
{
|
||||
AES_CTX ctx;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_MD5_H
|
||||
#define __INCLUDE_CRYPTO_MD5_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MD5_BLOCK_LENGTH 64
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_POLY1305_H
|
||||
#define __INCLUDE_CRYPTO_POLY1305_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define poly1305_block_size 16
|
||||
|
||||
typedef struct poly1305_state
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_RIJNDAEL_H
|
||||
#define __INCLUDE_CRYPTO_RIJNDAEL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define AES_MAXKEYBITS (256)
|
||||
#define AES_MAXKEYBYTES (AES_MAXKEYBITS / 8)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_RMD160_H
|
||||
#define __INCLUDE_CRYPTO_RMD160_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define RMD160_BLOCK_LENGTH 64
|
||||
#define RMD160_DIGEST_LENGTH 20
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_SHA1_H
|
||||
#define __INCLUDE_CRYPTO_SHA1_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define SHA1_BLOCK_LENGTH 64
|
||||
#define SHA1_DIGEST_LENGTH 20
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_SHA2_H
|
||||
#define __INCLUDE_CRYPTO_SHA2_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* SHA-256/384/512 Various Length Definitions */
|
||||
|
||||
#define SHA256_BLOCK_LENGTH 64
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@
|
|||
#ifndef __INCLUDE_CRYPTO_SIPHASH_H_
|
||||
#define __INCLUDE_CRYPTO_SIPHASH_H_
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define SIPHASH_BLOCK_LENGTH 8
|
||||
#define SIPHASH_KEY_LENGTH 16
|
||||
#define SIPHASH_DIGEST_LENGTH 8
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <crypto/md5.h>
|
||||
#include <crypto/sha1.h>
|
||||
#include <crypto/rmd160.h>
|
||||
|
|
@ -116,6 +117,4 @@ extern const struct auth_hash auth_hash_gmac_aes_192;
|
|||
extern const struct auth_hash auth_hash_gmac_aes_256;
|
||||
extern const struct auth_hash auth_hash_chacha20_poly1305;
|
||||
|
||||
extern const struct comp_algo comp_algo_deflate;
|
||||
|
||||
#endif /* __INCLUDE_CRYPTO_XFORM_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue