OpenSSL ECC Engine  1.0
OpenSSL Engine implementation using ATECC508 for ECC key storage and ECDSA, ECDH, and RNG.
Macros | Functions | Variables
eccx08_common.c File Reference

Implementation of OpenSSL ENGINE callback functions for ECC See reference code in ec_pmeth.c. More...

#include <stdint.h>
#include <assert.h>
#include <stdarg.h>
#include <openssl/engine.h>
#include <openssl/ec.h>
#include <crypto/ec/ec_lcl.h>
#include <crypto/evp/evp.h>
#include <crypto/evp/evp_locl.h>
#include <crypto/asn1/asn1_locl.h>
#include <crypto/ossl_typ.h>
#include "ecc_meth.h"
#include "platform.h"

Macros

#define KEY_FORMAT_VERSION   (1)
 

Functions

ATCA_STATUS eccx08_get_enc_key (uint8_t *enckey, int16_t keysize)
 A user defined function that fills a raw buffer (32 bytes) with the platform-specific encryption key. More...
 
int eccx08_eckey_fill_key (char *ptr, int size, uint8_t slot_id, uint8_t *serial_number, int serial_len)
 Fills a raw buffer (32 bytes) with data to save into the private key structure. More...
 
int eccx08_eckey_encode_in_privkey (EC_KEY *eckey, uint8_t slot_id, uint8_t *serial_number, int serial_len)
 Converts 32 bytes from ATECC508 format to the openssl EC_KEY structure. It allocates EC_KET structure and does not free it (must be a caller to free) More...
 
int eccx08_eckey_compare_privkey (EC_KEY *eckey, uint8_t slot_id, uint8_t *serial_number, int serial_len)
 Checks if the private key in the openssl EC_KEY structure corresponds to the private key in the ATECCCX08 slot. More...
 
int eccx08_generate_key (EC_KEY *eckey, uint8_t *serial_number, int serial_len)
 Generates a 32-byte private key then replaces it with token data using the eccx08_eckey_encode_in_privkey() call. More...
 
int eccx08_eckey_convert (EC_KEY **p_eckey, uint8_t *raw_pubkey, uint8_t *serial_number, int serial_len)
 Converts raw 64 bytes of public key (ATECC508 format) to the openssl EC_KEY structure. It allocates EC_KEY structure and does not free it (must be a caller to free) More...
 
int eccx08_BN_encrypt (BIGNUM *number, uint8_t *iv, uint8_t *aes_key)
 Encrypt a BIGNUM data using AES-256 OFB mode. More...
 
int eccx08_BN_decrypt (BIGNUM *number, uint8_t *iv, uint8_t *aes_key)
 Decrypt a BIGNUM data using AES-256 OFB mode. Assuming that data there was encrypted using the eccx08_BN_encrypt(). More...
 
int eccx08_debug (const char *fmt,...)
 

Variables

uint8_t test_priv_key [MEM_BLOCK_SIZE]
 
uint8_t test_pub_key [MEM_BLOCK_SIZE *2]
 

Detailed Description

Implementation of OpenSSL ENGINE callback functions for ECC See reference code in ec_pmeth.c.

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

Function Documentation

int eccx08_BN_decrypt ( BIGNUM *  number,
uint8_t *  iv,
uint8_t *  aes_key 
)

Decrypt a BIGNUM data using AES-256 OFB mode. Assuming that data there was encrypted using the eccx08_BN_encrypt().

Parameters
int eccx08_BN_encrypt ( BIGNUM *  number,
uint8_t *  iv,
uint8_t *  aes_key 
)

Encrypt a BIGNUM data using AES-256 OFB mode.

Parameters
int eccx08_eckey_compare_privkey ( EC_KEY *  eckey,
uint8_t  slot_id,
uint8_t *  serial_number,
int  serial_len 
)

Checks if the private key in the openssl EC_KEY structure corresponds to the private key in the ATECCCX08 slot.

eccx08_eckey_compare_privkey()

Parameters
[in,out]eckeyPointer to EC_KEY with Private key token on success
[in]slot_idATECCX08 slot ID
[in]serial_number9 bytes of ATECCX08 serial number
[in]serial_lenSize of the ATECCX08 serial number buffer
Returns
1 on success, 0 on error
int eccx08_eckey_convert ( EC_KEY **  p_eckey,
uint8_t *  raw_pubkey,
uint8_t *  serial_number,
int  serial_len 
)

Converts raw 64 bytes of public key (ATECC508 format) to the openssl EC_KEY structure. It allocates EC_KEY structure and does not free it (must be a caller to free)

eccx08_eckey_convert()

Parameters
[out]p_eckeyPointer to EC_KEY with Public Key on success
[in]raw_pubkeyRaw public key, 64 bytes length 32-byte X following with 32-byte Y
[in]serial_number9 bytes of ATECCX08 serial number
[in]serial_lenSize of the ATECCX08 serial number buffer
Returns
1 on success, 0 on error
int eccx08_eckey_encode_in_privkey ( EC_KEY *  eckey,
uint8_t  slot_id,
uint8_t *  serial_number,
int  serial_len 
)

Converts 32 bytes from ATECC508 format to the openssl EC_KEY structure. It allocates EC_KET structure and does not free it (must be a caller to free)

eccx08_eckey_encode_in_privkey()

Parameters
int eccx08_eckey_fill_key ( char *  ptr,
int  size,
uint8_t  slot_id,
uint8_t *  serial_number,
int  serial_len 
)

Fills a raw buffer (32 bytes) with data to save into the private key structure.

eccx08_eckey_fill_key()

Parameters
[in,out]ptrPointer to a buffer to fill the key data
[in]slot_idATECCX08 slot ID
[in]serial_number9 bytes of ATECCX08 serial number
[in]serial_lenSize of the ATECCX08 serial number buffer
Returns
1 on success, 0 on error
int eccx08_generate_key ( EC_KEY *  eckey,
uint8_t *  serial_number,
int  serial_len 
)

Generates a 32-byte private key then replaces it with token data using the eccx08_eckey_encode_in_privkey() call.

eccx08_generate_key()

Parameters
[out]p_eckeyPointer to EC_KEY with Public Key on success
[in]serial_number9 bytes of ATECCX08 serial number
[in]serial_lenSize of the ATECCX08 serial number buffer
Returns
1 on success, 0 on error
ATCA_STATUS eccx08_get_enc_key ( uint8_t *  enckey,
int16_t  keysize 
)

A user defined function that fills a raw buffer (32 bytes) with the platform-specific encryption key.

USER: Platform needs to to provide secure storage for this encryption key

Parameters
[in,out]enckeyPointer to a buffer to fill with the encryption key data
[in]keysizeThe size of the enckey buffer (number of bytes should be MEM_BLOCK_SIZE)
Returns
1 on success, 0 on error

Variable Documentation

uint8_t test_priv_key[MEM_BLOCK_SIZE]
Initial value:
= {
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
0x27, 0x28, 0x29, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42,
}
uint8_t test_pub_key[MEM_BLOCK_SIZE *2]
Initial value:
= {
0xe9, 0xb8, 0x91, 0x9f, 0x3d, 0x76, 0x4a, 0x26, 0xa4, 0xa8, 0xf6, 0x2b, 0x53, 0xbe, 0xd7, 0xe3,
0x14, 0x46, 0x33, 0xdd, 0xf2, 0x64, 0x98, 0xd0, 0xe9, 0x85, 0x70, 0xab, 0xe5, 0xb3, 0x06, 0xfd,
0xdf, 0x91, 0x63, 0x84, 0x71, 0x7d, 0xdc, 0x68, 0x05, 0x79, 0x12, 0x86, 0x30, 0x73, 0xc5, 0x77,
0xc5, 0xb3, 0x73, 0x95, 0x8b, 0x95, 0xaf, 0xd5, 0x49, 0x1f, 0x9f, 0x82, 0xe4, 0xeb, 0x77, 0x86,
}