Skip to content

CHACHA20_POLY1305 support#673

Open
ilie-halip-nxp wants to merge 4 commits intolatchset:mainfrom
ilie-halip-nxp:feature/chacha20_poly1305
Open

CHACHA20_POLY1305 support#673
ilie-halip-nxp wants to merge 4 commits intolatchset:mainfrom
ilie-halip-nxp:feature/chacha20_poly1305

Conversation

@ilie-halip-nxp
Copy link
Collaborator

@ilie-halip-nxp ilie-halip-nxp commented Jan 20, 2026

Description

Add support for CHACHA20_POLY1305 AEAD mechanism. This piggybacks on the current AES-GCM code because in most cases they behave the same.

The IV length is hardcoded to 12, and the tag length to 16. Both these values are specified in PKCS#11.

Checklist

  • Code modified for feature
  • Test suite updated with functionality tests
  • Test suite updated with negative tests
  • Documentation updated

Reviewer's checklist:

  • Any issues marked for closing are addressed
  • There is a test suite reasonably covering new functionality or modifications
  • This feature/change has adequate documentation added
  • Code conform to coding style that today cannot yet be enforced via the check style test
  • Commits have short titles and sensible commit messages
  • Coverity Scan has run if needed (code PR) and no new defects were found

@simo5
Copy link
Member

simo5 commented Jan 20, 2026

I guess you need to make some of the TLS tests run conditionally?

@ilie-halip-nxp
Copy link
Collaborator Author

I think at least some of the failures are due to some ciphers not being built into openssl. I added a check for cipher availability, let's see how the tests look.

@simo5 simo5 added the covscan Triggers Coverity Scanner label Jan 20, 2026
@github-actions github-actions bot removed the covscan Triggers Coverity Scanner label Jan 20, 2026
Copy link
Member

@simo5 simo5 left a comment

Choose a reason for hiding this comment

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

Mostly just code organization issues, I will take another pass once the two ciphers are better separated

@simo5 simo5 added the covscan-ok Coverity scan passed label Jan 20, 2026
@github-actions github-actions bot removed the covscan-ok Coverity scan passed label Jan 23, 2026
@ilie-halip-nxp ilie-halip-nxp force-pushed the feature/chacha20_poly1305 branch from e801e38 to 5b70dfe Compare January 23, 2026 17:44
Copy link
Member

@simo5 simo5 left a comment

Choose a reason for hiding this comment

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

Thanks for the cosmetic changes, I have just one more, if you can squash and rebase as you apply it I can then review and merge, I do not see anything else out of place.

@simo5 simo5 added the covscan-ok Coverity scan passed label Jan 23, 2026
@ilie-halip-nxp ilie-halip-nxp force-pushed the feature/chacha20_poly1305 branch from 5b70dfe to 00568d3 Compare January 26, 2026 07:18
@github-actions github-actions bot removed the covscan-ok Coverity scan passed label Jan 26, 2026
@ilie-halip-nxp ilie-halip-nxp force-pushed the feature/chacha20_poly1305 branch 2 times, most recently from e45af82 to 13d3d32 Compare January 27, 2026 09:26
@simo5 simo5 added the covscan Triggers Coverity Scanner label Jan 27, 2026
@github-actions github-actions bot removed the covscan Triggers Coverity Scanner label Jan 27, 2026
Copy link
Member

@simo5 simo5 left a comment

Choose a reason for hiding this comment

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

Just a couple of minor nits, but this looks good now and is basically ready to merge

src/cipher.c Outdated
return CKR_ARGUMENTS_BAD;
}

if (!ivlen && ivlen > EVP_MAX_IV_LENGTH) {
Copy link
Member

Choose a reason for hiding this comment

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

This is hard to parse, is this trying to ensure (ivlen != 0) ? if that is the case please explicitly write it that way, we use !var basically only for pointers.

Copy link
Member

@simo5 simo5 Jan 27, 2026

Choose a reason for hiding this comment

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

Note that Covscan also mark this as dead code because I this translates to:
if (ivlen == 0 && ivlen > EVP_MAX_IV_LENGHT)
which is an impossible condition.

src/cipher.c Outdated
CK_SALSA20_CHACHA20_POLY1305_MSG_PARAMS_PTR chacha =
(CK_SALSA20_CHACHA20_POLY1305_MSG_PARAMS_PTR)mech->pParameter;

if (iv && ivlen) {
Copy link
Member

Choose a reason for hiding this comment

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

&& ivlen != 0 please

Similarly to AES-GCM, add CHACHA20_POLY1305 AEAD support. It requrires
a 96-bit nonce, as that selects the CHACHA20 algorithm variant instead
of the original SALSA20. The tag length is hardcoded to 16, which is
the minimum required by the PKCS#11 spec.

This includes a bit of refactoring to make the code for GCM & POLY1305
simpler.

Signed-off-by: Ilie Halip <ilie.halip@nxp.com>
Add CHACHA20_POLY1305 to the list for AEAD algorithms that can be
tested.

Since this algorithms only supports a 96-bit nonce, hardcode the IV
instead of trying multiple IV lengths, also for GCM.

Signed-off-by: Ilie Halip <ilie.halip@nxp.com>
To make sure multiple ciphersuites are exercised in the tests (not just
the ones that are negociated by the server+client), add more cases for
explicit ciphersuites.

Signed-off-by: Ilie Halip <ilie.halip@nxp.com>
SKEY_SUPPORT is not defined for the test sources, use an OpenSSL macro
instead.

Moreover, tokens may support only a subset of AEAD algorithms, so skip
algorithms that are not available.

Signed-off-by: Ilie Halip <ilie.halip@nxp.com>
@ilie-halip-nxp ilie-halip-nxp force-pushed the feature/chacha20_poly1305 branch from 13d3d32 to 3c6fc6e Compare February 2, 2026 08:41
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.

2 participants