44#if defined(ASCON_INPUT_ASSERTS) && !defined(ASCON_ASSERT)
61#undef ASCON_INPUT_ASSERTS
62#define ASCON_INPUT_ASSERTS 1
73#define ASCON_ASSERT(expr) assert(expr)
74#elif !defined(ASCON_ASSERT)
77#define ASCON_ASSERT(expr)
85#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__NT__)
91#define ASCON_WINDOWS 1
92#define ASCON_API __declspec(dllexport)
98#define ASCON_API_VERSION_MAJOR 1
100#define ASCON_API_VERSION_MINOR 2
102#define ASCON_API_VERSION_BUGFIX 1
104#define ASCON_API_VERSION "1.2.1"
109#define ASCON_AEAD128_KEY_LEN 16U
114#define ASCON_AEAD128a_KEY_LEN 16U
119#define ASCON_AEAD80pq_KEY_LEN 20U
125#define ASCON_AEAD_NONCE_LEN 16U
131#define ASCON_AEAD_TAG_MIN_SECURE_LEN 16U
137#define ASCON_HASH_DIGEST_LEN 32U
143#define ASCON_HASHA_DIGEST_LEN ASCON_HASH_DIGEST_LEN
156#define ASCON_DOUBLE_RATE (2U * ASCON_RATE)
161#define ASCON_TAG_OK true
166#define ASCON_TAG_INVALID false
293 const uint8_t* assoc_data,
294 const uint8_t* plaintext,
295 size_t assoc_data_len,
296 size_t plaintext_len,
383 const uint8_t* assoc_data,
384 size_t assoc_data_len);
429 const uint8_t* plaintext,
430 size_t plaintext_len);
526 const uint8_t* assoc_data,
527 const uint8_t* ciphertext,
528 const uint8_t* expected_tag,
529 size_t assoc_data_len,
530 size_t ciphertext_len,
531 size_t expected_tag_len);
570 const uint8_t* ciphertext,
571 size_t ciphertext_len);
620 const uint8_t* expected_tag,
621 size_t expected_tag_len);
691 const uint8_t* assoc_data,
692 const uint8_t* plaintext,
693 size_t assoc_data_len,
694 size_t plaintext_len,
784 const uint8_t* assoc_data,
785 size_t assoc_data_len);
830 const uint8_t* plaintext,
831 size_t plaintext_len);
929 const uint8_t* assoc_data,
930 const uint8_t* ciphertext,
931 const uint8_t* expected_tag,
932 size_t assoc_data_len,
933 size_t ciphertext_len,
934 size_t expected_tag_len);
973 const uint8_t* ciphertext,
974 size_t ciphertext_len);
1024 const uint8_t* expected_tag,
1025 size_t expected_tag_len);
1076 const uint8_t* assoc_data,
1077 const uint8_t* plaintext,
1078 size_t assoc_data_len,
1079 size_t plaintext_len,
1170 const uint8_t* assoc_data,
1171 size_t assoc_data_len);
1215 uint8_t* ciphertext,
1216 const uint8_t* plaintext,
1217 size_t plaintext_len);
1266 uint8_t* ciphertext,
1315 const uint8_t* assoc_data,
1316 const uint8_t* ciphertext,
1317 const uint8_t* expected_tag,
1318 size_t assoc_data_len,
1319 size_t ciphertext_len,
1320 size_t expected_tag_len);
1359 const uint8_t* ciphertext,
1360 size_t ciphertext_len);
1409 const uint8_t* expected_tag,
1410 size_t expected_tag_len);
1435 const uint8_t* data,
1462 const uint8_t* data,
1496 const uint8_t* data,
1531 const uint8_t* data,
1603 const uint8_t* data,
1625 const uint8_t* data,
1767 const uint8_t* data,
1803 const uint8_t* data,
1846 const uint8_t* data,
1847 size_t expected_digest_len,
1890 const uint8_t* data,
1891 size_t expected_digest_len,
1964 const uint8_t* data,
1987 const uint8_t* data,
2078 const uint8_t* expected_digest,
2079 size_t expected_digest_len);
2105 const uint8_t* expected_digest,
2106 size_t expected_digest_len);
ASCON_API bool ascon_aead80pq_decrypt(uint8_t *plaintext, const uint8_t key[ASCON_AEAD80pq_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN], const uint8_t *assoc_data, const uint8_t *ciphertext, const uint8_t *expected_tag, size_t assoc_data_len, size_t ciphertext_len, size_t expected_tag_len)
Offline symmetric decryption using Ascon80pq, which uses a larger key compared to Ascon128.
ASCON_API bool ascon_hash_xof_matches(const uint8_t *expected_digest, const uint8_t *data, size_t expected_digest_len, size_t data_len)
Offline Ascon-Hash with custom digest length (eXtendable Output Function, XOF) and validation of the ...
ASCON_API void ascon_hasha_final(ascon_hash_ctx_t *ctx, uint8_t digest[ASCON_HASHA_DIGEST_LEN])
Online Ascon-Hasha with fixed digest length, finalisation and digest generation.
ASCON_API bool ascon_hash_final_matches(ascon_hash_ctx_t *ctx, const uint8_t expected_digest[ASCON_HASH_DIGEST_LEN])
Online Ascon-Hasha with fixed digest length, finalisation and digest validation of the expected one.
ASCON_API bool ascon_hasha_xof_final_matches(ascon_hash_ctx_t *ctx, const uint8_t *expected_digest, size_t expected_digest_len)
Online Ascon-Hasha with custom digest length (eXtendable Output Function, XOF), finalisation and dige...
ASCON_API void ascon_hash_init(ascon_hash_ctx_t *ctx)
Online Ascon-Hash with fixed digest length, initialisation.
#define ASCON_HASH_DIGEST_LEN
Length in bytes of the digest generated by the fixed-size (non-xof) hash function.
Definition: ascon.h:137
ASCON_API void ascon_hasha_xof_final(ascon_hash_ctx_t *ctx, uint8_t *digest, size_t digest_len)
Online Ascon-Hasha with custom digest length (eXtendable Output Function, XOF), finalisation and dige...
ASCON_API void ascon_hash_xof_init(ascon_hash_ctx_t *ctx)
Online Ascon-Hash with custom digest length (eXtendable Output Function, XOF), initialisation.
ASCON_API void ascon_aead80pq_init(ascon_aead_ctx_t *ctx, const uint8_t key[ASCON_AEAD80pq_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN])
Online symmetric encryption/decryption using Ascon80pq, initialisation - note that a larger key is us...
#define ASCON_AEAD128a_KEY_LEN
Length in bytes of the secret symmetric key used for the Ascon128a cipher.
Definition: ascon.h:114
ASCON_API void ascon_aead128_init(ascon_aead_ctx_t *ctx, const uint8_t key[ASCON_AEAD128_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN])
Online symmetric encryption/decryption using Ascon128, initialisation.
ASCON_API void ascon_aead128_assoc_data_update(ascon_aead_ctx_t *ctx, const uint8_t *assoc_data, size_t assoc_data_len)
Online symmetric encryption/decryption using Ascon128, feeding associated data.
#define ASCON_HASHA_DIGEST_LEN
Length in bytes of the digest generated by the fixed-size (non-xof) hasha function.
Definition: ascon.h:143
#define ASCON_API
Marker of all the library's public API functions.
Definition: ascon.h:92
ASCON_API size_t ascon_aead80pq_decrypt_update(ascon_aead_ctx_t *ctx, uint8_t *plaintext, const uint8_t *ciphertext, size_t ciphertext_len)
Online symmetric decryption using Ascon80pq, feeding ciphertext and getting plaintext.
#define ASCON_DOUBLE_RATE
Number of bytes the cipher can process at the time in AEAD128a mode.
Definition: ascon.h:156
ASCON_API void ascon_hash_cleanup(ascon_hash_ctx_t *ctx)
Security cleanup of the hashing context, in case the online processing is not completed to the end.
ASCON_API void ascon_hasha_xof_update(ascon_hash_ctx_t *ctx, const uint8_t *data, size_t data_len)
Online Ascon-Hasha with custom digest length (eXtendable Output Function, XOF), feeding data to hash.
ASCON_API size_t ascon_aead80pq_encrypt_final(ascon_aead_ctx_t *ctx, uint8_t *ciphertext, uint8_t *tag, size_t tag_len)
Online symmetric encryption using Ascon80pq, finalisation and tag generation.
#define ASCON_AEAD128_KEY_LEN
Length in bytes of the secret symmetric key used for the Ascon128 cipher.
Definition: ascon.h:109
ASCON_API size_t ascon_aead128_decrypt_update(ascon_aead_ctx_t *ctx, uint8_t *plaintext, const uint8_t *ciphertext, size_t ciphertext_len)
Online symmetric decryption using Ascon128, feeding ciphertext and getting plaintext.
ASCON_API size_t ascon_aead128a_encrypt_final(ascon_aead_ctx_t *ctx, uint8_t *ciphertext, uint8_t *tag, size_t tag_len)
Online symmetric encryption using Ascon128a, finalisation and tag generation.
ASCON_API size_t ascon_aead128_encrypt_final(ascon_aead_ctx_t *ctx, uint8_t *ciphertext, uint8_t *tag, size_t tag_len)
Online symmetric encryption using Ascon128, finalisation and tag generation.
ascon_bufstate_t ascon_hash_ctx_t
Cipher context for hashing.
Definition: ascon.h:221
ASCON_API void ascon_hash_xof_update(ascon_hash_ctx_t *ctx, const uint8_t *data, size_t data_len)
Online Ascon-Hash with custom digest length (eXtendable Output Function, XOF), feeding data to hash.
ASCON_API size_t ascon_aead80pq_encrypt_update(ascon_aead_ctx_t *ctx, uint8_t *ciphertext, const uint8_t *plaintext, size_t plaintext_len)
Online symmetric encryption using Ascon80pq, feeding plaintext and getting ciphertext.
ASCON_API bool ascon_aead128a_decrypt(uint8_t *plaintext, const uint8_t key[ASCON_AEAD128a_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN], const uint8_t *assoc_data, const uint8_t *ciphertext, const uint8_t *expected_tag, size_t assoc_data_len, size_t ciphertext_len, size_t expected_tag_len)
Offline symmetric decryption using Ascon128a, which uses a double data rate compared to Ascon128.
ASCON_API void ascon_aead128a_assoc_data_update(ascon_aead_ctx_t *ctx, const uint8_t *assoc_data, size_t assoc_data_len)
Online symmetric encryption/decryption using Ascon128a, feeding associated data.
ASCON_API bool ascon_hasha_final_matches(ascon_hash_ctx_t *ctx, const uint8_t expected_digest[ASCON_HASHA_DIGEST_LEN])
Online Ascon-Hasha with fixed digest length, finalisation and digest validation of the expected one.
ASCON_API size_t ascon_aead128a_encrypt_update(ascon_aead_ctx_t *ctx, uint8_t *ciphertext, const uint8_t *plaintext, size_t plaintext_len)
Online symmetric encryption using Ascon128a, feeding plaintext and getting ciphertext.
ASCON_API bool ascon_hash_xof_final_matches(ascon_hash_ctx_t *ctx, const uint8_t *expected_digest, size_t expected_digest_len)
Online Ascon-Hash with custom digest length (eXtendable Output Function, XOF), finalisation and diges...
ASCON_API void ascon_hasha(uint8_t digest[ASCON_HASHA_DIGEST_LEN], const uint8_t *data, size_t data_len)
Offline Ascon-Hasha with fixed digest length.
ASCON_API bool ascon_hasha_xof_matches(const uint8_t *expected_digest, const uint8_t *data, size_t expected_digest_len, size_t data_len)
Offline Ascon-Hasha with custom digest length (eXtendable Output Function, XOF) and validation of the...
ASCON_API bool ascon_aead128_decrypt(uint8_t *plaintext, const uint8_t key[ASCON_AEAD128_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN], const uint8_t *assoc_data, const uint8_t *ciphertext, const uint8_t *expected_tag, size_t assoc_data_len, size_t ciphertext_len, size_t expected_tag_len)
Offline symmetric decryption using Ascon128.
ASCON_API size_t ascon_aead128a_decrypt_final(ascon_aead_ctx_t *ctx, uint8_t *plaintext, bool *is_tag_valid, const uint8_t *expected_tag, size_t expected_tag_len)
Online symmetric decryption using Ascon128a, finalisation and tag validation.
ASCON_API size_t ascon_aead128_encrypt_update(ascon_aead_ctx_t *ctx, uint8_t *ciphertext, const uint8_t *plaintext, size_t plaintext_len)
Online symmetric encryption using Ascon128, feeding plaintext and getting ciphertext.
ASCON_API void ascon_hash(uint8_t digest[ASCON_HASH_DIGEST_LEN], const uint8_t *data, size_t data_len)
Offline Ascon-Hash with fixed digest length.
struct ascon_sponge ascon_sponge_t
Internal cipher sponge state (320 bits).
ASCON_API void ascon_aead128_encrypt(uint8_t *ciphertext, uint8_t *tag, const uint8_t key[ASCON_AEAD128_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN], const uint8_t *assoc_data, const uint8_t *plaintext, size_t assoc_data_len, size_t plaintext_len, size_t tag_len)
Offline symmetric encryption using Ascon128.
ASCON_API size_t ascon_aead80pq_decrypt_final(ascon_aead_ctx_t *ctx, uint8_t *plaintext, bool *is_tag_valid, const uint8_t *expected_tag, size_t expected_tag_len)
Online symmetric decryption using Ascon80pq, finalisation and tag validation.
ASCON_API void ascon_aead128a_encrypt(uint8_t *ciphertext, uint8_t *tag, const uint8_t key[ASCON_AEAD128_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN], const uint8_t *assoc_data, const uint8_t *plaintext, size_t assoc_data_len, size_t plaintext_len, size_t tag_len)
Offline symmetric encryption using Ascon128a, which uses a double data rate compared to Ascon128.
ASCON_API void ascon_hasha_xof(uint8_t *digest, const uint8_t *data, size_t digest_len, size_t data_len)
Offline Ascon-Hasha with custom digest length (eXtendable Output Function, XOF).
ASCON_API void ascon_hasha_init(ascon_hash_ctx_t *ctx)
Online Ascon-Hasha with fixed digest length, initialisation.
ASCON_API void ascon_hash_final(ascon_hash_ctx_t *ctx, uint8_t digest[ASCON_HASH_DIGEST_LEN])
Online Ascon-Hash with fixed digest length, finalisation and digest generation.
ASCON_API bool ascon_hasha_matches(const uint8_t expected_digest[ASCON_HASHA_DIGEST_LEN], const uint8_t *data, size_t data_len)
Offline Ascon-Hasha with fixed digest length, finalisation and digest validation of the expected one.
ASCON_API void ascon_aead80pq_assoc_data_update(ascon_aead_ctx_t *ctx, const uint8_t *assoc_data, size_t assoc_data_len)
Online symmetric encryption/decryption using Ascon80pq, feeding associated data.
ASCON_API void ascon_hash_xof(uint8_t *digest, const uint8_t *data, size_t digest_len, size_t data_len)
Offline Ascon-Hash with custom digest length (eXtendable Output Function, XOF).
ASCON_API void ascon_aead_cleanup(ascon_aead_ctx_t *ctx)
Security cleanup of the AEAD context, in case the online processing is not completed to the end.
ASCON_API void ascon_hasha_update(ascon_hash_ctx_t *ctx, const uint8_t *data, size_t data_len)
Online Ascon-Hasha with fixed digest length, feeding data to hash.
ASCON_API size_t ascon_aead128_decrypt_final(ascon_aead_ctx_t *ctx, uint8_t *plaintext, bool *is_tag_valid, const uint8_t *expected_tag, size_t expected_tag_len)
Online symmetric decryption using Ascon128, finalisation and tag validation.
ASCON_API size_t ascon_aead128a_decrypt_update(ascon_aead_ctx_t *ctx, uint8_t *plaintext, const uint8_t *ciphertext, size_t ciphertext_len)
Online symmetric decryption using Ascon128a, feeding ciphertext and getting plaintext.
ASCON_API void ascon_hasha_xof_init(ascon_hash_ctx_t *ctx)
Online Ascon-Hasha with custom digest length (eXtendable Output Function, XOF), initialisation.
struct ascon_bufstate ascon_bufstate_t
Internal cipher sponge state associated with a buffer holding for less-than-rate updates.
ASCON_API void ascon_aead128a_init(ascon_aead_ctx_t *ctx, const uint8_t key[ASCON_AEAD128a_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN])
Online symmetric encryption/decryption using Ascon128a, initialisation.
ASCON_API void ascon_hash_update(ascon_hash_ctx_t *ctx, const uint8_t *data, size_t data_len)
Online Ascon-Hash with fixed digest length, feeding data to hash.
#define ASCON_AEAD80pq_KEY_LEN
Length in bytes of the secret symmetric key used for the Ascon80pq cipher.
Definition: ascon.h:119
ASCON_API bool ascon_hash_matches(const uint8_t expected_digest[ASCON_HASH_DIGEST_LEN], const uint8_t *data, size_t data_len)
Offline Ascon-Hash with fixed digest length, finalisation and digest validation of the expected one.
struct ascon_aead_ctx ascon_aead_ctx_t
Cipher context for authenticated encryption and validated decryption.
#define ASCON_AEAD_NONCE_LEN
Length in bytes of the public nonce used for authenticated encryption and decryption.
Definition: ascon.h:125
ASCON_API void ascon_hash_xof_final(ascon_hash_ctx_t *ctx, uint8_t *digest, size_t digest_len)
Online Ascon-Hash with custom digest length (eXtendable Output Function, XOF), finalisation and diges...
ASCON_API void ascon_aead80pq_encrypt(uint8_t *ciphertext, uint8_t *tag, const uint8_t key[ASCON_AEAD80pq_KEY_LEN], const uint8_t nonce[ASCON_AEAD_NONCE_LEN], const uint8_t *assoc_data, const uint8_t *plaintext, size_t assoc_data_len, size_t plaintext_len, size_t tag_len)
Offline symmetric encryption using Ascon80pq, which uses a larger key.
Cipher context for authenticated encryption and validated decryption.
Definition: ascon.h:230
uint64_t k2
Copy of the secret key, to be used in the final step, third part, used only in the Ascon80pq cipher.
Definition: ascon.h:242
uint64_t k0
Copy of the secret key, to be used in the final step, first part.
Definition: ascon.h:235
uint64_t k1
Copy of the secret key, to be used in the final step, second part.
Definition: ascon.h:238
ascon_bufstate_t bufstate
Cipher buffered sponge state.
Definition: ascon.h:232
Internal cipher sponge state associated with a buffer holding for less-than-rate updates.
Definition: ascon.h:190
uint8_t buffer[ASCON_DOUBLE_RATE]
Buffer caching the less-than-rate long input between update calls.
Definition: ascon.h:195
uint8_t buffer_len
Currently used bytes of the buffer.
Definition: ascon.h:198
ascon_sponge_t sponge
Cipher sponge state.
Definition: ascon.h:192
uint8_t pad[6]
Unused padding to the next uint64_t (sponge.x0 or ctx.k0) to avoid errors when compiling with -Wpaddi...
Definition: ascon.h:217
uint8_t flow_state
State of the order of Init-Update-Final function calls, checked to know when to finalise the associat...
Definition: ascon.h:213
Internal cipher sponge state (320 bits).
Definition: ascon.h:172
uint64_t x2
Sponge's third field.
Definition: ascon.h:178
uint64_t x3
Sponge's fourth field.
Definition: ascon.h:180
uint64_t x1
Sponge's second field.
Definition: ascon.h:176
uint64_t x0
Sponge's first field.
Definition: ascon.h:174
uint64_t x4
Sponge's fifth field.
Definition: ascon.h:182