32
32
#include "tng_root_cert.h"
33
33
#include <limits.h>
34
34
35
+ #if ATCACERT_COMPCERT_EN
36
+
35
37
int tng_atcacert_max_device_cert_size (size_t * max_cert_size )
36
38
{
37
39
int ret = ATCACERT_E_WRONG_CERT_DEF ;
@@ -48,10 +50,14 @@ int tng_atcacert_max_device_cert_size(size_t* max_cert_size)
48
50
if (NULL != cert_def )
49
51
{
50
52
ret = atcacert_max_cert_size (cert_def , & cert_size );
51
- if (cert_size > * max_cert_size )
53
+ if (ATCACERT_E_SUCCESS == ret )
52
54
{
53
55
* max_cert_size = cert_size ;
54
56
}
57
+ else
58
+ {
59
+ break ;
60
+ }
55
61
56
62
if (index < INT_MAX )
57
63
{
@@ -110,7 +116,7 @@ int tng_atcacert_read_device_cert(uint8_t* cert, size_t* cert_size, const uint8_
110
116
}
111
117
}
112
118
113
- return atcacert_read_cert (cert_def , ca_public_key , cert , cert_size );
119
+ return atcacert_read_cert (cert_def , & ca_pubkey , cert , cert_size );
114
120
}
115
121
116
122
int tng_atcacert_device_public_key (uint8_t * public_key , uint8_t * cert )
@@ -159,7 +165,8 @@ int tng_atcacert_read_signer_cert(uint8_t* cert, size_t* cert_size)
159
165
{
160
166
int ret ;
161
167
const atcacert_def_t * cert_def = NULL ;
162
- const uint8_t * ca_public_key = NULL ;
168
+ uint8_t * ca_public_key = NULL ;
169
+ cal_buffer ca_pubkey = CAL_BUF_INIT (ATCA_ECCP256_PUBKEY_SIZE , NULL );
163
170
164
171
ret = tng_get_device_cert_def (& cert_def );
165
172
if (ATCA_SUCCESS == ret )
@@ -169,7 +176,8 @@ int tng_atcacert_read_signer_cert(uint8_t* cert, size_t* cert_size)
169
176
// Get the CA (root) public key
170
177
ca_public_key = & g_cryptoauth_root_ca_002_cert [CRYPTOAUTH_ROOT_CA_002_PUBLIC_KEY_OFFSET ];
171
178
172
- ret = atcacert_read_cert (cert_def , ca_public_key , cert , cert_size );
179
+ ca_pubkey .buf = ca_public_key ;
180
+ ret = atcacert_read_cert (cert_def , & ca_pubkey , cert , cert_size );
173
181
}
174
182
175
183
return ret ;
@@ -263,3 +271,5 @@ int tng_atcacert_root_public_key(uint8_t* public_key)
263
271
264
272
return ATCACERT_E_SUCCESS ;
265
273
}
274
+
275
+ #endif
0 commit comments