-
Notifications
You must be signed in to change notification settings - Fork 3k
Develop support for Atmel crypto engine ATCAECC508A #6104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
0xc0170
merged 32 commits into
ARMmbed:feature-opaque-keys
from
mazimkhan:atecc508a_se_dev
Feb 26, 2018
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a57f543
Develop support for Atmel crypto engine ATCAECC508A
feb08db
Add function comments and restructure device factory class
6e39a6c
Fixups after code restructure
d6c2b9c
Add missing ATCAFactory destructor
9a46c6d
Rename ATCA.h/c to ATCAFactory.h/c
3004483
Method for creating transparent pk context from HW engine
c3e9538
Fetch ECP PK info via API
0a9066f
Fix README extension
a413ad8
First draft of README
mazimkhan 5783fa7
Add steps to generate server certificate.
mazimkhan b1329cf
Complete README with SSL sample setup.
mazimkhan 58a72c3
Minor fixes and rework
9e16c31
Change ATCA_ERR_NO_ERROR to ATCA_SUCCESS
b69e999
Incorporate code review comments
4fed598
Calculate configuration zone CRC with device specific data.
deea022
Changes after basing with mbedtls:feature-opaque-keys branch
a3e9ac8
Change ATCA_ERR_SMALL_BUFFER to ATCA_ERR_BUFFER_TOO_SMALL
34185c3
Correct names where appropriate 'asn format'->'EC octet string'
123061b
Initialize pk context with API and return library error codes
81ce174
Improve comment explaining first 16 bytes of the sample configuration
2c1f903
Merge branch 'feature-opaque-keys' of github.com:ARMmbed/mbed-os into…
04369ac
Disable ATCAECC508A commission app in mbed_lib.json
54d1c9c
Add check for I2C dependency
7052a84
Add I2C pin names for NUMAKER_PFM_NUC472
02aaa63
Add check for ethernet dependency
e52971a
Add I2C pin names for NRF 52840 and 52832
6510453
Add I2C pin names for Maxim targets
4668930
Enable feature only for K64F
f4efd98
Check if mbedtls is enabled
100399f
Fix doxygen comments
d55a3b1
Guard I2C use under DEVICE_I2C
e4c8c48
Conditionally delete I2C pointer
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2018 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "ATCAConfig.h" | ||
|
||
ATCAError SlotConfig::EnableGenKey() | ||
{ | ||
if (!IsPrivKey()) | ||
return ATCA_ERR_SLOT_NOT_PRIV_KEY; | ||
_register = (_register & ~SLOT_CONFIG_WRITE_CONFIG_MASK) | SLOT_CONFIG_GEN_KEY_ENABLE_FLAG; | ||
return ATCA_SUCCESS; | ||
} | ||
|
||
void SlotConfig::SetAsPrivKey() | ||
{ | ||
/* Declare ECC Private key */ | ||
_register |= SLOT_CONFIG_IS_SECRET_MASK; | ||
/* Disable reads */ | ||
_register &= ~SLOT_CONFIG_ENCRYPT_READ_MASK; | ||
} | ||
|
||
void SlotConfig::EnableExtMsgSig() | ||
{ | ||
/* Disable ECDH operations and internal signatures */ | ||
_register &= ~SLOT_CONFIG_READ_KEY_MASK; | ||
/* Enable signing of arbitrary external messages */ | ||
_register |= SLOT_CONFIG_INT_SIG_FLAG; | ||
_register |= SLOT_CONFIG_EXT_SIG_FLAG; | ||
} | ||
|
||
bool SlotConfig::GenKeyEnabled() | ||
{ | ||
return ( (_register & SLOT_CONFIG_WRITE_CONFIG_MASK) == SLOT_CONFIG_GEN_KEY_ENABLE_FLAG); | ||
} | ||
|
||
bool SlotConfig::IsPrivKey() | ||
{ | ||
return (_register & SLOT_CONFIG_IS_SECRET_MASK) == SLOT_CONFIG_IS_SECRET_MASK && | ||
(_register & SLOT_CONFIG_ENCRYPT_READ_MASK) == 0; | ||
} | ||
|
||
|
||
ATCAError KeyConfig::SetECCKeyType() | ||
{ | ||
_register &= ~KEY_CONFIG_KEY_TYPE_MASK; | ||
_register |= KEY_CONFIG_P256_ECC_KEY; | ||
return ATCA_SUCCESS; | ||
} | ||
|
||
ATCAError KeyConfig::SetNonECCKeyType() | ||
{ | ||
_register &= ~KEY_CONFIG_KEY_TYPE_MASK; | ||
_register |= KEY_CONFIG_NON_ECC_KEY; | ||
return ATCA_SUCCESS; | ||
} | ||
|
||
ATCAError KeyConfig::EnablePubKeyGen() | ||
{ | ||
if (!IsPrivate()) | ||
return ATCA_ERR_SLOT_NOT_PRIV_KEY; | ||
_register |= KEY_CONFIG_EN_PUB_KEY_MASK; | ||
return ATCA_SUCCESS; | ||
} | ||
|
||
void KeyConfig::SetPrivate() | ||
{ | ||
_register |= KEY_CONFIG_PRIVATE_KEY_MASK; | ||
} | ||
|
||
bool KeyConfig::IsECCKey() | ||
{ | ||
return ( (_register & KEY_CONFIG_P256_ECC_KEY) == KEY_CONFIG_P256_ECC_KEY); | ||
} | ||
|
||
bool KeyConfig::PubKeyGenEnabled() | ||
{ | ||
return ( (_register & KEY_CONFIG_EN_PUB_KEY_MASK) == KEY_CONFIG_EN_PUB_KEY_MASK); | ||
} | ||
|
||
bool KeyConfig::IsPrivate() | ||
{ | ||
return ( (_register & KEY_CONFIG_PRIVATE_KEY_MASK) == KEY_CONFIG_PRIVATE_KEY_MASK); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2018 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef ATCACONFIG_H | ||
#define ATCACONFIG_H | ||
|
||
#include <stdint.h> | ||
#include "ATCAError.h" | ||
|
||
/* Field masks */ | ||
#define SLOT_CONFIG_WRITE_CONFIG_MASK 0xF000 | ||
#define SLOT_CONFIG_IS_SECRET_MASK 0x0080 | ||
#define SLOT_CONFIG_ENCRYPT_READ_MASK 0x0040 | ||
#define SLOT_CONFIG_READ_KEY_MASK 0x000F | ||
|
||
#define KEY_CONFIG_KEY_TYPE_MASK 0x001C | ||
#define KEY_CONFIG_PRIVATE_KEY_MASK 0x0001 | ||
#define KEY_CONFIG_EN_PUB_KEY_MASK 0x0002 | ||
|
||
/* Configuration flags */ | ||
#define SLOT_CONFIG_GEN_KEY_ENABLE_FLAG 0x2000 | ||
#define SLOT_CONFIG_INT_SIG_FLAG 0x0002 | ||
#define SLOT_CONFIG_EXT_SIG_FLAG 0x0001 | ||
|
||
#define KEY_CONFIG_P256_ECC_KEY 0x0010 | ||
#define KEY_CONFIG_NON_ECC_KEY 0x001C | ||
|
||
/** class for validating and preparing slot config for a data zone. | ||
*/ | ||
class SlotConfig | ||
{ | ||
private: | ||
uint16_t _register; | ||
public: | ||
SlotConfig(uint16_t slot_config) | ||
: _register(slot_config) | ||
{} | ||
SlotConfig() | ||
{ | ||
Reset(); | ||
} | ||
|
||
void Reset(){ _register = 0; } | ||
ATCAError EnableGenKey(); | ||
void SetAsPrivKey(); | ||
void EnableExtMsgSig(); | ||
|
||
bool GenKeyEnabled(); | ||
bool IsPrivKey(); | ||
uint16_t Get() | ||
{ | ||
return _register; | ||
} | ||
}; | ||
|
||
|
||
/** class for validating and preparing key config for a data zone. | ||
*/ | ||
class KeyConfig | ||
{ | ||
private: | ||
uint16_t _register; | ||
|
||
public: | ||
KeyConfig(uint16_t key_config) | ||
: _register(key_config) | ||
{} | ||
|
||
KeyConfig() | ||
{ | ||
Reset(); | ||
} | ||
|
||
void Reset(){ _register = 0; } | ||
ATCAError SetECCKeyType(); | ||
ATCAError SetNonECCKeyType(); | ||
ATCAError EnablePubKeyGen(); | ||
void SetPrivate(); | ||
|
||
bool IsECCKey(); | ||
bool PubKeyGenEnabled(); | ||
bool IsPrivate(); | ||
uint16_t Get() | ||
{ | ||
return _register; | ||
} | ||
}; | ||
|
||
#endif /* ATCACONFIG_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2018 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef ATCAECCCONSTANTS_H | ||
#define ATCAECCCONSTANTS_H | ||
|
||
/** Datasheet defined constants */ | ||
#define ATCA_ECC_508A_I2C_ADDR 0xC0 | ||
#define ATCA_ECC_508A_REVISION {0x00, 0x00, 0x50, 0x00} | ||
#define ATCA_ECC_WORD_SZ 4 | ||
#define ATCA_ECC_STATUS_RESP_LEN 4 | ||
#define ATCA_ECC_RESP_STATUS_IDX 1 | ||
#define ATCA_ECC_NUM_PRIV_KEY_SLOTS 8 | ||
#define ATCA_ECC_ECC_PK_LEN 64 | ||
#define ATCA_ECC_CONFIG_ZONE_SZ 128 | ||
#define ATCA_KEY_ID_0 0 | ||
#define ATCA_ECC_HASH_256_LEN 32 | ||
#define ATCA_ECC_SIG_LEN 64 | ||
#define ATCA_ECC_CRC_POLYNOMIAL 0x8005 | ||
#define ATCA_ECC_NUM_DEVICE_DATA_BLOCKS 4 | ||
|
||
/** Device functions */ | ||
#define ATCA_ECC_FUNC_RST_IO_ADDR 0x00 | ||
#define ATCA_ECC_FUNC_SLEEP 0x01 | ||
#define ATCA_ECC_FUNC_IDLE 0x02 | ||
#define ATCA_ECC_FUNC_COMMAND 0x03 | ||
|
||
|
||
/** EEPROM Zones */ | ||
enum ATCAZone | ||
{ | ||
ATCA_ECC_ZONE_CONFIG = 0x0 | ||
|
||
/* Data and OTP zones are not defined here as this driver does not make | ||
* use of them. */ | ||
}; | ||
|
||
/** Command opcodes */ | ||
enum ATCAOpCode | ||
{ | ||
ATCA_ECC_CMD_OPCODE_READ = 0x02, | ||
ATCA_ECC_CMD_OPCODE_WRITE = 0x12, | ||
ATCA_ECC_CMD_OPCODE_LOCK = 0x17, | ||
ATCA_ECC_CMD_OPCODE_GENKEY = 0x40, | ||
ATCA_ECC_CMD_OPCODE_NONCE = 0x16, | ||
ATCA_ECC_CMD_OPCODE_SIGN = 0x41, | ||
ATCA_ECC_CMD_OPCODE_VERIFY = 0x45, | ||
}; | ||
|
||
/** Key ID/Slot no. Type */ | ||
typedef uint32_t ATCAKeyID; | ||
#define ATCA_ECC_KEY_ID_0 0 | ||
#define ATCA_ECC_KEY_ID_INVALID 0xFFFFFFFF | ||
|
||
/** Command and responce length */ | ||
#define ATCA_ECC_CMD_OFFSET 2 /* Command offset in Tx buffer */ | ||
#define ATCA_ECC_RESP_OFFSET 1 /* Response offset in Rx buffer */ | ||
#define ATCA_ECC_CRC_INPUT_OFFSET 1 /* CRC input data offset in Tx buffer */ | ||
#define ATCA_ECC_MAX_CMD_LEN 132 /* Bytes device allocates for constructing command */ | ||
#define ATCA_ECC_MAX_RESP_LEN 67 /* Bytes device allocates for constructing responce */ | ||
#define ATCA_ECC_FUNCTION_LEN 1 /* Device function (Write address) */ | ||
#define ATCA_ECC_CMD_IO_WRAPER_LEN 3 /* Count + CRC */ | ||
#define ATCA_ECC_CMD_READ_LEN 4 | ||
#define ATCA_ECC_RESP_READ_LEN 7 | ||
#define ATCA_ECC_CMD_WRITE_LEN 8 | ||
#define ATCA_ECC_RESP_WRITE_LEN 4 | ||
#define ATCA_ECC_CMD_WRITE_LEN 8 | ||
#define ATCA_ECC_RESP_WRITE_LEN 4 | ||
#define ATCA_ECC_CMD_LOCK_LEN 4 | ||
#define ATCA_ECC_STATUS_LEN 4 | ||
#define ATCA_ECC_CMD_GENKEY_LEN 4 | ||
#define ATCA_ECC_RESP_GENKEY_LEN 67 | ||
#define ATCA_ECC_CMD_NONCE_LEN 36 | ||
#define ATCA_ECC_CMD_SIGN_LEN 4 | ||
#define ATCA_ECC_RESP_SIGN_LEN 67 | ||
#define ATCA_ECC_CMD_VERIFY_LEN 132 | ||
|
||
/** EEPROM addresses */ | ||
#define ATCA_ECC_CFG_ADDR_REVISION 4 | ||
#define ATCA_ECC_CFG_ADDR_SLOT_CFG 20 | ||
#define ATCA_ECC_CFG_ADDR_KEY_CFG 96 | ||
#define ATCA_ECC_CFG_ADDR_LCK_CFG 87 | ||
|
||
/** Flags */ | ||
#define ATCA_ECC_FLG_READ_SZ_32 0x80 | ||
|
||
/** Devices Delays */ | ||
#define ATCA_ECC_DELAY_TPU_US 100 | ||
#define ATCA_ECC_DELAY_TWLO_US 60 | ||
#define ATCA_ECC_DELAY_TWHI_US 1500 | ||
#define ATCA_ECC_DELAY_WAKE_TOKEN_RETRY_US 100 | ||
|
||
/** Command execution times */ | ||
#define ATCA_ECC_EXEC_TIME_READ_TYP_US 100 | ||
#define ATCA_ECC_EXEC_TIME_READ_MAX_US 1000 | ||
#define ATCA_ECC_EXEC_TIME_WRITE_TYP_US 7000 | ||
#define ATCA_ECC_EXEC_TIME_WRITE_MAX_US 26000 | ||
#define ATCA_ECC_EXEC_TIME_LOCK_TYP_US 8000 | ||
#define ATCA_ECC_EXEC_TIME_LOCK_MAX_US 32000 | ||
#define ATCA_ECC_EXEC_TIME_GENKEY_TYP_US 11000 | ||
#define ATCA_ECC_EXEC_TIME_GENKEY_MAX_US 115000 | ||
#define ATCA_ECC_EXEC_TIME_NONCE_TYP_US 100 | ||
#define ATCA_ECC_EXEC_TIME_NONCE_MAX_US 7000 | ||
#define ATCA_ECC_EXEC_TIME_SIGN_TYP_US 42000 | ||
#define ATCA_ECC_EXEC_TIME_SIGN_MAX_US 50000 | ||
#define ATCA_ECC_EXEC_TIME_VERIFY_TYP_US 38000 | ||
#define ATCA_ECC_EXEC_TIME_VERIFY_MAX_US 58000 | ||
|
||
/** Driver defined constants */ | ||
#define ATCA_ECC_I2C_FREQUENCY 10000 | ||
|
||
#endif /* ATCAECCCONSTANTS_H */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing any documentation for methods