Improve keyId logic. Fix minor compile warnings. Change `wc_se050_set_config` to match naming convention of other function in port.

pull/4322/head
David Garske 2021-10-04 13:40:24 -07:00
parent 09ce1e3c5f
commit 0c1d12c224
3 changed files with 30 additions and 33 deletions

View File

@ -74,7 +74,7 @@ sss_session_t *pSession2 = (sss_session_t *)&pCtx->session;
sss_key_store_t *pHostSession = (sss_key_store_t *)&pCtx->host_ks;
LOG_I("running setconfig");
ret = wc_se050_SetConfig(pSession2, pHostSession);
ret = wc_se050_set_config(pSession2, pHostSession);
if (ret != 0) {
return kStatus_SSS_Fail;
}
@ -87,7 +87,7 @@ return status;
Note: `wolfcrypt_test(NULL);` can be replaced with `benchmark_test();`
The two variables used in `wc_se050_SetConfig` are session and key store variables that are required to reference parts of the hardware.
The two variables used in `wc_se050_set_config` are session and key store variables that are required to reference parts of the hardware.
The Makefile needs to be edited. At the top of the Makefile, the base wolfssl directory needs to be added to `INCLUDE_FLAGS`.

View File

@ -70,7 +70,7 @@ static sss_session_t *cfg_se050_i2c_pi;
static sss_key_store_t *hostKeyStore;
static sss_key_store_t *keyStore;
int wc_se050_SetConfig(sss_session_t *pSession, sss_key_store_t *pHostKeyStore,
int wc_se050_set_config(sss_session_t *pSession, sss_key_store_t *pHostKeyStore,
sss_key_store_t *pKeyStore)
{
WOLFSSL_MSG("Setting SE050 session configuration");
@ -95,7 +95,7 @@ int wc_se050_init(const char* portName)
status = ex_sss_boot_open(&pCtx, portName);
if (status == kStatus_SSS_Success) {
ret = wc_se050_SetConfig(&pCtx.session,
ret = wc_se050_set_config(&pCtx.session,
#if SSS_HAVE_HOSTCRYPTO_ANY
&pCtx.host_ks,
#else
@ -114,37 +114,23 @@ int se050_allocate_key(int keyType)
{
int keyId = 0;
static int keyId_allocator = 100;
switch(keyType) {
#ifndef SE050_KEYID_AES
switch (keyType) {
case SE050_AES_KEY:
keyId = SE050_AES_KEYID;
keyId = SE050_KEYID_AES;
break;
#endif
#ifndef SE050_KEYID_ECC_SIGN
case SE050_ECC_SIGN:
keyId = SE050_ECC_SIGN_KEYID;
keyId = SE050_KEYID_ECC_SIGN;
break;
#endif
#ifndef SE050_KEYID_ECC_VERIFY
case SE050_ECC_VERIFY:
keyId = SE050_ECC_VERIFY_KEYID;
keyId = SE050_KEYID_ECC_VERIFY;
break;
#endif
#ifndef SE050_KEYID_ED25519
case SE050_ED25519:
keyId = SE050_ED25519_KEYID;
keyId = SE050_KEYID_ED25519;
break;
#endif
case SE050_KEYID_ANY:
keyId = keyId_allocator++;
break;
}
return keyId;
}
@ -489,7 +475,7 @@ int se050_ecc_sign_hash_ex(const byte* in, word32 inLen, byte* out,
size_t outLenSz = (size_t)*outLen;
status = sss_asymmetric_sign_digest(&ctx_asymm, (uint8_t *)in, inLen,
out, &outLenSz);
*outLen = outLenSz;
*outLen = (word32)outLenSz;
}
sss_asymmetric_context_free(&ctx_asymm);
@ -596,7 +582,7 @@ int se050_ecc_verify_hash_ex(const byte* hash, word32 hashLen, byte* signature,
key->keyId = keyId;
}
/* this is run after a sign function has taken place */
else if (key->keyId != 0) {
else {
status = sss_key_store_context_init(&host_keystore, cfg_se050_i2c_pi);
if (status == kStatus_SSS_Success) {
@ -819,7 +805,7 @@ int se050_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key,
size_t outlenSz = (size_t)*outlen;
status = sss_key_store_get_key(hostKeyStore, &deriveKey, out, &outlenSz,
&ecdhKeyBitLen);
*outlen = outlenSz;
*outlen = (word32)outlenSz;
}
if (ctx_derive_key.session != NULL)
sss_derive_key_context_free(&ctx_derive_key);
@ -962,8 +948,10 @@ int se050_ed25519_sign_msg(const byte* in, word32 inLen, byte* out,
}
if (status == kStatus_SSS_Success) {
size_t outlenSz = (size_t)*outLen;
status = sss_se05x_asymmetric_sign((sss_se05x_asymmetric_t *)&ctx_asymm,
(uint8_t *)in, inLen, out, outLen);
(uint8_t *)in, inLen, out, &outlenSz);
*outLen = (word32)outlenSz;
}
sss_asymmetric_context_free(&ctx_asymm);

View File

@ -43,17 +43,26 @@
#endif
#define SE050_AES_KEYID 55
#define SE050_ECC_SIGN_KEYID 56
#define SE050_ECC_VERIFY_KEYID 57
#define SE050_ED25519_KEYID 58
/* Default key ID's */
#ifndef SE050_KEYID_AES
#define SE050_KEYID_AES 55
#endif
#ifndef SE050_KEYID_ECC_SIGN
#define SE050_KEYID_ECC_SIGN 56
#endif
#ifndef SE050_KEYID_ECC_VERIFY
#define SE050_KEYID_ECC_VERIFY 57
#endif
#ifndef SE050_KEYID_ED25519
#define SE050_KEYID_ED25519 58
#endif
enum {
SSS_BLOCK_SIZE = 512
};
enum se050KeyType {
enum SE050KeyType {
SE050_KEYID_ANY,
SE050_AES_KEY,
SE050_ECC_SIGN,
@ -70,7 +79,7 @@ typedef struct {
} SE050_HASH_Context;
/* Public Functions */
WOLFSSL_API int wc_se050_SetConfig(sss_session_t *pSession,
WOLFSSL_API int wc_se050_set_config(sss_session_t *pSession,
sss_key_store_t *pHostKeyStore, sss_key_store_t *pKeyStore);
#ifdef WOLFSSL_SE050_INIT
WOLFSSL_API int wc_se050_init(const char* portName);