Deterministic ECDSA Cross Validation (DECV)
The purpose of DECV is to cross validate various different deterministic ECDSA implementations (libsecp256k1, OpenSSL, Trezor). By verifying that each library produces the exact same signatures for a large number of test vectors, we are able to confirm (with a high degree of confidence) that each library is both correct and lacks subliminal channels (also known as kleptograms). To learn more about ECDSA backdoors, see "Wallet Security" by Stephan Verbücheln and "Deterministic Signatures, Subliminal channels and Hardware wallets" by Sergio Demian Lerner.
An ECDSA signature is represented as a pair of values (r, s). All implementations must generate the same r. However, there exists two valid values for s: s and -s mod n (where n is the order of the group). Another Bitcoin-centric decision is to always pick the lower s (see BIP: 62, BIP: 146).
python/decv.py is used to generate test vectors. These test vectors can be saved to a file or can be streamed to any other implementation. The test vectors also contain BIP32 derivations, which enables writing validation code which is as close as feasible to actual Bitcoin wallet code.
- libsecp256k1 and OpenSSL are used via pycoin, a python library.
- trezor is compiled using cmake, with build files copied from Subzero.
The easiest way to run the code is to use Docker, as following. The code should run fine without Docker, as long as the various dependencies are available. It is recommended that you validate your crypto library in an environment identical to your production environment (i.e. it's preferable to validate hardware wallets on the actual hardware since the underlying library might run different code paths on different processors).
$ docker build -t decv . && docker run --rm -it decv # ./python/decv.py --libsecp256k1 generate 10000 | ./python/decv.py --libsecp256k1 verify verified: 10000 signatures # ./python/decv.py --libsecp256k1 generate 10000 | ./python/decv.py --openssl verify verified: 10000 signatures # ./python/decv.py --libsecp256k1 generate 10000 | ./trezor/build/decv verified: 10000 signatures # cat bip32_test_vectors.csv | ./python/decv.py --libsecp256k1 verify verified: 14 signatures # cat bip32_test_vectors.csv | ./python/decv.py --openssl verify verified: 14 signatures # cat bip32_test_vectors.csv | ./trezor/build/decv verified: 14 signatures # exit
Test vector format
The test vectors are emitted using comma separated values (CSV). See following table for the field names and one sample row.
|seed (hex)||chain||ext pub (base58)||ext priv (base58)||hash of message (hex)||signature (DER encoded, low s, hex)|
Cross Validated Implementations
Releated and Future work
If you found DECV interesting or useful, you should check out Project Wycheproof and Cryptofuzz - Differential cryptography fuzzing. Both project, using different methodologies, look for bugs in cryptographic libraries.
At this point, DECV is considered complete and no future work is planned. However, we welcome pull requests which verify additional libraries or which verify existing libraries using different programming language wrappers.