Reports the byte lengths that the HQC specification fixes for a security level: the encapsulation (public) key, the decapsulation (secret) key, the ciphertext, the key-generation seed, the encapsulation randomness and the shared secret. Use it to validate stored keys and ciphertexts, or to size storage, without hard-coding numbers.
Usage
hqcsz(lvl, ver = c("v5", "round4"))Arguments
- lvl
Security level: 1, 3 or 5 (or 128, 192, 256 for the same three). There is no default.
- ver
"v5"(the default) or"round4", as inhqckg().
Value
A named integer vector of byte lengths: public (the encapsulation
key), secret (the decapsulation key), ciphertext, seed (key
generation), message and salt (encapsulation randomness) and shared
(the shared secret), named as hqckg() and
hqcencap() name their results.
Details
The values come from the compiled implementation, so they are the sizes
it actually uses. For version = "v5" (specification of 2025-08-22):
| HQC-1 | HQC-3 | HQC-5 | |
| encapsulation key | 2241 | 4514 | 7237 |
| decapsulation key | 2321 | 4602 | 7333 |
| ciphertext | 4433 | 8978 | 14421 |
| seed | 32 | 32 | 32 |
| message | 16 | 24 | 32 |
| salt | 16 | 16 | 16 |
| shared secret | 32 | 32 | 32 |
For version = "round4" the codes are the same but the key encoding
differs: the seed is 96, 104 or 112 bytes and the shared secret 64 bytes.
A level other than 1, 3, 5 (or 128, 192, 256) is an error.
Examples
hqcsz(1)
#> public secret ciphertext seed message salt shared
#> 2241 2321 4433 32 16 16 32
# code-based keys and ciphertexts are larger than ML-KEM's at the same
# category; the shared secret is 32 bytes at every level (64 in round 4)
rbind(HQC = hqcsz(3)[c("public", "ciphertext")],
MLKEM = kemsz(768)[c("public", "ciphertext")])
#> public ciphertext
#> HQC 4514 8978
#> MLKEM 1184 1088
rbind(v5 = hqcsz(1), round4 = hqcsz(1, "round4"))
#> public secret ciphertext seed message salt shared
#> v5 2241 2321 4433 32 16 16 32
#> round4 2249 2305 4433 96 16 16 64
# check a stored public key's length
key <- hqckg(1)
nchar(key$public) / 2 == hqcsz(1)[["public"]]
#> [1] TRUE
# an unknown level is refused rather than mapped to a default
try(hqcsz(2))
#> Error : `lvl` must be one of 1, 3 or 5 (HQC-1, HQC-3, HQC-5) or 128, 192, 256
