1
1
#include < Arduino.h>
2
2
3
- #include " ECC508 .h"
3
+ #include " ECCX08 .h"
4
4
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
7
7
8
- ECC508Class::ECC508Class (TwoWire& wire, uint8_t address) :
8
+ ECCX08Class::ECCX08Class (TwoWire& wire, uint8_t address) :
9
9
_wire(&wire),
10
10
_address(address)
11
11
{
12
12
}
13
13
14
- ECC508Class ::~ECC508Class ()
14
+ ECCX08Class ::~ECCX08Class ()
15
15
{
16
16
}
17
17
18
- int ECC508Class ::begin ()
18
+ int ECCX08Class ::begin ()
19
19
{
20
20
_wire->begin ();
21
21
@@ -26,12 +26,12 @@ int ECC508Class::begin()
26
26
return 1 ;
27
27
}
28
28
29
- void ECC508Class ::end ()
29
+ void ECCX08Class ::end ()
30
30
{
31
31
_wire->end ();
32
32
}
33
33
34
- String ECC508Class ::serialNumber ()
34
+ String ECCX08Class ::serialNumber ()
35
35
{
36
36
String result = (char *)NULL ;
37
37
byte sn[12 ];
@@ -64,7 +64,7 @@ String ECC508Class::serialNumber()
64
64
return result;
65
65
}
66
66
67
- int ECC508Class ::random (byte data[], size_t length)
67
+ int ECCX08Class ::random (byte data[], size_t length)
68
68
{
69
69
if (!wakeup ()) {
70
70
return 0 ;
@@ -97,7 +97,7 @@ int ECC508Class::random(byte data[], size_t length)
97
97
return 1 ;
98
98
}
99
99
100
- int ECC508Class ::generatePrivateKey (int slot, byte publicKey[])
100
+ int ECCX08Class ::generatePrivateKey (int slot, byte publicKey[])
101
101
{
102
102
if (!wakeup ()) {
103
103
return 0 ;
@@ -120,7 +120,7 @@ int ECC508Class::generatePrivateKey(int slot, byte publicKey[])
120
120
return 1 ;
121
121
}
122
122
123
- int ECC508Class ::generatePublicKey (int slot, byte publicKey[])
123
+ int ECCX08Class ::generatePublicKey (int slot, byte publicKey[])
124
124
{
125
125
if (!wakeup ()) {
126
126
return 0 ;
@@ -143,7 +143,7 @@ int ECC508Class::generatePublicKey(int slot, byte publicKey[])
143
143
return 1 ;
144
144
}
145
145
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[])
147
147
{
148
148
if (!challenge (message)) {
149
149
return 0 ;
@@ -156,7 +156,7 @@ int ECC508Class::ecdsaVerify(const byte message[], const byte signature[], const
156
156
return 1 ;
157
157
}
158
158
159
- int ECC508Class ::ecSign (int slot, const byte message[], byte signature[])
159
+ int ECCX08Class ::ecSign (int slot, const byte message[], byte signature[])
160
160
{
161
161
byte rand [32 ];
162
162
@@ -175,7 +175,7 @@ int ECC508Class::ecSign(int slot, const byte message[], byte signature[])
175
175
return 1 ;
176
176
}
177
177
178
- int ECC508Class ::readSlot (int slot, byte data[], int length)
178
+ int ECCX08Class ::readSlot (int slot, byte data[], int length)
179
179
{
180
180
if (slot < 0 || slot > 15 ) {
181
181
return -1 ;
@@ -200,7 +200,7 @@ int ECC508Class::readSlot(int slot, byte data[], int length)
200
200
return 1 ;
201
201
}
202
202
203
- int ECC508Class ::writeSlot (int slot, const byte data[], int length)
203
+ int ECCX08Class ::writeSlot (int slot, const byte data[], int length)
204
204
{
205
205
if (slot < 0 || slot > 15 ) {
206
206
return -1 ;
@@ -225,7 +225,7 @@ int ECC508Class::writeSlot(int slot, const byte data[], int length)
225
225
return 1 ;
226
226
}
227
227
228
- int ECC508Class ::locked ()
228
+ int ECCX08Class ::locked ()
229
229
{
230
230
byte config[4 ];
231
231
@@ -240,7 +240,7 @@ int ECC508Class::locked()
240
240
return 0 ;
241
241
}
242
242
243
- int ECC508Class ::writeConfiguration (const byte data[])
243
+ int ECCX08Class ::writeConfiguration (const byte data[])
244
244
{
245
245
// skip first 16 bytes, they are not writable
246
246
for (int i = 16 ; i < 128 ; i += 4 ) {
@@ -257,7 +257,7 @@ int ECC508Class::writeConfiguration(const byte data[])
257
257
return 1 ;
258
258
}
259
259
260
- int ECC508Class ::readConfiguration (byte data[])
260
+ int ECCX08Class ::readConfiguration (byte data[])
261
261
{
262
262
for (int i = 0 ; i < 128 ; i += 32 ) {
263
263
if (!read (0 , i / 4 , &data[i], 32 )) {
@@ -268,7 +268,7 @@ int ECC508Class::readConfiguration(byte data[])
268
268
return 1 ;
269
269
}
270
270
271
- int ECC508Class ::lock ()
271
+ int ECCX08Class ::lock ()
272
272
{
273
273
// lock config
274
274
if (!lock (0 )) {
@@ -283,7 +283,7 @@ int ECC508Class::lock()
283
283
return 1 ;
284
284
}
285
285
286
- int ECC508Class ::wakeup ()
286
+ int ECCX08Class ::wakeup ()
287
287
{
288
288
_wire->setClock (_wakeupFrequency);
289
289
_wire->beginTransmission (0x00 );
@@ -302,7 +302,7 @@ int ECC508Class::wakeup()
302
302
return 1 ;
303
303
}
304
304
305
- int ECC508Class ::sleep ()
305
+ int ECCX08Class ::sleep ()
306
306
{
307
307
_wire->beginTransmission (_address);
308
308
_wire->write (0x01 );
@@ -314,7 +314,7 @@ int ECC508Class::sleep()
314
314
return 1 ;
315
315
}
316
316
317
- int ECC508Class ::idle ()
317
+ int ECCX08Class ::idle ()
318
318
{
319
319
_wire->beginTransmission (_address);
320
320
_wire->write (0x02 );
@@ -326,7 +326,7 @@ int ECC508Class::idle()
326
326
return 1 ;
327
327
}
328
328
329
- int ECC508Class ::version ()
329
+ int ECCX08Class ::version ()
330
330
{
331
331
uint32_t version = 0 ;
332
332
@@ -350,7 +350,7 @@ int ECC508Class::version()
350
350
return version;
351
351
}
352
352
353
- int ECC508Class ::challenge (const byte message[])
353
+ int ECCX08Class ::challenge (const byte message[])
354
354
{
355
355
uint8_t status;
356
356
@@ -379,7 +379,7 @@ int ECC508Class::challenge(const byte message[])
379
379
return 1 ;
380
380
}
381
381
382
- int ECC508Class ::verify (const byte signature[], const byte pubkey[])
382
+ int ECCX08Class ::verify (const byte signature[], const byte pubkey[])
383
383
{
384
384
uint8_t status;
385
385
@@ -412,7 +412,7 @@ int ECC508Class::verify(const byte signature[], const byte pubkey[])
412
412
return 1 ;
413
413
}
414
414
415
- int ECC508Class ::sign (int slot, byte signature[])
415
+ int ECCX08Class ::sign (int slot, byte signature[])
416
416
{
417
417
if (!wakeup ()) {
418
418
return 0 ;
@@ -434,7 +434,7 @@ int ECC508Class::sign(int slot, byte signature[])
434
434
return 1 ;
435
435
}
436
436
437
- int ECC508Class ::read (int zone, int address, byte buffer[], int length)
437
+ int ECCX08Class ::read (int zone, int address, byte buffer[], int length)
438
438
{
439
439
if (!wakeup ()) {
440
440
return 0 ;
@@ -464,7 +464,7 @@ int ECC508Class::read(int zone, int address, byte buffer[], int length)
464
464
return length;
465
465
}
466
466
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)
468
468
{
469
469
uint8_t status;
470
470
@@ -500,7 +500,7 @@ int ECC508Class::write(int zone, int address, const byte buffer[], int length)
500
500
return 1 ;
501
501
}
502
502
503
- int ECC508Class ::lock (int zone)
503
+ int ECCX08Class ::lock (int zone)
504
504
{
505
505
uint8_t status;
506
506
@@ -528,15 +528,15 @@ int ECC508Class::lock(int zone)
528
528
return 1 ;
529
529
}
530
530
531
- int ECC508Class ::addressForSlotOffset (int slot, int offset)
531
+ int ECCX08Class ::addressForSlotOffset (int slot, int offset)
532
532
{
533
533
int block = offset / 32 ;
534
534
offset = (offset % 32 ) / 4 ;
535
535
536
536
return (slot << 3 ) | (block << 8 ) | (offset);
537
537
}
538
538
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)
540
540
{
541
541
int commandLength = 8 + dataLength; // 1 for type, 1 for length, 1 for opcode, 1 for param1, 2 for param2, 2 for crc
542
542
byte command[commandLength];
@@ -560,7 +560,7 @@ int ECC508Class::sendCommand(uint8_t opcode, uint8_t param1, uint16_t param2, co
560
560
return 1 ;
561
561
}
562
562
563
- int ECC508Class ::receiveResponse (void * response, size_t length)
563
+ int ECCX08Class ::receiveResponse (void * response, size_t length)
564
564
{
565
565
int retries = 20 ;
566
566
int responseSize = length + 3 ; // 1 for length header, 2 for CRC
@@ -590,7 +590,7 @@ int ECC508Class::receiveResponse(void* response, size_t length)
590
590
return 1 ;
591
591
}
592
592
593
- uint16_t ECC508Class ::crc16 (const byte data[], size_t length)
593
+ uint16_t ECCX08Class ::crc16 (const byte data[], size_t length)
594
594
{
595
595
if (data == NULL || length == 0 ) {
596
596
return 0 ;
@@ -619,4 +619,4 @@ uint16_t ECC508Class::crc16(const byte data[], size_t length)
619
619
return crc;
620
620
}
621
621
622
- ECC508Class ECC508 (Wire, 0x60 );
622
+ ECCX08Class ECCX08 (Wire, 0x60 );
0 commit comments