Kyber: fix TLS usage

Allow only select parameter sets to be compiled in.
Fixed unit.test to recognize when level is supported.
This commit is contained in:
Sean Parkinson
2024-08-27 10:35:08 +10:00
parent bf074d2bb9
commit 893a486ae1
5 changed files with 127 additions and 16 deletions

View File

@@ -710,24 +710,45 @@ static void SetKeyShare(WOLFSSL* ssl, int onlyKeyShare, int useX25519,
else if (usePqc == 1) {
#ifdef HAVE_PQC
groups[count] = 0;
#ifndef WOLFSSL_NO_KYBER512
if (XSTRCMP(pqcAlg, "KYBER_LEVEL1") == 0) {
groups[count] = WOLFSSL_KYBER_LEVEL1;
}
else if (XSTRCMP(pqcAlg, "KYBER_LEVEL3") == 0) {
else
#endif
#ifndef WOLFSSL_NO_KYBER768
if (XSTRCMP(pqcAlg, "KYBER_LEVEL3") == 0) {
groups[count] = WOLFSSL_KYBER_LEVEL3;
}
else if (XSTRCMP(pqcAlg, "KYBER_LEVEL5") == 0) {
else
#endif
#ifndef WOLFSSL_NO_KYBER1024
if (XSTRCMP(pqcAlg, "KYBER_LEVEL5") == 0) {
groups[count] = WOLFSSL_KYBER_LEVEL5;
}
else if (XSTRCMP(pqcAlg, "P256_KYBER_LEVEL1") == 0) {
else
#endif
#ifndef WOLFSSL_NO_KYBER512
if (XSTRCMP(pqcAlg, "P256_KYBER_LEVEL1") == 0) {
groups[count] = WOLFSSL_P256_KYBER_LEVEL1;
}
else if (XSTRCMP(pqcAlg, "P384_KYBER_LEVEL3") == 0) {
else
#endif
#ifndef WOLFSSL_NO_KYBER768
if (XSTRCMP(pqcAlg, "P384_KYBER_LEVEL3") == 0) {
groups[count] = WOLFSSL_P384_KYBER_LEVEL3;
}
else if (XSTRCMP(pqcAlg, "P521_KYBER_LEVEL5") == 0) {
else
#endif
#ifndef WOLFSSL_NO_KYBER1024
if (XSTRCMP(pqcAlg, "P521_KYBER_LEVEL5") == 0) {
groups[count] = WOLFSSL_P521_KYBER_LEVEL5;
}
else
#endif
{
err_sys("invalid post-quantum KEM specified");
}
if (groups[count] == 0) {
err_sys("invalid post-quantum KEM specified");