Merge pull request #7682 from SparkiDev/dilithium_fix_1

Dilithium: fix public and private key decode
This commit is contained in:
Daniel Pouzzner
2024-06-26 00:03:03 -04:00
committed by GitHub

View File

@@ -7126,8 +7126,7 @@ int wc_Dilithium_PrivateKeyDecode(const byte* input, word32* inOutIdx,
ret = DecodeAsymKey_Assign(input, inOutIdx, inSz, &privKey, &privKeyLen, ret = DecodeAsymKey_Assign(input, inOutIdx, inSz, &privKey, &privKeyLen,
&pubKey, &pubKeyLen, keytype); &pubKey, &pubKeyLen, keytype);
} }
if ((ret == 0) && (pubKey == NULL) && (pubKeyLen == 0)) {
if ((pubKey == NULL) && (pubKeyLen == 0)) {
/* Check if the public key is included in the private key. */ /* Check if the public key is included in the private key. */
if ((key->level == 2) && if ((key->level == 2) &&
(privKeyLen == DILITHIUM_LEVEL2_PRV_KEY_SIZE)) { (privKeyLen == DILITHIUM_LEVEL2_PRV_KEY_SIZE)) {
@@ -7197,16 +7196,10 @@ int wc_Dilithium_PublicKeyDecode(const byte* input, word32* inOutIdx,
if (ret == 0) { if (ret == 0) {
/* Try to import the key directly. */ /* Try to import the key directly. */
ret = wc_dilithium_import_public(input, inSz, key); ret = wc_dilithium_import_public(input, inSz, key);
} if (ret != 0) {
if (ret == 0) { /* Start again. */
return 0;
}
else {
/* Not successful, decode it first. */
ret = 0; ret = 0;
}
if (ret == 0) {
/* Get OID sum for level. */ /* Get OID sum for level. */
if (key->level == 2) { if (key->level == 2) {
keytype = DILITHIUM_LEVEL2k; keytype = DILITHIUM_LEVEL2k;
@@ -7221,7 +7214,6 @@ int wc_Dilithium_PublicKeyDecode(const byte* input, word32* inOutIdx,
/* Level not set. */ /* Level not set. */
ret = BAD_FUNC_ARG; ret = BAD_FUNC_ARG;
} }
}
if (ret == 0) { if (ret == 0) {
/* Decode the asymmetric key and get out public key data. */ /* Decode the asymmetric key and get out public key data. */
ret = DecodeAsymKeyPublic_Assign(input, inOutIdx, inSz, &pubKey, ret = DecodeAsymKeyPublic_Assign(input, inOutIdx, inSz, &pubKey,
@@ -7231,6 +7223,8 @@ int wc_Dilithium_PublicKeyDecode(const byte* input, word32* inOutIdx,
/* Import public key data. */ /* Import public key data. */
ret = wc_dilithium_import_public(pubKey, pubKeyLen, key); ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
} }
}
}
return ret; return ret;
} }