Skip to content

Commit 05921d5

Browse files
implementing methods from SecureElement library
Making ECCX08 compatible with abstract SecureElement usage from Arduino_SecureElement library
1 parent 4de05ab commit 05921d5

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/ECCX08.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ void ECCX08Class::end()
7373
#endif
7474
}
7575

76-
int ECCX08Class::serialNumber(byte sn[])
76+
int ECCX08Class::serialNumber(byte sn[], size_t len)
7777
{
78+
if(len < 12) {
79+
return 0;
80+
}
81+
7882
if (!read(0, 0, &sn[0], 4)) {
7983
return 0;
8084
}
@@ -252,6 +256,18 @@ int ECCX08Class::ecSign(int slot, const byte message[], byte signature[])
252256
return 1;
253257
}
254258

259+
int ECCX08Class::SHA256(const uint8_t *buffer, size_t size, uint8_t *digest)
260+
{
261+
beginSHA256();
262+
uint8_t * cursor = (uint8_t*)buffer;
263+
uint32_t bytes_read = 0;
264+
265+
for(; bytes_read + 64 < size; bytes_read += 64, cursor += 64) {
266+
updateSHA256(cursor);
267+
}
268+
return endSHA256(cursor, size - bytes_read, digest);
269+
}
270+
255271
int ECCX08Class::beginSHA256()
256272
{
257273
uint8_t status;

src/ECCX08.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ECCX08Class
3333
int begin(uint8_t i2cAddress);
3434
void end();
3535

36-
int serialNumber(byte sn[]);
36+
int serialNumber(byte sn[], size_t length=12);
3737
String serialNumber();
3838

3939
long random(long max);
@@ -46,6 +46,7 @@ class ECCX08Class
4646
int ecdsaVerify(const byte message[], const byte signature[], const byte pubkey[]);
4747
int ecSign(int slot, const byte message[], byte signature[]);
4848

49+
int SHA256(const uint8_t *buffer, size_t size, uint8_t *digest);
4950
int beginSHA256();
5051
int updateSHA256(const byte data[]); // 64 bytes
5152
int endSHA256(byte result[]);
@@ -55,7 +56,7 @@ class ECCX08Class
5556
int writeSlot(int slot, const byte data[], int length);
5657

5758
int locked();
58-
int writeConfiguration(const byte data[]);
59+
int writeConfiguration(const byte data[]=ECCX08_DEFAULT_TLS_CONFIG);
5960
int readConfiguration(byte data[]);
6061
int lock();
6162

0 commit comments

Comments
 (0)