CryptoAuthLib
Atmel CryptoAuthentication Library
atcatls.c File Reference

Collection of functions for hardware abstraction of TLS implementations (e.g. OpenSSL) More...

#include <stdlib.h>
#include <stdio.h>
#include "atcatls.h"
#include "atcatls_cfg.h"
#include "basic/atca_basic.h"
#include "atcacert/atcacert_client.h"
#include "atcacert/atcacert_host_hw.h"

Macros

#define RSA_KEY_SLOT   8
 
#define RSA_KEY_START_BLOCK   5
 

Functions

ATCA_STATUS atcatls_config_default ()
 Configure the ECC508 for use with TLS API funcitons. The configuration zone is written and locked. All GenKey and slot initialization is done and then the data zone is locked. This configuration needs to be performed before the TLS API functions are called On a locked ECC508 device, this function will check the configuraiton against the default and fail if it does not match. More...
 
ATCA_STATUS atcatls_init (ATCAIfaceCfg *pCfg)
 Initialize the ECC508 for use with the TLS API. Like a constructor. More...
 
ATCA_STATUS atcatls_finish ()
 Finalize the ECC508 when finished. Like a destructor. More...
 
ATCA_STATUS atcatls_sign (uint8_t slotid, const uint8_t *message, uint8_t *signature)
 Sign the message with the specified slot and return the signature. More...
 
ATCA_STATUS atcatls_verify (const uint8_t *message, const uint8_t *signature, const uint8_t *pubkey, bool *verified)
 Verify the signature of the specified message using the specified public key. More...
 
ATCA_STATUS atcatls_verify_cert (const atcacert_def_t *cert_def, const uint8_t *cert, size_t cert_size, const uint8_t *ca_public_key)
 Verify a certificate against its certificate authority's public key. More...
 
ATCA_STATUS atcatls_ecdh (uint8_t slotid, const uint8_t *pubkey, uint8_t *pmk)
 Generate a pre-master key (pmk) given a private key slot and a public key that will be shared with. More...
 
ATCA_STATUS atcatls_ecdh_enc (uint8_t slotid, uint8_t enckeyId, const uint8_t *pubkey, uint8_t *pmk)
 Generate a pre-master key (pmk) given a private key slot and a public key that will be shared with. More...
 
ATCA_STATUS atcatls_ecdhe (uint8_t slotid, const uint8_t *pubkey, uint8_t *pubkeyret, uint8_t *pmk)
 Generate a pre-master key (pmk) given a private key slot and a public key that will be shared with. More...
 
ATCA_STATUS atcatls_create_key (uint8_t slotid, uint8_t *pubkey)
 Create a unique public-private key pair in the specified slot. More...
 
ATCA_STATUS atcatls_calc_pubkey (uint8_t slotid, uint8_t *pubkey)
 Get the public key from the specified private key slot. More...
 
ATCA_STATUS atcatls_read_pubkey (uint8_t slotid, uint8_t *pubkey)
 reads a pub key from a readable data slot versus atcab_get_pubkey which generates a pubkey from a private key slot More...
 
ATCA_STATUS atcatls_random (uint8_t *randout)
 Get a random number. More...
 
ATCA_STATUS atcatlsfn_set_get_enckey (atcatlsfn_get_enckey *fn_get_enckey)
 Set the function used to retrieve the unique encryption key for this platform. More...
 
ATCA_STATUS atcatls_init_enckey (uint8_t *enckeyout, uint8_t enckeyId, bool lock)
 Initialize the unique encryption key for this platform. Write a random number to the parent encryption key slot Return the random number for storage on platform. More...
 
ATCA_STATUS atcatls_set_enckey (uint8_t *enckeyin, uint8_t enckeyId, bool lock)
 Initialize the unique encryption key for this platform Write the provided encryption key to the parent encryption key slot Function optionally lock the parent encryption key slot after it is written. More...
 
ATCA_STATUS atcatls_get_enckey (uint8_t *enckeyout)
 Return the random number for storage on platform. This function reads from platform storage, not the ECC508 device Therefore, the implementation is platform specific and must be provided at integration. More...
 
ATCA_STATUS atcatls_enc_read (uint8_t slotid, uint8_t block, uint8_t enckeyId, uint8_t *data, int16_t *bufsize)
 Read encrypted bytes from the specified slot. More...
 
ATCA_STATUS atcatls_enc_write (uint8_t slotid, uint8_t block, uint8_t enckeyId, uint8_t *data, int16_t bufsize)
 Write encrypted bytes to the specified slot. More...
 
ATCA_STATUS atcatls_enc_rsakey_read (uint8_t enckeyId, uint8_t *rsakey, int16_t *keysize)
 
ATCA_STATUS atcatls_enc_rsakey_write (uint8_t enckeyId, uint8_t *rsakey, int16_t keysize)
 
ATCA_STATUS atcatls_get_signer_cert (uint8_t *certout, size_t *certsize)
 Get the certificate. More...
 
ATCA_STATUS atcatls_get_device_cert (uint8_t *certout, size_t *certsize)
 Get the certificate. More...
 
ATCA_STATUS atcatls_get_ca_cert (uint8_t *certout, size_t *certsize)
 Get the certificate. More...
 
ATCA_STATUS atcatls_write_pubkey (uint8_t slotid, uint8_t caPubkey[PUB_KEY_SIZE], bool lock)
 
ATCA_STATUS atcatls_read_ca_pubkey (uint8_t caPubkey[PUB_KEY_SIZE])
 
ATCA_STATUS atcatls_get_cert (const atcacert_def_t *cert_def, const uint8_t *ca_public_key, uint8_t *certout, size_t *certsize)
 Get the certificate of der format. More...
 
ATCA_STATUS atcatls_get_sn (uint8_t sn_out[ATCA_SERIAL_NUM_SIZE])
 Get the serial number of this device. More...
 

Variables

uint8_t _enckey [ATCA_KEY_SIZE] = { 0 }
 
atcatlsfn_get_enckey_fn_get_enckey = NULL
 
uint8_t g_CaCert []
 
uint8_t g_SignerCert []
 
uint8_t g_DeviceCert []
 
uint8_t config_data_default []
 

Detailed Description

Collection of functions for hardware abstraction of TLS implementations (e.g. OpenSSL)

Copyright (c) 2015 Atmel Corporation. All rights reserved.

Macro Definition Documentation

#define RSA_KEY_SLOT   8
#define RSA_KEY_START_BLOCK   5

Variable Documentation

uint8_t _enckey[ATCA_KEY_SIZE] = { 0 }
atcatlsfn_get_enckey* _fn_get_enckey = NULL
uint8_t config_data_default[]
uint8_t g_CaCert[]
uint8_t g_DeviceCert[]
Initial value:
=
{
0x30, 0x82, 0x01, 0xA8, 0x30, 0x82, 0x01, 0x4E, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0A, 0x40,
0x01, 0x23, 0x80, 0x4C, 0xD9, 0x2C, 0xA5, 0x71, 0xEE, 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48,
0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30, 0x48, 0x31, 0x1A, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x0A,
0x0C, 0x11, 0x41, 0x74, 0x6D, 0x65, 0x6C, 0x20, 0x4F, 0x70, 0x65, 0x6E, 0x53, 0x53, 0x4C, 0x20,
0x44, 0x65, 0x76, 0x31, 0x2A, 0x30, 0x28, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x21, 0x4F, 0x70,
0x65, 0x6E, 0x53, 0x53, 0x4C, 0x20, 0x44, 0x65, 0x76, 0x20, 0x41, 0x54, 0x45, 0x43, 0x43, 0x35,
0x30, 0x38, 0x41, 0x20, 0x53, 0x69, 0x67, 0x6E, 0x65, 0x72, 0x20, 0x31, 0x30, 0x30, 0x31, 0x30,
0x20, 0x17, 0x0D, 0x31, 0x35, 0x31, 0x31, 0x31, 0x32, 0x31, 0x36, 0x30, 0x30, 0x30, 0x30, 0x5A,
0x18, 0x0F, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39,
0x5A, 0x30, 0x43, 0x31, 0x1A, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x11, 0x41, 0x74,
0x6D, 0x65, 0x6C, 0x20, 0x4F, 0x70, 0x65, 0x6E, 0x53, 0x53, 0x4C, 0x20, 0x44, 0x65, 0x76, 0x31,
0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x1C, 0x4F, 0x70, 0x65, 0x6E, 0x53, 0x53,
0x4C, 0x20, 0x44, 0x65, 0x76, 0x20, 0x41, 0x54, 0x45, 0x43, 0x43, 0x35, 0x30, 0x38, 0x41, 0x20,
0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00,
0x04, 0xA7, 0x15, 0xDE, 0x0C, 0x04, 0x16, 0x6D, 0xF3, 0xCF, 0x7D, 0x85, 0x5E, 0x3A, 0xD5, 0x74,
0x02, 0xE6, 0x67, 0xF7, 0xFB, 0x64, 0x22, 0x92, 0x9A, 0xF5, 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