Skip to content
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

Add Ascon Hash Algorithm #479

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Kalkwst
Copy link
Contributor

@Kalkwst Kalkwst commented Oct 14, 2024

Summary of Changes

This pull request implements the AsconHash algorithm along with the necessary cryptographic exceptions and utility functions. The changes are structured as follows:

1. AsconHash Algorithm:

  • Added two variants: AsconHash and AsconHashA.
  • Both variants follow the official Ascon specification.
  • Includes methods for:
    • Updating the hash state with input data via Update.
    • Finalizing the hash computation with DoFinal.
    • Resetting the internal state for new hashing operations with Reset.

2. Cryptographic Exceptions:

  • CryptoException: A base exception for cryptographic errors.
  • DataLengthException: Thrown when the input data length is invalid for processing.
  • OutputLengthException: Thrown when the output buffer is too short for the resulting data.

3. Utility Classes:

  • ByteEncodingUtils:
    • Provides functions for converting between byte arrays and 64-bit integers in big-endian format.
    • Includes methods for writing and reading data to/from byte arrays efficiently.
  • ValidationUtils:
    • Contains validation methods to ensure input and output buffers meet the required sizes.
    • Throws the appropriate exceptions (DataLengthException or OutputLengthException) when validation fails.

Cross-Examination of Hash Values

To ensure the accuracy and correctness of the implemented AsconHash algorithm, the resulting hash values from this implementation have been cross-examined against values generated by trusted and vetted cryptographic libraries, including Bouncy Castle. The hashes were verified to match exactly for identical input data, ensuring that this implementation is in line with established cryptographic standards and is fully compatible with the Ascon specifications.


How Ascon Algorithm Works

Ascon is a lightweight cryptographic algorithm designed to provide secure hashing and authenticated encryption. It is particularly optimized for constrained environments such as IoT devices and embedded systems. Ascon utilizes a sponge construction, which processes data in two phases:

  • Absorption Phase: The input data is XOR-ed into the internal state in 64-bit chunks. Each chunk is absorbed into the state, followed by a permutation function.
  • Squeezing Phase: After absorbing all input data, the final hash output is squeezed from the state, with additional permutations to enhance diffusion and non-linearity.

The security of Ascon comes from its permutation function (P), which performs several rounds of bitwise operations, rotations, and mixing using round constants to ensure cryptographic strength.


Context and Use Cases

Ascon was a finalist in the CAESAR competition and has since been standardized as part of the ISO/IEC 29192-6 standard for lightweight cryptography. Its design is focused on efficiency, making it ideal for:

  • IoT Devices: These devices often have limited processing power and memory, where Ascon’s lightweight operations are highly beneficial.

  • Embedded Systems: With minimal computational overhead, Ascon can be implemented in hardware or software for secure data processing.

  • Secure Communications: Ascon is suitable for hashing and encryption in protocols ensuring data integrity, such as message authentication.

  • I have performed a self-review of my code

  • My code follows the style guidelines of this project

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes

  • Comments in areas I changed are up to date

  • I have added comments to hard-to-understand areas of my code

  • I have made corresponding changes to the README.md

@Kalkwst Kalkwst requested a review from siriak as a code owner October 14, 2024 10:38
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 95.56650% with 9 lines in your changes missing coverage. Please review.

Project coverage is 95.01%. Comparing base (36a7dd6) to head (cedbc58).

Files with missing lines Patch % Lines
Algorithms/Crypto/Digests/AsconDigest.cs 95.55% 3 Missing and 3 partials ⚠️
Algorithms/Crypto/Utils/ValidationUtils.cs 85.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #479      +/-   ##
==========================================
+ Coverage   95.00%   95.01%   +0.01%     
==========================================
  Files         246      253       +7     
  Lines       10367    10570     +203     
  Branches     1478     1491      +13     
==========================================
+ Hits         9849    10043     +194     
- Misses        398      403       +5     
- Partials      120      124       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Kalkwst Kalkwst force-pushed the feature/Crypto/Digest/AsconHash branch 2 times, most recently from 43fad79 to 46638c6 Compare October 14, 2024 11:03
@Kalkwst Kalkwst force-pushed the feature/Crypto/Digest/AsconHash branch from 46638c6 to 75084ab Compare October 14, 2024 11:10
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.

1 participant