My Project
Loading...
Searching...
No Matches
atmel.h
1/* atmel.h
2 *
3 * Copyright (C) 2006-2020 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22#ifndef _ATECC508_H_
23#define _ATECC508_H_
24
25#include <stdint.h>
26
27#include <wolfssl/wolfcrypt/settings.h>
29
30#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC_PKCB)
31 #undef SHA_BLOCK_SIZE
32 #define SHA_BLOCK_SIZE SHA_BLOCK_SIZE_REMAP
33 #include <cryptoauthlib.h>
34 #undef SHA_BLOCK_SIZE
35#endif
36
37/* ATECC508A only supports ECC P-256 */
38#define ATECC_KEY_SIZE (32)
39#define ATECC_PUBKEY_SIZE (ATECC_KEY_SIZE*2) /* X and Y */
40#define ATECC_SIG_SIZE (ATECC_KEY_SIZE*2) /* R and S */
41#ifndef ATECC_MAX_SLOT
42#define ATECC_MAX_SLOT (0x8) /* Only use 0-7 */
43#endif
44#define ATECC_INVALID_SLOT (0xFF)
45
46/* Device Key for signing */
47#ifndef ATECC_SLOT_AUTH_PRIV
48#define ATECC_SLOT_AUTH_PRIV (0x0)
49#endif
50/* Ephemeral key */
51#ifndef ATECC_SLOT_ECDHE_PRIV
52#define ATECC_SLOT_ECDHE_PRIV (0x2)
53#endif
54/* Symmetric encryption key */
55#ifndef ATECC_SLOT_I2C_ENC
56#define ATECC_SLOT_I2C_ENC (0x04)
57#endif
58/* Parent encryption key */
59#ifndef ATECC_SLOT_ENC_PARENT
60#define ATECC_SLOT_ENC_PARENT (0x7)
61#endif
62
63/* ATECC_KEY_SIZE required for ecc.h */
65
66struct WOLFSSL;
67struct WOLFSSL_CTX;
69struct ecc_key;
70
71/* Atmel port functions */
72int atmel_init(void);
73void atmel_finish(void);
74int atmel_get_random_number(uint32_t count, uint8_t* rand_out);
75#ifndef ATMEL_GET_RANDOM_BLOCK_DEFINED
76 int atmel_get_random_block(unsigned char* output, unsigned int sz);
77 #define ATMEL_GET_RANDOM_BLOCK_DEFINED
78#endif
79long atmel_get_curr_time_and_date(long* tm);
80
81#ifdef WOLFSSL_ATECC508A
82
83enum atmelSlotType {
84 ATMEL_SLOT_ANY,
85 ATMEL_SLOT_ENCKEY,
86 ATMEL_SLOT_DEVICE,
87 ATMEL_SLOT_ECDHE,
88 ATMEL_SLOT_ECDHE_ENC,
89};
90
91int atmel_ecc_alloc(int slotType);
92void atmel_ecc_free(int slotId);
93
94typedef int (*atmel_slot_alloc_cb)(int);
95typedef void (*atmel_slot_dealloc_cb)(int);
96int atmel_set_slot_allocator(atmel_slot_alloc_cb alloc,
97 atmel_slot_dealloc_cb dealloc);
98
99int atmel_ecc_translate_err(int status);
100int atmel_get_rev_info(word32* revision);
101void atmel_show_rev_info(void);
102
103/* The macro ATECC_GET_ENC_KEY can be set to override the default
104 encryption key with your own at build-time */
105#ifndef ATECC_GET_ENC_KEY
106 #define ATECC_GET_ENC_KEY(enckey, keysize) atmel_get_enc_key_default((enckey), (keysize))
107#endif
108int atmel_get_enc_key_default(byte* enckey, word16 keysize);
109int atmel_ecc_create_pms(int slotId, const uint8_t* peerKey, uint8_t* pms);
110int atmel_ecc_create_key(int slotId, byte* peerKey);
111int atmel_ecc_sign(int slotId, const byte* message, byte* signature);
112int atmel_ecc_verify(const byte* message, const byte* signature,
113 const byte* pubkey, int* verified);
114
115#endif /* WOLFSSL_ATECC508A */
116
117#ifdef HAVE_PK_CALLBACKS
118 int atcatls_create_key_cb(struct WOLFSSL* ssl, struct ecc_key* key, unsigned int keySz,
119 int ecc_curve, void* ctx);
120 int atcatls_create_pms_cb(struct WOLFSSL* ssl, struct ecc_key* otherKey,
121 unsigned char* pubKeyDer, word32* pubKeySz,
122 unsigned char* out, word32* outlen,
123 int side, void* ctx);
124 int atcatls_sign_certificate_cb(struct WOLFSSL* ssl, const byte* in, unsigned int inSz,
125 byte* out, word32* outSz, const byte* key, unsigned int keySz, void* ctx);
126 int atcatls_verify_signature_cb(struct WOLFSSL* ssl, const byte* sig, unsigned int sigSz,
127 const byte* hash, unsigned int hashSz, const byte* key, unsigned int keySz,
128 int* result, void* ctx);
129
130 int atcatls_set_callbacks(struct WOLFSSL_CTX* ctx);
131 int atcatls_set_callback_ctx(struct WOLFSSL* ssl, void* user_ctx);
132#endif
133
134#endif /* _ATECC508_H_ */
Definition internal.h:2595
Definition ssl.h:569
Definition internal.h:3849
Definition ecc.h:357