Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@evil-cry
Copy link

Add Ascon128 AEAD cipher provider implementation

This PR adds a complete OpenSSL provider implementation for ASCON-128. The implementation supports both streaming and one-shot encryption/decryption operations with AAD, and follows established provider patterns for stream ciphers in OpenSSL.

Note: the LibAscon implementation added to libcrypto should be considered temporary. @bbbrumley will add a cleanroom implementation of ascon128 in future.

  • documentation is added or updated
  • tests are added or updated

Part of an ongoing issue: #28271

Co-authored by: Dominic Cunningham [email protected]
Co-authored by: Jack Barsa [email protected]
Supervised by: Billy Brumley [email protected]

…SL tree

- Added providers/implementations/ciphers/cipher_ascon128.c
- Added providers/implementations/ciphers/cipher_ascon128.h
- Added providers/implementations/ciphers/ciphercommon_ascon.c
- Added providers/implementations/ciphers/ciphercommon_ascon.h
- Updated #include with openssl internal includes
- Updated error codes with standard PROV_R_* codes

This is beginning of an ongoing migration in openssl#28271

Co-authored-by: @Jcb5272
- Update function names from ossl_cipher_ascon128_* to ascon128_*
- Make all functions static, matching the pattern used by fixed-key ciphers
- Reorder dispatch table to OpenSSL standard order and remove function declarations from header file.

openssl#28271
- Add ascon128 cipher to the build configuration
- creating a libcrypto header stub for ascon

openssl#28271
- Add ASCON-128 to algorithm registration in defltprov.c, implementations.h, and names.h
- Preserve AEAD tag during context reinitialization for decryption to prevent tag loss when EVP_CipherInit_ex is called after tag is set
- Add IV tracking support for get_updated_iv by storing IV in context and implementing OSSL_CIPHER_PARAM_UPDATED_IV
- Add key and IV length validation in ascon128_internal_init for better error handling
- Improve AAD handling in update function and add null pointer checks for outl parameter
- Changes based on patterns used by ChaCha and AES-SIV ciphers
- Replace incorrectly converted test vector with verified official test vector
# include "ascon_internal.h"

ASCON_API void
ascon_aead128_encrypt(uint8_t* ciphertext,
Copy link
Member

Choose a reason for hiding this comment

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

The notation for internal global functions should be prefixed with ossl_.
(NOTE: This is not necessary for static functions).

size_t tag_len)
{
ASCON_ASSERT(plaintext_len == 0 || ciphertext != NULL);
ASCON_ASSERT(tag_len != 0 || tag != NULL);
Copy link
Member

Choose a reason for hiding this comment

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

SP800-232 has minimum AEAD requirements in Section 4.3.
See R4 for minimum tag length.

size_t plaintext_len,
size_t tag_len)
{
ASCON_ASSERT(plaintext_len == 0 || ciphertext != NULL);
Copy link
Member

Choose a reason for hiding this comment

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

These asserts are not how we handle errors in OpenSSL.

Copy link
Author

Choose a reason for hiding this comment

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

I've replaced with ossl_assert in the cleanroom implementation, is there another preferred way for this input validation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Try the style guide section on asserts.

As a rule, the preference is for ossl_assert as part of an if statement which returns an error.

size_t plaintext_len,
size_t tag_len)
{
ASCON_ASSERT(plaintext_len == 0 || ciphertext != NULL);
Copy link
Member

Choose a reason for hiding this comment

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

potentially the plaintext could be nothing.

ASCON_ASSERT(tag_len != 0 || tag != NULL);
ASCON_ASSERT(key != NULL);
ASCON_ASSERT(nonce != NULL);
ASCON_ASSERT(assoc_data_len == 0 || assoc_data != NULL);
Copy link
Member

Choose a reason for hiding this comment

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

associated data should be able to be null I would expect.

Copy link
Member

@slontis slontis left a comment

Choose a reason for hiding this comment

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

Is this implementation conforming to SP800-232?
Because that is what OpenSSL would need to support.
(In much the same way that for PQ algorithms we implemented the FIPS 203/204/205 standards not dillithium, etc that they were based on).

SP800-232 Section 1 lists 7 differences that should be adhered to.
For example little endian vs big endian.. And it looks like this code is Big Endian..

I think the CLA issue relating to the original authors needs to be sorted before any extensive reviews are done on this
code (otherwise we are just wasting our time)

@slontis
Copy link
Member

slontis commented Nov 11, 2025

Code Style checks should be fixed if they are relevant..

@t8m t8m added approval: review pending This pull request needs review by a committer branch: master Merge to master branch triaged: feature The issue/pr requests/adds a feature tests: present The PR has suitable tests present labels Nov 11, 2025
@evil-cry
Copy link
Author

Is this implementation conforming to SP800-232? Because that is what OpenSSL would need to support. (In much the same way that for PQ algorithms we implemented the FIPS 203/204/205 standards not dillithium, etc that they were based on).

SP800-232 Section 1 lists 7 differences that should be adhered to. For example little endian vs big endian.. And it looks like this code is Big Endian..

I think the CLA issue relating to the original authors needs to be sorted before any extensive reviews are done on this code (otherwise we are just wasting our time)

The implementation added to libcrypto is based on the NIST draft, which can account for some differences like big endian vs little endian. Dr. Brumley @bbbrumley is writing a new implementation based on the NIST standard, and will conform to OpenSSL standards. This affects all of the files in crypto/ascon.

With this change in mind should I continue to make changes based on the reviews for the crypto implementation or wait for an update from BBB, and focus on the provider changes required? Sorry if I submitted the PR too early, wanted to get it in earlier with such a big diff.

@evil-cry
Copy link
Author

Forgot to include in my initial description, but the original implementation of the provider was written by @romen and @theakifmehmood. They should both have CLAs available.

@t8m
Copy link
Member

t8m commented Nov 11, 2025

With this change in mind should I continue to make changes based on the reviews for the crypto implementation or wait for an update from BBB, and focus on the provider changes required? Sorry if I submitted the PR too early, wanted to get it in earlier with such a big diff.

I would definitely then suggest focusing on the provider changes.

@t8m t8m marked this pull request as draft November 11, 2025 15:02
@t8m
Copy link
Member

t8m commented Nov 11, 2025

I've converted it into a draft until the implementation is replaced with a standard version.

@slontis
Copy link
Member

slontis commented Nov 11, 2025

With this change in mind should I continue to make changes based on the reviews for the crypto implementation or wait for an update from BBB, and focus on the provider changes required? Sorry if I submitted the PR too early, wanted to get it in earlier with such a big diff.

I would definitely then suggest focusing on the provider changes.

If they havent already done it, the suggestion in
#29115 (review)
would be useful also.

@bbbrumley
Copy link
Contributor

Just wanted to say, thanks so much for the feedback so far @slontis and @paulidale and indeed, thanks @t8m for putting this in draft state. def WIP rn. To note:

  • the license issue (and libascon dependency) will go away when we drop in the cleanroom ascon code
  • yes we will handle the LE vs BE issues

Thanks for the initiative @evil-cry

@slontis
Copy link
Member

slontis commented Nov 12, 2025

Sounds like a good plan. Would be good to get into 4.0 if we can. Are you planning on XOF and hash also?
I can do the FIPS provider/self tests part if you want a hand.

@evil-cry
Copy link
Author

Sounds like a good plan. Would be good to get into 4.0 if we can. Are you planning on XOF and hash also? I can do the FIPS provider/self tests part if you want a hand.

Yes, we are planning to implement XOF and hash as well. A hand with FIPS would be greatly appreciated once we get everything squared away!

…ation

- Update function names, variables, and file names from ascon128_* to ascon_aead128_*
- Update build files and algorithm registration from ascon128_* to ascon_aead128_*
- Update crypto implementation from ascon128 to ascon128a based on NIST SP800-232
- TODO: Update test vectors based on ascon128a
- Remove redundant ciphercommon_ascon files and inline necessary definitions.
- Order struct members by type, remove unnecessary typedef, and use OPENSSL_cleanse for sensitive data. Simplify dupctx() to use struct assignment and remove redundant cleanup.
- Remove OSSL_CIPHER_PARAM_AEAD_AAD parameter as AAD is handled via update() when out is NULL.
- Update definitions and function signatures to match provider implementation
- Add OPENSSL_cleanse() for secure cleanup of sensitive state, keys, and tags
- Add input validation (NULL checks) to all public functions to ensure proper error handling for provider integration.
Add cleanroom implementation of SP 800-232 to libcrypto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: review pending This pull request needs review by a committer branch: master Merge to master branch tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants