Skip to content

Commit

Permalink
[#144] Updates to crypto_config.c to autodetermine crypto module in u…
Browse files Browse the repository at this point in the history
…se and added CMAC and SIV build flags to WolfSSL docker build;
  • Loading branch information
jlucas9 committed Sep 21, 2023
1 parent bc252d1 commit c7e203c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 34 deletions.
26 changes: 10 additions & 16 deletions src/core/crypto_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,22 @@ int32_t Crypto_Init(void)
} // TODO: Error stack

/* Crypto Interface */
// Prepare Cryptographic Library from config
if(crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_LIBGCRYPT)
// Determine which cryptographic module is in use
cryptography_if = get_cryptography_interface_libgcrypt();
if (cryptography_if == NULL)
{
cryptography_if = get_cryptography_interface_libgcrypt();
cryptography_if = get_cryptography_interface_wolfssl();
}
else if(crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_KMCCRYPTO)
{
if (cryptography_kmc_crypto_config == NULL)
if (cryptography_if == NULL)
{ // Note this needs to be the last option in the chain due to addition configuration required
if (cryptography_kmc_crypto_config != NULL)
{
status = CRYPTOGRAPHY_KMC_CRYPTO_SERVICE_CONFIGURATION_NOT_COMPLETE;
printf(KRED "ERROR: CryptoLib KMC Crypto Service Interface must be configured before intializing!\n" RESET);
return status;
cryptography_if = get_cryptography_interface_kmc_crypto_service();
}
cryptography_if = get_cryptography_interface_kmc_crypto_service();
}
else if(crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_WOLFSSL)
{
cryptography_if = get_cryptography_interface_wolfssl();
}
else
if (cryptography_if == NULL)
{
printf("Fatal Error: Unable to identify Cryptography Interface!\n");
status = CRYPTOGRAPHY_INVALID_CRYPTO_INTERFACE_TYPE;
return status;
}
Expand All @@ -241,7 +236,6 @@ int32_t Crypto_Init(void)
return status;
}


// Init Security Associations
status = sa_if->sa_init();
if (status==CRYPTO_LIB_SUCCESS)
Expand Down
5 changes: 1 addition & 4 deletions src/crypto/kmc_stub/cryptography_interface_kmc.stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

#include "cryptography_interface.h"

static CryptographyInterfaceStruct cryptography_if;

CryptographyInterface get_cryptography_interface_kmc_crypto_service(void)
{
fprintf(stderr,"ERROR: Loading KMC Crypto Service cryptography interface stub source code. Rebuild CryptoLib with -DKMCCRYPTO=ON to use proper KMC Crytpo Service implementation.\n");
return &cryptography_if;
return NULL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

#include "cryptography_interface.h"

static CryptographyInterfaceStruct cryptography_if;

CryptographyInterface get_cryptography_interface_libgcrypt(void)
{
fprintf(stderr,"ERROR: Loading libgcrypt cryptography interface stub source code. Rebuild CryptoLib with -DCRYPTO_LIBGCRYPT=ON to use proper libgcrypt implementation.\n");
return &cryptography_if;
return NULL;
}
7 changes: 2 additions & 5 deletions src/crypto/wolfssl/cryptography_interface_wolfssl.template.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out,
uint8_t ecs, uint8_t acs, char* cam_cookies)
{
int32_t status = CRYPTO_LIB_SUCCESS;
//int32_t tmp;
uint32_t tmp;
Cmac cmac;
Hmac hmac;

// Unused in this implementation
Expand All @@ -170,8 +171,6 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out,
{
// Reference: https://www.wolfssl.com/documentation/manuals/wolfssl/group__CMAC.html
case CRYPTO_MAC_CMAC_AES256:
/*
Cmac cmac;
status = wc_InitCmac(&cmac, key, len_key, WC_CMAC_AES, NULL);
if (status == 0)
{
Expand All @@ -185,8 +184,6 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out,
{
status = wc_CmacFinal(&cmac, mac, &tmp);
}
*/
status = CRYPTO_LIB_ERR_UNSUPPORTED_ACS;
break;

// Reference: https://www.wolfssl.com/documentation/manuals/wolfssl/group__HMAC.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

#include "cryptography_interface.h"

static CryptographyInterfaceStruct cryptography_if;

CryptographyInterface get_cryptography_interface_wolfssl(void)
{
fprintf(stderr,"ERROR: Loading WolfSSL cryptography interface stub source code. Rebuild CryptoLib with -DCRYPTO_WOLFSSL=ON to use proper WolfSSL implementation.\n");
return &cryptography_if;
return NULL;
}
2 changes: 1 addition & 1 deletion support/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RUN cd /tmp \

RUN mkdir /tmp/wolfssl/build \
&& cd /tmp/wolfssl/build \
&& cmake -DCMAKE_C_FLAGS="-DWOLFSSL_AESGCM_STREAM" .. \
&& cmake -DWOLFSSL_AESCCM=yes -DWOLFSSL_AESSIV=yes -DWOLFSSL_CMAC=yes .. \
&& make install \
&& rm -rf /tmp/wolfssl

Expand Down

0 comments on commit c7e203c

Please sign in to comment.