3232#include "tng_root_cert.h"
3333#include <limits.h>
3434
35+ #if ATCACERT_COMPCERT_EN
36+
3537int tng_atcacert_max_device_cert_size (size_t * max_cert_size )
3638{
3739 int ret = ATCACERT_E_WRONG_CERT_DEF ;
@@ -48,10 +50,14 @@ int tng_atcacert_max_device_cert_size(size_t* max_cert_size)
4850 if (NULL != cert_def )
4951 {
5052 ret = atcacert_max_cert_size (cert_def , & cert_size );
51- if (cert_size > * max_cert_size )
53+ if (ATCACERT_E_SUCCESS == ret )
5254 {
5355 * max_cert_size = cert_size ;
5456 }
57+ else
58+ {
59+ break ;
60+ }
5561
5662 if (index < INT_MAX )
5763 {
@@ -110,7 +116,7 @@ int tng_atcacert_read_device_cert(uint8_t* cert, size_t* cert_size, const uint8_
110116 }
111117 }
112118
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 );
114120}
115121
116122int 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)
159165{
160166 int ret ;
161167 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 );
163170
164171 ret = tng_get_device_cert_def (& cert_def );
165172 if (ATCA_SUCCESS == ret )
@@ -169,7 +176,8 @@ int tng_atcacert_read_signer_cert(uint8_t* cert, size_t* cert_size)
169176 // Get the CA (root) public key
170177 ca_public_key = & g_cryptoauth_root_ca_002_cert [CRYPTOAUTH_ROOT_CA_002_PUBLIC_KEY_OFFSET ];
171178
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 );
173181 }
174182
175183 return ret ;
@@ -263,3 +271,5 @@ int tng_atcacert_root_public_key(uint8_t* public_key)
263271
264272 return ATCACERT_E_SUCCESS ;
265273}
274+
275+ #endif
0 commit comments