11#include < Arduino.h>
22
3- #include " ECC508 .h"
3+ #include " ECCX08 .h"
44
5- const uint32_t ECC508Class ::_wakeupFrequency = 100000u ; // 100 kHz
6- const uint32_t ECC508Class ::_normalFrequency = 1000000u ; // 1 MHz
5+ const uint32_t ECCX08Class ::_wakeupFrequency = 100000u ; // 100 kHz
6+ const uint32_t ECCX08Class ::_normalFrequency = 1000000u ; // 1 MHz
77
8- ECC508Class::ECC508Class (TwoWire& wire, uint8_t address) :
8+ ECCX08Class::ECCX08Class (TwoWire& wire, uint8_t address) :
99 _wire(&wire),
1010 _address(address)
1111{
1212}
1313
14- ECC508Class ::~ECC508Class ()
14+ ECCX08Class ::~ECCX08Class ()
1515{
1616}
1717
18- int ECC508Class ::begin ()
18+ int ECCX08Class ::begin ()
1919{
2020 _wire->begin ();
2121
@@ -26,12 +26,12 @@ int ECC508Class::begin()
2626 return 1 ;
2727}
2828
29- void ECC508Class ::end ()
29+ void ECCX08Class ::end ()
3030{
3131 _wire->end ();
3232}
3333
34- String ECC508Class ::serialNumber ()
34+ String ECCX08Class ::serialNumber ()
3535{
3636 String result = (char *)NULL ;
3737 byte sn[12 ];
@@ -64,7 +64,7 @@ String ECC508Class::serialNumber()
6464 return result;
6565}
6666
67- int ECC508Class ::random (byte data[], size_t length)
67+ int ECCX08Class ::random (byte data[], size_t length)
6868{
6969 if (!wakeup ()) {
7070 return 0 ;
@@ -97,7 +97,7 @@ int ECC508Class::random(byte data[], size_t length)
9797 return 1 ;
9898}
9999
100- int ECC508Class ::generatePrivateKey (int slot, byte publicKey[])
100+ int ECCX08Class ::generatePrivateKey (int slot, byte publicKey[])
101101{
102102 if (!wakeup ()) {
103103 return 0 ;
@@ -120,7 +120,7 @@ int ECC508Class::generatePrivateKey(int slot, byte publicKey[])
120120 return 1 ;
121121}
122122
123- int ECC508Class ::generatePublicKey (int slot, byte publicKey[])
123+ int ECCX08Class ::generatePublicKey (int slot, byte publicKey[])
124124{
125125 if (!wakeup ()) {
126126 return 0 ;
@@ -143,7 +143,7 @@ int ECC508Class::generatePublicKey(int slot, byte publicKey[])
143143 return 1 ;
144144}
145145
146- int ECC508Class ::ecdsaVerify (const byte message[], const byte signature[], const byte pubkey[])
146+ int ECCX08Class ::ecdsaVerify (const byte message[], const byte signature[], const byte pubkey[])
147147{
148148 if (!challenge (message)) {
149149 return 0 ;
@@ -156,7 +156,7 @@ int ECC508Class::ecdsaVerify(const byte message[], const byte signature[], const
156156 return 1 ;
157157}
158158
159- int ECC508Class ::ecSign (int slot, const byte message[], byte signature[])
159+ int ECCX08Class ::ecSign (int slot, const byte message[], byte signature[])
160160{
161161 byte rand[32 ];
162162
@@ -175,7 +175,7 @@ int ECC508Class::ecSign(int slot, const byte message[], byte signature[])
175175 return 1 ;
176176}
177177
178- int ECC508Class ::readSlot (int slot, byte data[], int length)
178+ int ECCX08Class ::readSlot (int slot, byte data[], int length)
179179{
180180 if (slot < 0 || slot > 15 ) {
181181 return -1 ;
@@ -200,7 +200,7 @@ int ECC508Class::readSlot(int slot, byte data[], int length)
200200 return 1 ;
201201}
202202
203- int ECC508Class ::writeSlot (int slot, const byte data[], int length)
203+ int ECCX08Class ::writeSlot (int slot, const byte data[], int length)
204204{
205205 if (slot < 0 || slot > 15 ) {
206206 return -1 ;
@@ -225,7 +225,7 @@ int ECC508Class::writeSlot(int slot, const byte data[], int length)
225225 return 1 ;
226226}
227227
228- int ECC508Class ::locked ()
228+ int ECCX08Class ::locked ()
229229{
230230 byte config[4 ];
231231
@@ -240,7 +240,7 @@ int ECC508Class::locked()
240240 return 0 ;
241241}
242242
243- int ECC508Class ::writeConfiguration (const byte data[])
243+ int ECCX08Class ::writeConfiguration (const byte data[])
244244{
245245 // skip first 16 bytes, they are not writable
246246 for (int i = 16 ; i < 128 ; i += 4 ) {
@@ -257,7 +257,7 @@ int ECC508Class::writeConfiguration(const byte data[])
257257 return 1 ;
258258}
259259
260- int ECC508Class ::readConfiguration (byte data[])
260+ int ECCX08Class ::readConfiguration (byte data[])
261261{
262262 for (int i = 0 ; i < 128 ; i += 32 ) {
263263 if (!read (0 , i / 4 , &data[i], 32 )) {
@@ -268,7 +268,7 @@ int ECC508Class::readConfiguration(byte data[])
268268 return 1 ;
269269}
270270
271- int ECC508Class ::lock ()
271+ int ECCX08Class ::lock ()
272272{
273273 // lock config
274274 if (!lock (0 )) {
@@ -283,7 +283,7 @@ int ECC508Class::lock()
283283 return 1 ;
284284}
285285
286- int ECC508Class ::wakeup ()
286+ int ECCX08Class ::wakeup ()
287287{
288288 _wire->setClock (_wakeupFrequency);
289289 _wire->beginTransmission (0x00 );
@@ -302,7 +302,7 @@ int ECC508Class::wakeup()
302302 return 1 ;
303303}
304304
305- int ECC508Class ::sleep ()
305+ int ECCX08Class ::sleep ()
306306{
307307 _wire->beginTransmission (_address);
308308 _wire->write (0x01 );
@@ -314,7 +314,7 @@ int ECC508Class::sleep()
314314 return 1 ;
315315}
316316
317- int ECC508Class ::idle ()
317+ int ECCX08Class ::idle ()
318318{
319319 _wire->beginTransmission (_address);
320320 _wire->write (0x02 );
@@ -326,7 +326,7 @@ int ECC508Class::idle()
326326 return 1 ;
327327}
328328
329- int ECC508Class ::version ()
329+ int ECCX08Class ::version ()
330330{
331331 uint32_t version = 0 ;
332332
@@ -350,7 +350,7 @@ int ECC508Class::version()
350350 return version;
351351}
352352
353- int ECC508Class ::challenge (const byte message[])
353+ int ECCX08Class ::challenge (const byte message[])
354354{
355355 uint8_t status;
356356
@@ -379,7 +379,7 @@ int ECC508Class::challenge(const byte message[])
379379 return 1 ;
380380}
381381
382- int ECC508Class ::verify (const byte signature[], const byte pubkey[])
382+ int ECCX08Class ::verify (const byte signature[], const byte pubkey[])
383383{
384384 uint8_t status;
385385
@@ -412,7 +412,7 @@ int ECC508Class::verify(const byte signature[], const byte pubkey[])
412412 return 1 ;
413413}
414414
415- int ECC508Class ::sign (int slot, byte signature[])
415+ int ECCX08Class ::sign (int slot, byte signature[])
416416{
417417 if (!wakeup ()) {
418418 return 0 ;
@@ -434,7 +434,7 @@ int ECC508Class::sign(int slot, byte signature[])
434434 return 1 ;
435435}
436436
437- int ECC508Class ::read (int zone, int address, byte buffer[], int length)
437+ int ECCX08Class ::read (int zone, int address, byte buffer[], int length)
438438{
439439 if (!wakeup ()) {
440440 return 0 ;
@@ -464,7 +464,7 @@ int ECC508Class::read(int zone, int address, byte buffer[], int length)
464464 return length;
465465}
466466
467- int ECC508Class ::write (int zone, int address, const byte buffer[], int length)
467+ int ECCX08Class ::write (int zone, int address, const byte buffer[], int length)
468468{
469469 uint8_t status;
470470
@@ -500,7 +500,7 @@ int ECC508Class::write(int zone, int address, const byte buffer[], int length)
500500 return 1 ;
501501}
502502
503- int ECC508Class ::lock (int zone)
503+ int ECCX08Class ::lock (int zone)
504504{
505505 uint8_t status;
506506
@@ -528,15 +528,15 @@ int ECC508Class::lock(int zone)
528528 return 1 ;
529529}
530530
531- int ECC508Class ::addressForSlotOffset (int slot, int offset)
531+ int ECCX08Class ::addressForSlotOffset (int slot, int offset)
532532{
533533 int block = offset / 32 ;
534534 offset = (offset % 32 ) / 4 ;
535535
536536 return (slot << 3 ) | (block << 8 ) | (offset);
537537}
538538
539- int ECC508Class ::sendCommand (uint8_t opcode, uint8_t param1, uint16_t param2, const byte data[], size_t dataLength)
539+ int ECCX08Class ::sendCommand (uint8_t opcode, uint8_t param1, uint16_t param2, const byte data[], size_t dataLength)
540540{
541541 int commandLength = 8 + dataLength; // 1 for type, 1 for length, 1 for opcode, 1 for param1, 2 for param2, 2 for crc
542542 byte command[commandLength];
@@ -560,7 +560,7 @@ int ECC508Class::sendCommand(uint8_t opcode, uint8_t param1, uint16_t param2, co
560560 return 1 ;
561561}
562562
563- int ECC508Class ::receiveResponse (void * response, size_t length)
563+ int ECCX08Class ::receiveResponse (void * response, size_t length)
564564{
565565 int retries = 20 ;
566566 int responseSize = length + 3 ; // 1 for length header, 2 for CRC
@@ -590,7 +590,7 @@ int ECC508Class::receiveResponse(void* response, size_t length)
590590 return 1 ;
591591}
592592
593- uint16_t ECC508Class ::crc16 (const byte data[], size_t length)
593+ uint16_t ECCX08Class ::crc16 (const byte data[], size_t length)
594594{
595595 if (data == NULL || length == 0 ) {
596596 return 0 ;
@@ -619,4 +619,4 @@ uint16_t ECC508Class::crc16(const byte data[], size_t length)
619619 return crc;
620620}
621621
622- ECC508Class ECC508 (Wire, 0x60 );
622+ ECCX08Class ECCX08 (Wire, 0x60 );
0 commit comments