Updates per PR, cleanups, and error handling.

pull/392/head
Bill Phipps 2023-07-31 16:11:33 -04:00
parent 74ede69f3e
commit 77f58467b5
7 changed files with 912 additions and 696 deletions

View File

@ -45,7 +45,7 @@ static int nativeStartup(void)
#if defined(HAVE_CCBVAULTIC) && defined(WOLF_CRYPTO_CB_CMD)
if((ret == 0) && (devId == CCBVAULTIC420_DEVID)) {
ret = wc_CryptoCb_RegisterDevice((int) devId,
ccbVaultIc_CryptoDevCb, NULL);
ccbVaultIc_CryptoCb, NULL);
}
#endif

View File

@ -9,7 +9,7 @@ LD=${NDK_LD}
WOLFSSL_DIR?=../../wolfssl
# Relative path to VaultIC dev kit source
VAULTIC_DIR?=VaultIC-TLS_420/vaultic_tls-4xx
VAULTIC_DIR?=./VaultIC-TLS_420/vaultic_tls-4xx
# Common settings and files
CFLAGS+=-I. -O2 -DHAVE_CCBVAULTIC
@ -19,7 +19,6 @@ OBJS=ccb_vaultic.o
CFLAGS+=-DCCBVAULTIC_DEBUG
CFLAGS+=-DCCBVAULTIC_DEBUG_TIMING
#CFLAGS+=-DCCBVAULTIC_DEBUG_ALL
#CFLAGS+=-DSPI_TRACE_ERRORS
# Optionally disable certain kinds of offload
#CFLAGS+=-DCCBVAULTIC_NO_AES
@ -37,6 +36,7 @@ VAULTIC_CHIP=420
CHIP_TARGET=TARGETCHIP_VAULTIC_$(VAULTIC_CHIP)
CFLAGS+= -D$(CHIP_TARGET)
CFLAGS+= -DUSE_SPI
#CFLAGS+=-DSPI_TRACE_ERRORS
VAULTIC_ELIB?=$(VAULTIC_DIR)/VaultIC-Elib_$(VAULTIC_CHIP)/src
CFLAGS+=-I$(VAULTIC_ELIB)/common
@ -52,7 +52,7 @@ CFLAGS+=-DWC_USE_DEVID=0x56490420 -DBENCH_EMBEDDED -DNO_MAIN_DRIVER
TEST_OBJS:=$(WOLFSSL_DIR)/wolfcrypt/test/test.o main-test.o
BENCH_OBJS:=$(WOLFSSL_DIR)/wolfcrypt/benchmark/benchmark.o main-bench.o
#Makefile rules
all: wolfcrypt-test wolfcrypt-benchmark
wolfcrypt-test: $(OBJS) $(TEST_OBJS)

File diff suppressed because it is too large Load Diff

View File

@ -21,14 +21,11 @@
#ifndef CCB_VAULTIC_H
#define CCB_VAULTIC_H
#include "ccb_vaultic_defs.h"
#include "wolfssl/options.h"
/* VaultIC DevID MSBs are ASCII "VI" */
#define CCBVAULTIC_DEVID (0x56490000ul)
#define CCBVAULTIC420_DEVID (CCBVAULTIC_DEVID + 0x0420)
#if !defined(WOLF_CRYPTO_CB)
#error "Missing WOLF_CRYPTO_CB. Reconfigure wolfssl with --enable-cryptocb"
#endif
#include "wolfssl/wolfcrypt/cryptocb.h"
#ifdef HAVE_CCBVAULTIC
/*
* Implementation of wolfCrypt cryptocb callbacks
@ -53,6 +50,12 @@ typedef struct {
size_t aescbc_keylen;
} ccbVaultIc_Context;
/* ccbVaultIc_Context static initializer */
#define CCBVAULTIC_CONTEXT_INITIALIZER \
{ \
.initialized = 0 \
}
/* Initialize the Wisekey VaultIC library and clear the context.
* Returns: 0 on success
* BAD_FUNC_ARGS with NULL context
@ -64,12 +67,15 @@ int ccbVaultIc_Init(ccbVaultIc_Context *c);
/* Close the Wisekey VaultIC library. */
void ccbVaultIc_Cleanup(ccbVaultIc_Context *c);
#ifdef WOLF_CRYPTO_CB
#include "wolfssl/wolfcrypt/cryptocb.h" /* For wc_CryptInfo */
/* Register this callback and associate with a context using:
* ccbVaultIc_Context ctx={0};
* ccbVaultIc_Context ctx=CCBVAULTIC_CONTEXT_INITIALIZER;
* ccbVaultIc_Init(&ctx);
* wc_CryptoCb_RegisterDevice(
* CCBVAULTIC420_DEVID,
* ccbVaultIc_CryptoDevCb,
* ccbVaultIc_CryptoCb,
* &ctx);
* wc_Aes aes={0};
* wc_AesInit(&aes, NULL, CCBVAULTIC420_DEVID);
@ -77,8 +83,11 @@ void ccbVaultIc_Cleanup(ccbVaultIc_Context *c);
* CRYPTOCB_UNAVAILABLE if not initialized or not implemented
* MEMORY_E if memory allocation fails
*/
int ccbVaultIc_CryptoDevCb(int devId,
wc_CryptoInfo* info,
void* ctx);
int ccbVaultIc_CryptoCb(int devId,
wc_CryptoInfo* info,
void* ctx);
#endif /* WOLF_CRYPTO_CB */
#endif /* HAVE_CCBVAULTIC */
#endif /* CCB_VAULTIC_H_ */

View File

@ -1,34 +0,0 @@
/*
* ccb_vaultic_defs.h
*
* Copyright (C) 2023 wolfSSL Inc.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef CCB_VAULTIC_DEFS_H
#define CCB_VAULTIC_DEFS_H
/* VaultIC DevID MSBs are ASCII "VI" */
#define CCBVAULTIC_DEVID (0x56490000ul)
#define CCBVAULTIC420_DEVID (CCBVAULTIC_DEVID + 0x0420)
/* Key/Group ID's to support temporary wolfSSL usage */
#define CCBVAULTIC_WOLFSSL_GRPID 0xBB
#define CCBVAULTIC_TMPAES_KEYID 0x01
#define CCBVAULTIC_TMPHMAC_KEYID 0x02
#define CCBVAULTIC_TMPRSA_KEYID 0x03
#endif

View File

@ -17,43 +17,98 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <stdio.h>
#ifndef WOLFSSL_USER_SETTINGS
#include "wolfssl/options.h"
#endif
#include "wolfssl/wolfcrypt/settings.h" /* For X-defines */
#include "wolfssl/options.h"
#include "wolfssl/ssl.h"
/* wolfCrypt includes */
#include "wolfssl/wolfcrypt/wc_port.h" /* For Init/Cleanup */
#ifdef WOLF_CRYPTO_CB
#include "wolfssl/wolfcrypt/cryptocb.h" /* For Register/Unregister */
#endif
#ifdef HAVE_CCBVAULTIC
#include "ccb_vaultic.h" /* For devId and cryptocb */
#endif
/* Local include */
#include "wolfcrypt/benchmark/benchmark.h"
#include "ccb_vaultic.h"
int main(int argc, char **argv)
{
(void)argc; (void)argv;
(void)argc;
(void)argv;
int rc=0;
int rc = 0;
/* Initialize wolfSSL and wolfCrypt */
rc=wolfSSL_Init();
if(rc!=WOLFSSL_SUCCESS) {
fprintf(stderr, "Failed to initialize wolfSSL: %d\n", rc);
return(rc);
/* Initialize wolfCrypt */
rc = wolfCrypt_Init();
if (rc == 0) {
#ifdef WOLF_CRYPTO_CB
/* Allocate/initialize context */
void* ctx = NULL;
#ifndef WOLF_CRYPTO_CB_CMD
/* External allocation/initialization of hardware context */
#ifdef HAVE_CCBVAULTIC
static ccbVaultIc_Context ctx_storage = CCBVAULTIC_CONTEXT_INITIALIZER;
ctx = &ctx_storage;
rc = ccbVaultIc_Init(ctx);
#else
/* Add other elif hardware here */
#endif
#endif /* WOLF_CRYPTO_CB_CMD */
if (rc == 0) {
/* Setup callback and devId */
int devId = INVALID_DEVID;
CryptoDevCallbackFunc ccb = NULL;
#ifdef HAVE_CCBVAULTIC
devId = CCBVAULTIC420_DEVID;
ccb = ccbVaultIc_CryptoCb;
#else
/* Add other elif hardware here */
#endif
/* Register cryptocb */
rc = wc_CryptoCb_RegisterDevice(
devId,
ccb,
ctx);
#endif /* WOLF_CRYPTO_CB */
if (rc == 0) {
/* Run benchmarks */
rc = benchmark_test(NULL);
#ifdef WOLF_CRYPTO_CB
/* Unregister the callback */
wc_CryptoCb_UnRegisterDevice(devId);
#endif
} else {
printf("Failed to register cryptocb:%d (%x) "\
" with devId:%x ccb:%p\n",
rc, rc, devId, ccb);
}
#ifdef WOLF_CRYPTO_CB
#ifndef WOLF_CRYPTO_CB_CMD
/* External deallocation of hardware context */
#ifdef HAVE_CCBVAULTIC
ccbVaultIc_Cleanup(ctx);
#else
/* Add other hardware cleanup here */
#endif
#endif
#endif
} else {
printf(" Failed to initialize hardware: %d (%x)\n", rc, rc);
}
wolfCrypt_Cleanup();
}else {
printf("Failed to initialize wolfCrypt: %d (%x)\n", rc, rc);
}
/* Register VaultIC as cryptocb */
rc = wc_CryptoCb_RegisterDevice(CCBVAULTIC420_DEVID,
ccbVaultIc_CryptoDevCb, NULL);
if(rc) {
fprintf(stderr, "Failed to register cryptocb: %d\n", rc);
wolfSSL_Cleanup();
return(rc);
}
/* Run benchmarks */
benchmark_test(NULL);
wc_CryptoCb_UnRegisterDevice(CCBVAULTIC420_DEVID);
wolfSSL_Cleanup();
return 0;
return rc;
}

View File

@ -17,41 +17,98 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include "wolfssl/options.h"
#ifndef WOLFSSL_USER_SETTINGS
#include "wolfssl/options.h"
#endif
#include "wolfssl/wolfcrypt/settings.h" /* For X-defines */
#include "wolfssl/ssl.h"
/* wolfCrypt includes */
#include "wolfssl/wolfcrypt/wc_port.h" /* For Init/Cleanup */
#ifdef WOLF_CRYPTO_CB
#include "wolfssl/wolfcrypt/cryptocb.h" /* For Register/Unregister */
#endif
#ifdef HAVE_CCBVAULTIC
#include "ccb_vaultic.h" /* For devId and cryptocb */
#endif
/* Local include */
#include "wolfcrypt/test/test.h"
#include <stdio.h>
#include <stdlib.h>
#include "ccb_vaultic.h"
int main(int argc, char **argv)
{
(void)argc; (void)argv;
(void)argc;
(void)argv;
int rc=0;
int rc = 0;
/* Initialize wolfSSL and wolfCrypt */
rc=wolfSSL_Init();
if(rc!=WOLFSSL_SUCCESS) {
fprintf(stderr, "Failed to initialize wolfSSL: %d\n", rc);
return(rc);
/* Initialize wolfCrypt */
rc = wolfCrypt_Init();
if (rc == 0) {
#ifdef WOLF_CRYPTO_CB
/* Allocate/initialize context */
void* ctx = NULL;
#ifndef WOLF_CRYPTO_CB_CMD
/* External allocation/initialization of hardware context */
#ifdef HAVE_CCBVAULTIC
static ccbVaultIc_Context ctx_storage = CCBVAULTIC_CONTEXT_INITIALIZER;
ctx = &ctx_storage;
rc = ccbVaultIc_Init(ctx);
#else
/* Add other elif hardware here */
#endif
#endif /* WOLF_CRYPTO_CB_CMD */
if (rc == 0) {
/* Setup callback and devId */
int devId = INVALID_DEVID;
CryptoDevCallbackFunc ccb = NULL;
#ifdef HAVE_CCBVAULTIC
devId = CCBVAULTIC420_DEVID;
ccb = ccbVaultIc_CryptoCb;
#else
/* Add other elif hardware here */
#endif
/* Register cryptocb */
rc = wc_CryptoCb_RegisterDevice(
devId,
ccb,
ctx);
#endif /* WOLF_CRYPTO_CB */
if (rc == 0) {
/* Run tests */
rc = wolfcrypt_test(NULL);
#ifdef WOLF_CRYPTO_CB
/* Unregister the callback */
wc_CryptoCb_UnRegisterDevice(devId);
#endif
} else {
printf("Failed to register cryptocb:%d (%x) "\
" with devId:%x ccb:%p\n",
rc, rc, devId, ccb);
}
#ifdef WOLF_CRYPTO_CB
#ifndef WOLF_CRYPTO_CB_CMD
/* External deallocation of hardware context */
#ifdef HAVE_CCBVAULTIC
ccbVaultIc_Cleanup(ctx);
#else
/* Add other hardware cleanup here */
#endif
#endif
#endif
} else {
printf(" Failed to initialize hardware: %d (%x)\n", rc, rc);
}
wolfCrypt_Cleanup();
}else {
printf("Failed to initialize wolfCrypt: %d (%x)\n", rc, rc);
}
/* Register VaultIC as cryptocb */
rc = wc_CryptoCb_RegisterDevice(CCBVAULTIC420_DEVID,
ccbVaultIc_CryptoDevCb, NULL);
if(rc) {
fprintf(stderr, "Failed to register cryptocb: %d\n", rc);
wolfSSL_Cleanup();
return(rc);
}
wolfcrypt_test(NULL);
wc_CryptoCb_UnRegisterDevice(CCBVAULTIC420_DEVID);
wolfSSL_Cleanup();
return 0;
return rc;
}