[WIP] Add Python ChaCha20 and bindings for CPP ChaCha20 #22851

pull siv2r wants to merge 2 commits into bitcoin:master from siv2r:chacha20-test-coverage changing 6 files +220 −47
  1. siv2r commented at 5:20 AM on September 1, 2021: none

    In reference to,

    We'll need a python chacha implementation when BIP324 lands, and the functionality in chacha20_doubleround() could be part of that, but until BIP324 I think it's fine to have it in the same file as the muhash code.

    Originally posted in #19105 (comment)

    This PR implements the following:

    • Adds Pyallowsthon ChaCha20 implementation with a 64-bit nonce.
    • Creates Python bindings for the CPP implementation chacha20.cpp using pybind11.

    This will allow us to test both the Python chacha20 and CPP chacha20 against the same test vectors. Hence, increasing the test coverage for chacha20.

    The idea of using Pybind11 was suggested in #19841 (comment). This PR is built on top of the PR draft [#21301](/bitcoin-bitcoin/21301/) using the changes suggested here.

    To test this PR, build Bitcoin Core with(out) the wallet and run:

    $ test/functional/test_runner.py 
    
  2. Add Python ChaCha20 implementation with a 64-bit nonce
    This commit adds an implementation of ChaCha20 (with a 64-bit nonce) in
    Python, and replaces the specialized ChaCha20 implementation in
    `test/functional/test_framework/muhash.py`.
    
    Update chacha20 python implementation
    
    updated `keystream` function for better code readability
    343f980b6c
  3. Add python tests, cpp test and Makefile
    Adds a CSV file with the ChaCha20 test vectors from
    `src/test/crypto_tests.cpp`, and tests the python implementation against
    those vectors.
    
    Adds pybind11 bindings for the `src/crypto/chacha20.h`
    implementation and tests this wrapped implementation against the test
    vectors defined in the CSV.
    
    These tests requires a build step and this commit adds a Makefile for
    performing this step. The Makefile currently only works with macOS. On
    Linux, `-underfined dynamic lookup` should be replaced with `-fPIC`.
    f451cdafeb
  4. siv2r commented at 5:22 AM on September 1, 2021: none

    To Do

    • Separate chacha20 tests (needs pybind11 bindings to be enabled) and chacha20 python implementation.
    • Integrate Makefile into the build process
    • Update necessary docs
  5. siv2r renamed this:
    [WIP] Add Python ChaCha20 implementation and bindings for CPP ChaCha20 implementation
    [WIP] Add Python ChaCha20 and bindings for CPP ChaCha20
    on Sep 1, 2021
  6. DrahtBot commented at 7:07 AM on September 1, 2021: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24005 (test: add python implementation of Elligator squared by stratospher)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  7. DrahtBot added the label Build system on Sep 1, 2021
  8. laanwj commented at 2:54 PM on November 8, 2021: member

    I think it would make sense to split this into a pure-python part, and a part that requires C++ compilation/binding. The first part is more straightforward to review, the latter needs scrutiny from a build-system and cross-platform angle, complicating it.

  9. laanwj added the label Tests on Nov 8, 2021
  10. laanwj commented at 8:01 AM on April 14, 2022: member

    I'm closing this for now as it's been inactive for a long time. If you want to start work again, let me know and I'll reopen it.

  11. laanwj closed this on Apr 14, 2022

  12. DrahtBot locked this on Apr 14, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-01 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me