Skip to content

Commit

Permalink
Implement a bunch more HAL functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Jan 22, 2020
1 parent 0979543 commit 0830fd7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
22 changes: 13 additions & 9 deletions cryptoauthlib/lib/mbedtls/atca_mbedtls_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,49 @@

#include "mbedtls/pk.h"
#include "mbedtls/ecp.h"
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include "mbedtls/x509_crt.h"

/* Cryptoauthlib Includes */
#include "cryptoauthlib.h"
#include "atcacert/atcacert_client.h"
#include "atcacert/atcacert_def.h"

#if 0

#include "crypto/atca_crypto_sw_sha1.h"
#include "crypto/atca_crypto_sw_sha2.h"
#include "crypto/atca_crypto_sw_ecdsa.h"
#include "crypto/atca_crypto_sw_rand.h"

int atcac_sw_sha1(const uint8_t * data, size_t data_size, uint8_t digest[ATCA_SHA1_DIGEST_SIZE])
{

return mbedtls_sha1_ret(data, data_size, digest);
}

int atcac_sw_sha2_256_init(atcac_sha2_256_ctx* ctx)
{

mbedtls_sha256_init((mbedtls_sha256_context *) ctx);
return mbedtls_sha256_starts_ret((mbedtls_sha256_context *) ctx, 0 /* is224 */);
}

int atcac_sw_sha2_256_update(atcac_sha2_256_ctx* ctx, const uint8_t* data, size_t data_size)
{

return mbedtls_sha256_update_ret((mbedtls_sha256_context *) ctx, data, data_size);
}

int atcac_sw_sha2_256_finish(atcac_sha2_256_ctx * ctx, uint8_t digest[ATCA_SHA2_256_DIGEST_SIZE])
{

int ret = mbedtls_sha256_finish_ret((mbedtls_sha256_context *) ctx, digest);
mbedtls_sha256_free((mbedtls_sha256_context *) ctx);
return ret;
}

int atcac_sw_sha2_256(const uint8_t * data, size_t data_size, uint8_t digest[ATCA_SHA2_256_DIGEST_SIZE])
{

return mbedtls_sha256_ret(data, data_size, digest, 0 /* is224 */);
}

#if 0
int atcac_sw_ecdsa_verify_p256(const uint8_t msg[ATCA_ECC_P256_FIELD_SIZE],
const uint8_t signature[ATCA_ECC_P256_SIGNATURE_SIZE],
const uint8_t public_key[ATCA_ECC_P256_PUBLIC_KEY_SIZE])
Expand All @@ -94,7 +98,6 @@ int atcac_sw_random(uint8_t* data, size_t data_size)
{

}

#endif

/** \brief Initializes an mbedtls pk context for use with EC operations
Expand Down Expand Up @@ -154,6 +157,7 @@ int atca_mbedtls_pk_init(mbedtls_pk_context * pkey, const uint16_t slotid)
return ret;
}

#if 0
/** \brief Rebuild a certificate from an atcacert_def_t structure, and then add
* it to an mbedtls cert chain.
* \param[in,out] cert mbedtls cert chain. Must have already been initialized
Expand Down Expand Up @@ -203,4 +207,4 @@ int atca_mbedtls_cert_add(mbedtls_x509_crt * cert, const atcacert_def_t * cert_d

return ret;
}

#endif
1 change: 1 addition & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sources:
- cryptoauthlib/lib
- cryptoauthlib/lib/basic
- cryptoauthlib/lib/host
- cryptoauthlib/lib/mbedtls/atca_mbedtls_wrap.c

includes:
- include
Expand Down
18 changes: 14 additions & 4 deletions src/mgos_atca_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,20 @@ ATCA_STATUS hal_iface_release(ATCAIfaceType ifacetype, void *hal_data) {
return ATCA_SUCCESS;
}

int atcac_sw_sha2_256(const uint8_t *data, size_t data_size,
uint8_t digest[32]) {
mbedtls_sha256(data, data_size, digest, false /* is_224 */);
return 0;
ATCA_STATUS hal_i2c_discover_buses(int i2c_buses[], int max_buses) {
for (int i = 0; i < max_buses; i++) {
i2c_buses[i] = (mgos_i2c_get_bus(i) != NULL ? i : -1);
}
return ATCA_SUCCESS;
}

ATCA_STATUS hal_i2c_discover_devices(int bus_num, ATCAIfaceCfg *cfg,
int *found) {
*found = 0;
if (bus_num < 0) return ATCA_BAD_PARAM;
// TODO
(void) cfg;
return ATCA_SUCCESS;
}

void atca_delay_ms(uint32_t delay) {
Expand Down

0 comments on commit 0830fd7

Please sign in to comment.