Skip to content

ECDSA signing & public key exporting #2

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
merged 12 commits into from
May 30, 2019
63 changes: 0 additions & 63 deletions atecc608a_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,73 +19,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "atecc608a_se.h"
#include "atecc608a_utils.h"

#include "atca_basic.h"

ATCAIfaceCfg atca_iface_config = {
.iface_type = ATCA_I2C_IFACE,
.devtype = ATECC608A,
.atcai2c.slave_address = 0xC0,
.atcai2c.bus = 2,
.atcai2c.baud = 400000,
.wake_delay = 1500,
.rx_retries = 20,
};

psa_status_t atecc608a_to_psa_error(ATCA_STATUS ret)
{
switch (ret)
{
case ATCA_SUCCESS:
case ATCA_RX_NO_RESPONSE:
case ATCA_WAKE_SUCCESS:
return PSA_SUCCESS;
case ATCA_BAD_PARAM:
case ATCA_INVALID_ID:
return PSA_ERROR_INVALID_ARGUMENT;
case ATCA_ASSERT_FAILURE:
return PSA_ERROR_TAMPERING_DETECTED;
case ATCA_SMALL_BUFFER:
return PSA_ERROR_BUFFER_TOO_SMALL;
case ATCA_RX_CRC_ERROR:
case ATCA_RX_FAIL:
case ATCA_STATUS_CRC:
case ATCA_RESYNC_WITH_WAKEUP:
case ATCA_PARITY_ERROR:
case ATCA_TX_TIMEOUT:
case ATCA_RX_TIMEOUT:
case ATCA_TOO_MANY_COMM_RETRIES:
case ATCA_COMM_FAIL:
case ATCA_TIMEOUT:
case ATCA_TX_FAIL:
case ATCA_NO_DEVICES:
return PSA_ERROR_COMMUNICATION_FAILURE;
case ATCA_UNIMPLEMENTED:
return PSA_ERROR_NOT_SUPPORTED;
case ATCA_ALLOC_FAILURE:
return PSA_ERROR_INSUFFICIENT_MEMORY;
case ATCA_BAD_OPCODE:
case ATCA_CONFIG_ZONE_LOCKED:
case ATCA_DATA_ZONE_LOCKED:
case ATCA_NOT_LOCKED:
case ATCA_WAKE_FAILED:
case ATCA_STATUS_UNKNOWN:
case ATCA_STATUS_ECC:
case ATCA_STATUS_SELFTEST_ERROR:
case ATCA_CHECKMAC_VERIFY_FAILED:
case ATCA_PARSE_ERROR:
case ATCA_FUNC_FAIL:
case ATCA_GEN_FAIL:
case ATCA_EXECUTION_ERROR:
case ATCA_HEALTH_TEST_ERROR:
case ATCA_INVALID_SIZE:
default:
return PSA_ERROR_HARDWARE_FAILURE;
}
}

psa_status_t atecc608a_get_serial_number(uint8_t* buffer,
size_t buffer_size,
size_t *buffer_length)
Expand Down
27 changes: 2 additions & 25 deletions atecc608a_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,8 @@
#ifndef ATECC608A_UTILS_H
#define ATECC608A_UTILS_H

#include "atca_iface.h"
#include "psa/crypto.h"

#define ATCAB_INIT() \
do \
{ \
if (atcab_init(&atca_iface_config) != ATCA_SUCCESS) \
{ \
status = PSA_ERROR_HARDWARE_FAILURE; \
goto exit; \
} \
} while(0)

/** `atcab_release()` might return `ATCA_BAD_PARAM` if there is no global device
* initialized via `atcab_init()`. HAL might return an error if an i2c device
* cannot be released, but in current implementations it always returns
* `ATCA_SUCCESS` - therefore we are ignoring the return code. */
#define ATCAB_DEINIT() \
do \
{ \
atcab_release(); \
} while(0)
#include "atecc608a_se.h"

/** This macro checks if the result of an `expression` is equal to an
* `expected` value and sets a `status` variable of type `psa_status_t` to
Expand Down Expand Up @@ -75,12 +55,9 @@
* the PSA return code - PSA_SUCCESS.*/
#define ASSERT_SUCCESS_PSA(expression) ASSERT_STATUS(expression, PSA_SUCCESS, \
ASSERT_result)

psa_status_t atecc608a_get_serial_number(uint8_t* buffer, size_t buffer_size,
size_t *buffer_length);
psa_status_t atecc608a_check_config_locked();
psa_status_t atecc608a_to_psa_error(ATCA_STATUS ret);

extern ATCAIfaceCfg atca_iface_config;

#endif /* ATECC608A_SE_H */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing newline. Please pass check-files.py.