Support committed generated test data and generate PQCP test data #278
No reviewers
Labels
No labels
approved
bug
dependencies
DO-NOT-MERGE
enhancement
good-first-issue
help-wanted
historical-reviewed
historical-reviewing
needs-adoption
needs-ci
needs-design-approval
needs-info
needs-preceding-pr
needs-review
needs-reviewer
needs-work
priority-high
priority-low
priority-medium
priority-scheduled
priority-very-high
single-reviewer
size-l
size-m
size-s
size-xs
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Mbed-TLS/mbedtls-framework!278
Loading…
Reference in a new issue
No description provided.
Delete branch "generate_mldsa_tests-create"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
framework/util, according to the design proposed in https://github.com/Mbed-TLS/mbedtls-framework/pull/272.Framework part of https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/690.
PR checklist
Please add the numbers (or links) of the associated pull requests for consuming branches. You can omit branches where this pull request is not needed.
Not had time to do a full review, however added a couple of initial comments/questions.
Is there a byte/bit mismatch here as all entries in the array appear to be in bytes not bits, so should the SM3 entry be 32 not 256?
Is there a bits/bytes mistmatch here most of the entries in the table appear to be bytes. ie. MD5 16 etc. However SM3 is 256, however if I've understood correctly this is the bitlen and this value should the byte length ie 32?
@ -0,0 +1,5 @@# Python module requirements for maintainer utilitiesDoes this file need a SPDX copywrite notice?
@ -0,0 +1,5 @@# Python module requirements for maintainer utilitiesIdeally yes, but there are no notices in the other
requirements.txtfiles, and we routinely create new files that don't have notices (e.g.tests/suites/*.dataandtests/suites/*.function), so this is fine.Handled in https://github.com/Mbed-TLS/mbedtls-framework/pull/265.
Since #265 has been merged, you might rebase this PR so that we can get it merged and unlock https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/690 as well ;)
Oh, I hadn't rebased because there was no conflict, but now there is one! Ronald and I simultaneously created a file with the same name... I'll rework this then.
I've rebased on top of the merge of https://github.com/Mbed-TLS/mbedtls-framework/pull/265. I also renamed
scripts/mbedtls_framework/generated_files.pytoscripts/mbedtls_framework/generate_files_helper.pyto disambiguate it from thescripts/mbedtls_framework/generated_files.pythat Ronald added in parallel. This is ready for review if the CI agrees.(Taking over from Ben as a reviewer while he's away.)
Looking pretty good to me. Just a minor point that can be ignored, and a question that's probably just me missing something but I'd still like it answered before I formally approve.
@ -0,0 +40,4 @@#pylint: disable=too-few-public-methodsdef __init__(self, kl: int, seed: bytes) -> None:self.kl = kl #pylint: disable=invalid-nameMinor: rather than silencing pylint, we could also call it something more explicit. I'm not sure what
klstands for tbh. I'm assuming 87 means k =8 and l = 7 or something like this?@ -0,0 +144,4 @@def one_mldsa_verify_pure(api: API,key: Key,message: bytes,deterministic: bool,Sorry, this is probably just me lacking contextual knowledge, but how does "deterministic" make sense for the verification?
@ -0,0 +40,4 @@#pylint: disable=too-few-public-methodsdef __init__(self, kl: int, seed: bytes) -> None:self.kl = kl #pylint: disable=invalid-nameIndeed, “87” is a string, not a number, representing the pair of integers (8, 7). Those integers are called (k, l) in mathematical descriptions. We use 87 as a ”key bit-size“ in the PSA API, but with a note that we're repurposing an existing field, and the number is not actually the size of anything.
When describing ML-DSA, (k, l) is usually called the “parameter set”. I found
parameter_setto be a bit long, even for me. Also, to be more precise, it's the designation of the part of the parameter set for which several variants have been made official — the underlying lattice construction has more parameters. I guessk_lwould also meet the rule that we've set for variable names, without being unwieldy or vague.@ -0,0 +40,4 @@#pylint: disable=too-few-public-methodsdef __init__(self, kl: int, seed: bytes) -> None:self.kl = kl #pylint: disable=invalid-nameSwitching to
k_lmakes me think that the data is a pair(k, l), but the variable actually contains the number, because the number is what you need to pass to various APIs. So I thinkklis a better name. I'd rather not make the code less readable for humans just to satisfy a rule whose general intent is to make code more readable, but that doesn't handle this specific case well.@ -0,0 +144,4 @@def one_mldsa_verify_pure(api: API,key: Key,message: bytes,deterministic: bool,It's about the data, not the algorithm. My intent was to have test data be either a valid deterministic signature, or some other valid signature. As I went to write this in the function documentation, I realized that I hadn't implemented the non-deterministic case correctly, so I went and did that.
@ -0,0 +40,4 @@#pylint: disable=too-few-public-methodsdef __init__(self, kl: int, seed: bytes) -> None:self.kl = kl #pylint: disable=invalid-nameOk, let's stick with kl then.
Sure! It's just that with the little context I had, I didn't find
klsuper readable, so I thought the rule was handling this case well. But after discussion,klseems to be the best choice, so let's stick with it.@ -0,0 +144,4 @@def one_mldsa_verify_pure(api: API,key: Key,message: bytes,deterministic: bool,Ok, it's still not clear to me why we want to test verification on both sets of data. Perhaps I have the wrong intuition here (mostly transposed from ECDSA), but it seems to me the verifier can't know whether the signature was generated using the deterministic scheme or not (that would require knowing the private key), so it seems unlikely to me that both sets of data would exercise different paths in the verification code.
I'm not opposed to having both, in fact I'm almost never opposed to having more test data. I'm just trying to understand if there's something about ML-DSA I'm missing that makes this more useful than I feel it is.
LGTM, thanks!
@ -0,0 +144,4 @@def one_mldsa_verify_pure(api: API,key: Key,message: bytes,deterministic: bool,It's not strictly necessary, but hardly anything about test coverage ever is. My thinking is, there are many valid signatures for a given (key, message) pair, so we should test multiple signatures. Of the valid signatures, one has a special distinction (deterministic) and the others are parametrized by a random value, so we should test the special one and one of the non-special ones.
@ -0,0 +144,4 @@def one_mldsa_verify_pure(api: API,key: Key,message: bytes,deterministic: bool,To clarify, from a gray-box perspective, it's impossible to distinguish the deterministic signature from any other valid signature unless you have the private key, so a verification function that only has the public key and accepts the deterministic signature must also accept all the randomized signatures. But from a black-box perspective, I prefer to also test a signature that isn't the deterministic one.