cnpack / cnvcl

CnPack VCL Components
http://www.cnpack.org
341 stars 103 forks source link

Adding Support for CnXChaCha20 with 512-bit Key and 256-bit Nonce #31

Closed CryptonicToy closed 1 year ago

CryptonicToy commented 1 year ago

Hello everyone,

I hope you're all doing well. I wanted to let you know about some exciting updates I've been working on for the CnVCL Delphi project.

Firstly, I've created a new file called CnXChaCha20.pas, which is based on the original CnChaCha20.pas. In this new version, I've significantly improved the security and flexibility by increasing the key size from 256-bit to a more robust 512-bit, and the nonce from 192-bit to 256-bit. I've thoroughly tested this implementation to ensure its accuracy and efficiency.

Furthermore, I'm currently focused on another important addition to the project. I'm developing CnXChaCha20_Poly1305.pas, which will provide enhanced security and authentication capabilities through the use of the Poly1305 algorithm.

I'm enthusiastic about contributing these enhancements and would greatly appreciate your valuable feedback. Thank you for considering my pull request.

Best regards, CryptonicToy

shanzhashu commented 1 year ago

Thanks. We have some questions:

  1. Is there any XChaCha20 standard document or RFC ?We'll check the code by reading the documents.
  2. Is there any test case or test data for this new unit?
  3. It copies too lots of code from CnChaCha20.pas, is there a new way to re-uses them?
CryptonicToy commented 1 year ago

Some material about XChaCha20 and ChaCha20 can be found here:

https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-chacha20-poly1305-10 https://datatracker.ietf.org/doc/rfc8439/ https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03 https://datatracker.ietf.org/doc/html/draft-arciszewski-xchacha-03 https://asecuritysite.com/encryption/poly1305

I haven't compared the encryption/decryption times by data length between the original and upgraded versions.

My goal was to raise the key size to 512 bits and the Nonce to 256 bits in order to reuse the XChaCha20 unit to develop the new XChaCha20-Poly1305.

On Thu, Jul 27, 2023 at 6:17 PM Liu Xiao @.***> wrote:

Thanks. We have some questions:

  1. Is there any XChaCha20 standard document or RFC ?We'll check the code by reading the documents.
  2. Is there any test case or test data for this new unit?
  3. It copies too lots of code from CnChaCha20.pas, is there a new way to re-uses them?

— Reply to this email directly, view it on GitHub https://github.com/cnpack/cnvcl/pull/31#issuecomment-1654656345, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBRZ6LRR43WXLR2NO64WGLDXSLSITANCNFSM6AAAAAA22RRGGM . You are receiving this because you authored the thread.Message ID: @.***>

shanzhashu commented 1 year ago

Thanks for your materials. My new question is:

According to the drafts, XChaCha20 is

XChaCha20 can be constructed from an existing ChaCha20 implementation and HChaCha20. All one needs to do is:

  1. Pass the key and the first 16 bytes of the 24-byte nonce to HChaCha20 to obtain the subkey.
  2. Use the subkey and remaining 8 byte nonce with ChaCha20 as normal (prefixed by 4 NUL bytes, since [RFC8439] specifies a 12-byte nonce).

But no 'key size to 512 bits and Nonce to 256 bits' rule given? Seems Key size is still normal ChaCha20 Key size 32 bytes, and Nonce changes from ChaCha20's 12 bytes to 24 bytes.

shanzhashu commented 1 year ago

We added Key-size-32-bytes-and-Nonce-24-bytes XChaCha20Encrypt/Decrypt functions into CnChaCha20.pas now. Also ChaCha20_Poly1305 AEAD functions will be added soon.

But still don't know your mentioned new rule.

shanzhashu commented 1 year ago

Now ChaCha20_Poly1305 AEAD is ready in CnAEAD.pas for RFC 8439. XChaCha20_Poly1305 AEAD is also ready in CnAEAD.pas for draft 03.

cnpack commented 1 year ago

No more response, no standard rule document. Discard request.

If you just want to copy a new XChaCha20 unit and change to your longer params, you can just do it without commit to us.