Skip to content

Ascon examples#573

Open
helkoulak wants to merge 8 commits into
wolfSSL:masterfrom
helkoulak:ascon-examples
Open

Ascon examples#573
helkoulak wants to merge 8 commits into
wolfSSL:masterfrom
helkoulak:ascon-examples

Conversation

@helkoulak
Copy link
Copy Markdown

Two examples that show how to use the algorithms Ascon-Hash256 and Ascon-AEAD128

Fix typos

No need to input key size as the size for ascon AEAD algorithm is fixed

Add an example for algorithm Ascon-Hash256
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.c and document how to run it in hash/README.md.
  • Add a new crypto/ascon/ example (ascon-file-encrypt.c) with a local Makefile and README.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.

Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/Makefile Outdated
Comment thread hash/README.md Outdated
Comment thread hash/Ascon-Hash256.c
Comment thread hash/Ascon-Hash256.c Outdated
Comment thread hash/Ascon-Hash256.c Outdated
@helkoulak
Copy link
Copy Markdown
Author

I will fix those errors ASAP. Thanks.

@helkoulak helkoulak removed their assignment May 5, 2026
@dgarske
Copy link
Copy Markdown
Member

dgarske commented May 5, 2026

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,
David Garske, wolfSSL

@helkoulak
Copy link
Copy Markdown
Author

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, David Garske, wolfSSL

Thank you David for the instructions. I will contact support ASAP.

@dgarske
Copy link
Copy Markdown
Member

dgarske commented May 6, 2026

Contributor agreement on file. Thank you @helkoulak

@dgarske
Copy link
Copy Markdown
Member

dgarske commented May 7, 2026

@julek-wolfssl please review . Merge when you are happy with it.

Copy link
Copy Markdown
Member

@julek-wolfssl julek-wolfssl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add crypto/ascon/ascon-file-encrypt to .gitignore. Everything looks nice but just needs more error handling.

Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c
Comment thread hash/Ascon-Hash256.c Outdated
Comment thread hash/Ascon-Hash256.c Outdated
Comment thread hash/Ascon-Hash256.c Outdated
@dgarske dgarske assigned julek-wolfssl and unassigned helkoulak May 26, 2026
fseek(inFile, 0, SEEK_SET);

byte* input = malloc(BLOCK_SIZE);
byte* output = malloc(inFileLength);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's write in BLOCK_SIZE chunks too. On error we should delete the file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output still uses a inFileLength buffer.

Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
Comment thread hash/Ascon-Hash256.c Outdated
Comment thread crypto/ascon/ascon-file-encrypt.c Outdated
@helkoulak helkoulak requested a review from julek-wolfssl May 29, 2026 22:07
Comment thread hash/Ascon-Hash256.c
goto cleanup;
}

for (int i = 0; i < BLOCK_SIZE; i += BLOCK_SIZE) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (int i = 0; i < BLOCK_SIZE; i += BLOCK_SIZE) {
for (int i = 0; i < fileLength; i += BLOCK_SIZE) {

fseek(inFile, 0, SEEK_SET);

byte* input = malloc(BLOCK_SIZE);
byte* output = malloc(inFileLength);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output still uses a inFileLength buffer.

/*
* Encrypts a file using Ascon
*/
int AsconEncrypt(wc_AsconAEAD128* ascon, byte* key, int size, FILE* inFile, FILE* outFile)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the output file on error.

/*
* Decrypts a file using Ascon
*/
int AsconDecrypt(wc_AsconAEAD128* ascon, byte* key, int size, FILE* inFile, FILE* outFile)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the output file on error.

}

// Error out on no valid password.
if (strlen(key) == 1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strip the trailing newline here to match aes-file-encrypt.c:289, and this check then becomes == 0.

Comment on lines +222 to +225
int length = 0;

fseek(inFile, 0, SEEK_END);
length = ftell(inFile);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also long so as to not truncate.

Comment thread crypto/ascon/README.md

4) Running 'make clean' will delete the executable as well as any created
files. Making sure that the only files left are 'ascon-file-encrypt.c',
'Makefile', and 'README'.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Makefile', and 'README'.
'Makefile', and 'README.md'.

@@ -0,0 +1,485 @@
/* ascon-file-encrypt.c
*
* Copyright (C) 2006-2020 wolfSSL Inc.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update to 2026

Comment thread hash/Ascon-Hash256.c
@@ -0,0 +1,134 @@
/* Ascon-Hash256.c
*
* Copyright (C) 2006-2020 wolfSSL Inc.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update to 2026

Comment thread hash/Ascon-Hash256.c
#endif
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <wolfssl/ssl.h>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants