@@ -54,25 +54,21 @@ int SecureElement::buildCSR(ECP256Certificate & cert, const int keySlot, bool ne
5454
5555 if (newPrivateKey) {
5656 if (!_secureElement.generatePrivateKey (keySlot, publicKey)) {
57- Serial.println (" Error1" );
5857 return 0 ;
5958 }
6059 } else {
6160 if (!_secureElement.generatePublicKey (keySlot, publicKey)) {
62- Serial.println (" Error2" );
6361 return 0 ;
6462 }
6563 }
6664
6765 /* Store public key in csr */
6866 if (!cert.setPublicKey (publicKey, ECP256_CERT_PUBLIC_KEY_LENGTH)) {
69- Serial.println (" Error3" );
7067 return 0 ;
7168 }
7269
7370 /* Build CSR */
7471 if (!cert.buildCSR ()) {
75- Serial.println (" Error4" );
7672 return 0 ;
7773 }
7874
@@ -81,7 +77,6 @@ int SecureElement::buildCSR(ECP256Certificate & cert, const int keySlot, bool ne
8177 this ->SHA256 (cert.bytes (), cert.length (), sha256buf);
8278
8379 if (!_secureElement.ecSign (keySlot, sha256buf, signature)) {
84- Serial.println (" Error5" );
8580 return 0 ;
8681 }
8782
@@ -147,9 +142,10 @@ int SecureElement::readCert(ECP256Certificate & cert, const int certSlot)
147142
148143 cert.begin ();
149144
150- if (!readDeviceId (deviceId, int ::DeviceId)) {
151- return 0 ;
152- }
145+ /* To do certificate is splitted into multiple slots */
146+ // if (!readDeviceId(deviceId, 0)) {
147+ // return 0;
148+ // }
153149
154150 if (!_secureElement.readSlot (certSlot, cert.compressedCertSignatureAndDatesBytes (), cert.compressedCertSignatureAndDatesLength ())) {
155151 return 0 ;
@@ -185,18 +181,20 @@ int SecureElement::readCert(ECP256Certificate & cert, const int certSlot)
185181 return 1 ;
186182}
187183
188-
189184int SecureElement::SHA256 (const uint8_t *buffer, size_t size, uint8_t *digest)
190185{
191- #if defined(BOARD_HAS_SE050)
192- size_t outLen;
193- _secureElement.SHA256 (buffer, size, digest, 32 , &outLen);
194- #else
195186 _secureElement.beginSHA256 ();
196-
197- unit8_t * cursor = buffer;
187+ uint8_t * cursor = (uint8_t *)buffer;
198188 uint32_t bytes_read = 0 ;
199- for (; bytes_read + 64 < size; bytes_read += 64 , cursor += 64 ;) {
189+ #if defined(BOARD_HAS_SE050)
190+ size_t outLen = 32 ;
191+ for (; bytes_read + 64 < size; bytes_read += 64 , cursor += 64 ) {
192+ _secureElement.updateSHA256 (cursor, 64 );
193+ }
194+ _secureElement.updateSHA256 (cursor, size - bytes_read);
195+ _secureElement.endSHA256 (digest, &outLen);
196+ #else
197+ for (; bytes_read + 64 < size; bytes_read += 64 , cursor += 64 ) {
200198 _secureElement.updateSHA256 (cursor);
201199 }
202200 _secureElement.endSHA256 (cursor, size - bytes_read, digest);
0 commit comments