-
Notifications
You must be signed in to change notification settings - Fork 50
Adding HMAC and nonce functionality for ATECC608 #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0fe299d
Adding HMAC functionality.
RLeclair a36a841
Minor bug fix
RLeclair bca4e13
Adding HMAC and nonce example
RLeclair 0534372
Adding 508 check
RLeclair 7a9b7c2
Adding newline
RLeclair 4562d7c
Apply suggestions from code review
RLeclair 199703b
Addressing comments
RLeclair eb93d9d
Quick fix
RLeclair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
ECCX08 HMAC functionality example | ||
|
||
This sketch uses the ECC608 to generate an hmac on some data. | ||
Stores key using nonce. | ||
|
||
Used the Arduino Nano RP2040. | ||
|
||
created 10 October 2022 | ||
by Raul Leclair | ||
*/ | ||
|
||
#include <ArduinoECCX08.h> | ||
|
||
byte nonceKey[] = { | ||
0x10, 0x10, 0x10, 0x10 | ||
}; | ||
|
||
byte data[] = { | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, | ||
}; | ||
|
||
int dataLength = 72; | ||
RLeclair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
while (!Serial); | ||
|
||
if (!ECCX08.begin()) { | ||
Serial.println("Failed to initialize ECC608 board."); | ||
RLeclair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while (1); | ||
} | ||
|
||
// Perform nonce | ||
if (!ECCX08.nonce(nonceKey)) | ||
{ | ||
Serial.println("Failed to do nonce."); | ||
RLeclair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while (1); | ||
} | ||
|
||
// Starting HMAC operation on tempkey slot | ||
if (!ECCX08.beginHMAC(0xFFFF)) { | ||
RLeclair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Serial.println("Failed to start HMAC operation."); | ||
while (1); | ||
} | ||
|
||
if (!ECCX08.updateHMAC(data, dataLength)) { | ||
Serial.println("Failed to update HMAC operation."); | ||
while (1); | ||
} | ||
|
||
byte resultHMAC[32]; | ||
if (!ECCX08.endHMAC(resultHMAC)) { | ||
Serial.println("Failed to end HMAC operation"); | ||
while (1); | ||
} | ||
|
||
Serial.println("HMAC Result: "); | ||
for (int i = 0; i<sizeof(resultHMAC); i++) { | ||
RLeclair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
char hexChar[2]; | ||
sprintf(hexChar, "%02X", resultHMAC[i]); | ||
Serial.print(hexChar); | ||
Serial.print(" "); | ||
} | ||
} | ||
|
||
void loop() { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.