Ascon examples#573
Conversation
Fix typos No need to input key size as the size for ascon AEAD algorithm is fixed Add an example for algorithm Ascon-Hash256
09fa582 to
d000810
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds two new usage examples for Ascon algorithms in the examples repository: one for hashing with Ascon-Hash256 and one for file encryption/decryption with Ascon-AEAD128, along with README/Makefile support so users can build and run them.
Changes:
- Add
hash/Ascon-Hash256.cand document how to run it inhash/README.md. - Add a new
crypto/ascon/example (ascon-file-encrypt.c) with a localMakefileandREADME.md. - Link the new Ascon crypto example docs from
crypto/README.md.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| hash/README.md | Documents running the new Ascon hashing example. |
| hash/Ascon-Hash256.c | New Ascon-Hash256 file hashing example program. |
| crypto/ascon/ascon-file-encrypt.c | New Ascon-AEAD128 file encrypt/decrypt example program. |
| crypto/ascon/README.md | Build/run instructions for the Ascon file encryption example. |
| crypto/ascon/Makefile | Builds the Ascon file encryption example. |
| crypto/README.md | Adds a link to the new crypto/ascon documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I will fix those errors ASAP. Thanks. |
|
Hi @helkoulak thanks for this example. I don't see you setup as a contributor. Please email support at wolfssl dot com and reference this pull request. We will send you an agreement that we need signed. In the email please include your location and a bit more about your project and interest in Ascon and our project. Also if its commercial or open source or academic. Thanks, |
Thank you David for the instructions. I will contact support ASAP. |
|
Contributor agreement on file. Thank you @helkoulak |
|
@julek-wolfssl please review . Merge when you are happy with it. |
julek-wolfssl
left a comment
There was a problem hiding this comment.
Please add crypto/ascon/ascon-file-encrypt to .gitignore. Everything looks nice but just needs more error handling.
| byte nonce[ASCON_AEAD128_NONCE_SZ] = {0}; | ||
| byte salt[SALT_SIZE] = {0}; | ||
| byte tag[ASCON_AEAD128_TAG_SZ] = {0}; | ||
| int ret = 0; |
There was a problem hiding this comment.
Default to error and then set ret = 0; on success.
| int ret = 0; | |
| int ret = 1; |
| return -1010; | ||
| } | ||
| // Assign default value for key | ||
| memcpy((char*)key, "0123456789abcdef", ASCON_AEAD128_KEY_SZ); |
There was a problem hiding this comment.
Take the key as user input the same way that aes-file-encrypt.c does.
| AsconEncrypt(ascon, key, ASCON_AEAD128_KEY_SZ, inFile, outFile); | ||
| else if (choice == 'd') | ||
| AsconDecrypt(ascon, key, ASCON_AEAD128_KEY_SZ, inFile, outFile); | ||
| } |
There was a problem hiding this comment.
We definitely want to check the return value and set the exit code appropriately.
|
|
||
|
|
||
| fseek(inFile, 0, SEEK_END); | ||
| int length = ftell(inFile); |
There was a problem hiding this comment.
Var declaration at start of block.
| byte* input = malloc(aSize); | ||
| byte* output = malloc(aSize); |
There was a problem hiding this comment.
If we're showing file encryption then let's do this in blocks. For example 4096 bytes at a time.
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| int ret = 0; |
There was a problem hiding this comment.
Error by default is easier.
| int ret = 0; | |
| int ret = 1; |
| break; | ||
| } | ||
|
|
||
| hash = (byte*) malloc(ASCON_HASH256_SZ); |
There was a problem hiding this comment.
This can be stack allocated.
| break; | ||
| } | ||
|
|
||
| ret = wc_AsconHash256_Update(asconHash, rawInput, fileLength); |
There was a problem hiding this comment.
Here also let's loop on a fixed buffer size like 4096 bytes.
Two examples that show how to use the algorithms Ascon-Hash256 and Ascon-AEAD128