Expand test coverage: compile-fail invariants and nonce derivation correctness - #6
Conversation
Lock in three type-system invariants: Context is not Clone, ExportOnly cannot be used with seal_base, and PQ KEMs cannot be used with seal_auth.
|
@danieldia-dev Thanks for this great PR. Some fixes are required before merging:
|
|
Understood, I will implement the above fixes, as required. Thanks for the review! |
|
@danieldia-dev The README's |
This PR makes two small independent improvements:
Three
trybuildcompile-fail tests are added to lock in type-system invariants that were previously untested:Contextis notClone,ExportOnlycannot be used withseal_base, and PQ KEMs cannot be used withseal_auth. A regression in any of these previously would have silently widened the API.A
nonce_derivation_xors_seq_into_base_noncetest is added tocontext.rsthat directly verifies the XOR formula from RFC 9180 §5.2 (i.e.nonce = base_nonce XOR I2OSP(seq, Nn)whereI2OSPis "Integer to Octet String Primitive") across four specific sequence number values:0,1,256, and0x0102_0304_0506_0708. This tests the correctness of the individual nonce derivation computation, as opposed to running a large number of operations and checking for uniqueness.All compile-fail tests pass under
cargo test --features pq --test compile_fail.The
READMEtesting section is updated to document the newcargo test --features pq --test compile_failcommand and to mention the compile-fail invariant tests and nonce derivation unit test in the coverage summary.Note that the value
0x0102_0304_0506_0708was chosen as a test vector because every byte is distinct and non-zero, which means that a bug in byte indexing or byte ordering (e.g. writing a byte to the wrong position or reversing the endianness) would produce a visibly wrong result rather than accidentally passing.