= Cryptographic test vector
A \b[cryptographic test vector] is a specified collection of algorithm inputs, parameters and expected outputs used to check an implementation. Exact byte encodings are part of the vector: a key displayed in <hexadecimal> represents bytes, not necessarily the displayed characters. A <known-answer test> compares a computed result with the supplied answer. RFC 4231 provides such vectors for several <HMAC> instantiations.<Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512 (RFC 4231)>[Abstract and §4, conformance-test vectors]{ref}
For its Test Case 1, use a key of twenty bytes each equal to hexadecimal `0b`, and the eight ASCII message bytes spelling `Hi There`. <HMAC> with <SHA-256> must produce
`b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7`.
The output has 64 hexadecimal digits, hence 32 bytes. The key has twenty bytes; using the forty ASCII characters obtained by writing `0b` twenty times supplies a different key. Adding a newline to the message supplies different message bytes too.<Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512 (RFC 4231)>[§4.2, Test Case 1]{ref}
A good vector identifies the complete algorithm variant. An unkeyed <SHA-256> digest of that message is not the expected <HMAC> result, and <SHA-512 256> is a different hash operation despite its equal digest length. <HKDF> additionally needs its salt, initial material, context and requested output length; its primary specification supplies all those fields together with the expected extraction and expansion results.<HMAC-based Extract-and-Expand Key Derivation Function (HKDF) by Hugo Krawczyk and Pasi Eronen>[Appendix A, complete HKDF test cases]{ref}
Passing a vector establishes agreement for those inputs. It does not prove <collision resistance>, key secrecy or a <cryptographic protocol>'s security. Nor does one short input exercise every implementation path. Vectors covering long keys, truncation and boundary lengths can reveal mistakes that a single example misses; RFC 4231 includes separate cases for those behaviours.<Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512 (RFC 4231)>[§§4.6–4.8, truncated output and keys longer than a hash block]{ref}
Back to article page