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
hex-literal instead of blobby? #642
Comments
I do think that we should improve I am not sure why you have written your own tool. We already can inspect content of
We don't have to dump all vectors into the same file, i.e. you can have a separate file per vectors origin with a comment in Rust files containing a link to it. IIRC in some crates we do exactly that. In hindsight we should've been more rigorous with recording test vector origins.
Crates are not always get gzipped. The most obvious and common examples are repository cloning and crate vendoring. Also I don't think that having a ton of |
...which always grabs gzipped git pack files 😉 But perhaps more importantly, the size of the test vectors uncompressed is still not particularly large. I think these vectors (aside from the blobby Wycheproof test vectors) are relevant examples: https://github.com/RustCrypto/elliptic-curves/tree/master/p256/src/test_vectors These files are on the order of 10-20kB. The Wycheproof blobby files weigh in a bit bigger at ~30kB, but we're mostly talking about files that are <100kB tops.
The main part I really like about this is it makes it possible to directly compare the hex strings in the code versus ones in e.g. RFCs, and also annotate each of those hex strings with code comments about their provenance. I think RustCrypto/stream-ciphers#245 is a good example of this. If we look at RFC8439 Section 2.4.2:
This is easy to compare to the hex strings in the PR: //
// ChaCha20 test vectors from:
// <https://datatracker.ietf.org/doc/html/rfc8439#section-2.4.2>
//
const KEY: [u8; 32] = hex!(
"
000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
"
);
const IV: [u8; 12] = hex!(
"
000000000000004a00000000
"
);
const PLAINTEXT: [u8; 114] = hex!(
"
4c616469657320616e642047656e746c
656d656e206f662074686520636c6173
73206f66202739393a20496620492063
6f756c64206f6666657220796f75206f
6e6c79206f6e652074697020666f7220
746865206675747572652c2073756e73
637265656e20776f756c642062652069
742e
"
); See also these FIPS 186-4 test vectors for ECDSA expressed using https://github.com/RustCrypto/elliptic-curves/blob/master/p256/src/test_vectors/ecdsa.rs |
Regarding the inspectability of
The nice part of using a text/hex format is there's no tool at all required, and it's easy to compare things via just looking at the original test vectors versus the You've mentioned blobby's If you really want to put all test vectors in a binary format, I say this reluctantly but maybe ASN.1 DER would be a better choice. We have a It would also make it easier to have a more flexible, evolvable binary format, with things like optional description strings, or retroactively adding additional fields in a way where the parser can still interpret the old format in a backwards compatible way without requiring an eager transformation of the |
In RustCrypto/stream-ciphers#244 and RustCrypto/stream-ciphers#245 we encountered the problem of the blobby test vectors being opaque. As serendipity would have it two people opened PRs because they thought test vectors were missing.
It appears they were, but it's presently difficult to ascertain that because all of the test vectors are in an opaque binary blob. I ended up having to write a small tool to dump the test vectors as hex so I could compare them to the ones in the RFC.
If the goal of blobby is to reduce the size of the test vectors in a compiled binary, it seems like
hex-literal
accomplishes that by encoding the test vectors as binary at compile time.If the goal is to reduce the size of the crate, I really doubt it's accomplishing much over gzipped hex. But in the process, we also lose comments about the progeny of test vectors, which makes it difficult to answer questions like what ones we have included for each crate (see aforementioned PRs).
I would suggest that each of the crates in
traits
defines a test vector struct, and we populate an array of those usinghex-literal
.Separately I think it'd be great to have a
test-vectors
crate feature for each of the algorithms that would allow such vectors to be used as part of an initialization self-test (which is a common thing for e.g. FIPS).The text was updated successfully, but these errors were encountered: