-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples demonstrating how to use Ascon AEAD, Hash and Xof API
Signed-off-by: Anjan Roy <[email protected]>
- Loading branch information
1 parent
3cbf186
commit 70f4f41
Showing
16 changed files
with
148 additions
and
435 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,41 @@ | ||
#include "ascon/aead/ascon_aead128.hpp" | ||
#include "example_helper.hpp" | ||
#include <array> | ||
#include <cassert> | ||
#include <iostream> | ||
|
||
int | ||
main() | ||
{ | ||
constexpr size_t plaintext_byte_len = 64; | ||
constexpr size_t associated_data_byte_len = 32; | ||
|
||
std::array<uint8_t, ascon_aead128::KEY_BYTE_LEN> key{}; | ||
std::array<uint8_t, ascon_aead128::NONCE_BYTE_LEN> nonce{}; | ||
std::array<uint8_t, ascon_aead128::TAG_BYTE_LEN> tag{}; | ||
std::vector<uint8_t> associated_data(associated_data_byte_len); | ||
std::vector<uint8_t> plain_text(plaintext_byte_len); | ||
std::vector<uint8_t> cipher_text(plaintext_byte_len); | ||
std::vector<uint8_t> deciphered_text(plaintext_byte_len); | ||
|
||
generate_random_data<uint8_t>(key); | ||
generate_random_data<uint8_t>(nonce); | ||
generate_random_data<uint8_t>(associated_data); | ||
generate_random_data<uint8_t>(plain_text); | ||
|
||
ascon_aead128::encrypt(key, nonce, associated_data, plain_text, cipher_text, tag); | ||
const bool is_decrypted = ascon_aead128::decrypt(key, nonce, associated_data, cipher_text, deciphered_text, tag); | ||
|
||
assert(is_decrypted); | ||
assert(std::ranges::equal(plain_text, deciphered_text)); | ||
|
||
std::cout << "Ascon-AEAD128\n\n"; | ||
std::cout << "Key :\t" << bytes_to_hex_string(key) << "\n"; | ||
std::cout << "Nonce :\t" << bytes_to_hex_string(nonce) << "\n"; | ||
std::cout << "Data :\t" << bytes_to_hex_string(associated_data) << "\n"; | ||
std::cout << "Text :\t" << bytes_to_hex_string(plain_text) << "\n"; | ||
std::cout << "Encrypted :\t" << bytes_to_hex_string(cipher_text) << "\n"; | ||
std::cout << "Decrypted :\t" << bytes_to_hex_string(deciphered_text) << "\n"; | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,28 @@ | ||
#include "ascon/hashes/ascon_hash256.hpp" | ||
#include "example_helper.hpp" | ||
#include <array> | ||
#include <cassert> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
int | ||
main() | ||
{ | ||
constexpr size_t msg_byte_len = 64; | ||
|
||
std::vector<uint8_t> msg(msg_byte_len); | ||
std::array<uint8_t, ascon_hash256::DIGEST_BYTE_LEN> digest{}; | ||
|
||
generate_random_data<uint8_t>(msg); | ||
|
||
ascon_hash256::ascon_hash256_t hasher; | ||
assert(hasher.absorb(msg)); | ||
assert(hasher.finalize()); | ||
assert(hasher.digest(digest)); | ||
|
||
std::cout << "Ascon-Hash256\n\n"; | ||
std::cout << "Message :\t" << bytes_to_hex_string(msg) << "\n"; | ||
std::cout << "Digest :\t" << bytes_to_hex_string(digest) << "\n"; | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.