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

Wycheproof tests vectors #1106

Open
real-or-random opened this issue May 11, 2022 · 3 comments
Open

Wycheproof tests vectors #1106

real-or-random opened this issue May 11, 2022 · 3 comments

Comments

@real-or-random
Copy link
Contributor

Though we have good tests, the Wycheproof test vectors will be a good addition.

  • The ECDSA test vectors are probably most interesting but some test vectors are incompatible with Bitcoin (see Distinguish ECDSA malleability? C2SP/wycheproof#70). We asked for other vectors there but they don't respond currently. But even if we disable the incompatible vectors (after careful checking), the other vectors will be a good addition
  • Not sure if we can ECDH to work but I expect it will work at least with a custom derivation function
  • SHA256 and HMAC should not be an issue

The test cases are in a simple JSON format: https://github.com/google/wycheproof/tree/master/testvectors We could either parse them (e.g., https://github.com/zserge/jsmn is very thin, MIT single-header parser that we ), or have a small script (in whatever language) that converts the vectors to C code.

@Sajjon
Copy link

Sajjon commented Mar 20, 2023

@real-or-random Any progress on this? I've written a Swift wrapper called K1 around this wonderful library, and I've implemented unit test for every secp256k1 test vector known to man. Here is the folder with all unit tests and here are all test vectors I use

I've also done the necessary filtering out test vector which are incompatible with this library.

In K1 I support three ECDH variants, what this library does by default (SHA256 of compressed shared public point), and also ASN1 X9.63 version (returning only X component of shared public point, unhashed) and also a custom one which returns the whole point unhashed, I've implemented test for the first two, by having generated a couple of hundreds of tests using Python wrappers around this library and some other secp256k1 Python libraries (based on Open SSL secp25k1 I think), which vendors ASN1 X9.63 ECDH function. See the repo with the code to generated these ECDH test vectors here

This is such an important library since so many libraries build on top of it. I would love for this library to vendors thousands of test vectors for:

  • Public Key derivation
  • Public Key serialization
  • Public Key deserialziation
  • ECDH
  • ECDSA recoverable
  • ECDSA non-recoverable
  • Schnorr

I would be happy to contribute, but my C skills is not the greatest... how would one parse JSON i C? But I could probably easilty contribute once some first tests parsing JSON is up! :)

@real-or-random
Copy link
Contributor Author

@Sajjon That sounds very interesting.

Parsing JSON is indeed a pain point, but since it's really only for tests, and test vectors rarely change, we can really do whatever is most convenient. For example, we could just have a Python script that parses the JSON and outputs C data structures and literals... This was recently done in the fork secp256k1-zkp for MuSig2 test vectors (see https://github.com/BlockstreamResearch/secp256k1-zkp/blob/master/contrib/musig2-vectors.py). Not exactly elegant, but it does the job. We could do the same here. What do you think?

Please let us know if you run into any issues / API inconveniences with your Swift wrapper.

By the way, I'm currently out of office, so I won't reply quickly.

RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Mar 22, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are pulled from the Wycheproof repo using a python script to
emit C code. The script is embedded as a comment.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Mar 22, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are pulled from the Wycheproof repo using a python script to
emit C code. The script is embedded as a comment.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
@andozw
Copy link
Contributor

andozw commented Mar 22, 2023

We opened a PR that adds coverage for ECDSA Wycheproof test vectors at #1245 . We wrote a small Python script that parses the JSON and outputs C data structure, and embedded it in the source file (much like it is done elsewhere). All the tests for ECDSA pass from the latest drop of Wycheproof (released about 3 weeks ago).

RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Mar 22, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are pulled from the Wycheproof repo using a python script to
emit C code. The script is embedded as a comment.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Mar 22, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Mar 23, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Mar 25, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Mar 25, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Apr 7, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Apr 8, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Apr 8, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Apr 8, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Apr 9, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
RandomLattice added a commit to RandomLattice/secp256k1 that referenced this issue Apr 9, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
sipa added a commit that referenced this issue Apr 10, 2023
e5de454 tests: Add Wycheproof ECDSA vectors (RandomLattice)

Pull request description:

  This PR adds a test using the Wycheproof vectors as outlined in #1106. We add all 463 ECDSA test vectors. These vectors cover:
  - edge cases in arithmetic operations
  - signatures with special values for (r,s) that should be rejected
  - special cases of public keys

  The vectors are pulled from the Wycheproof project using a python script to emit C code.

  All the new ECDSA Wycheproof vectors pass.

ACKs for top commit:
  sipa:
    ACK e5de454
  real-or-random:
    ACK e5de454

Tree-SHA512: e9684f14ff3f5225a4a4949b490e07527d559c28aa61ed03c03bc52ea64785f0b80b9e1b1628665eacf24006526271ea0fb108629c9c3c1d758e52d214a056f1
dderjoel pushed a commit to dderjoel/secp256k1 that referenced this issue May 23, 2023
Adds a test using the Wycheproof vectors as outlined in bitcoin-core#1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
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

No branches or pull requests

3 participants