mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 10:47:28 +02:00
dilithium: support building dilithium with wolfboot.
This commit is contained in:
@ -70,7 +70,7 @@
|
|||||||
* but is slower.
|
* but is slower.
|
||||||
* WOLFSSL_DILITHIUM_SMALL_MEM_POLY64 Default: OFF
|
* WOLFSSL_DILITHIUM_SMALL_MEM_POLY64 Default: OFF
|
||||||
* Compiles the small memory implementations to use a 64-bit polynomial.
|
* Compiles the small memory implementations to use a 64-bit polynomial.
|
||||||
* Uses 2KB of memory but is slighlty quicker (2.75-7%).
|
* Uses 2KB of memory but is slightly quicker (2.75-7%).
|
||||||
*
|
*
|
||||||
* WOLFSSL_DILITHIUM_ALIGNMENT Default: 8
|
* WOLFSSL_DILITHIUM_ALIGNMENT Default: 8
|
||||||
* Use to indicate whether loading and storing of words needs to be aligned.
|
* Use to indicate whether loading and storing of words needs to be aligned.
|
||||||
|
@ -42117,9 +42117,12 @@ static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
|
|||||||
{
|
{
|
||||||
byte msg[512];
|
byte msg[512];
|
||||||
dilithium_key* key;
|
dilithium_key* key;
|
||||||
|
byte * pubExported = NULL;
|
||||||
wc_test_ret_t ret;
|
wc_test_ret_t ret;
|
||||||
int i;
|
int i;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
word32 lenExported = pubKeyLen;
|
||||||
|
int n_diff = 0;
|
||||||
|
|
||||||
key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
|
key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
|
||||||
DYNAMIC_TYPE_TMP_BUFFER);
|
DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
@ -42127,6 +42130,12 @@ static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
|
|||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pubExported = (byte*)XMALLOC(pubKeyLen, HEAP_HINT,
|
||||||
|
DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
if (pubExported == NULL) {
|
||||||
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
|
||||||
|
}
|
||||||
|
|
||||||
/* make dummy msg */
|
/* make dummy msg */
|
||||||
for (i = 0; i < (int)sizeof(msg); i++) {
|
for (i = 0; i < (int)sizeof(msg); i++) {
|
||||||
msg[i] = (byte)i;
|
msg[i] = (byte)i;
|
||||||
@ -42160,9 +42169,27 @@ static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
|
|||||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||||
if (res != 1)
|
if (res != 1)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
|
ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
|
||||||
|
|
||||||
|
/* Now test the export pub raw API, verify we recover the original pub. */
|
||||||
|
ret = wc_dilithium_export_public(key, pubExported, &lenExported);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lenExported <= 0 || lenExported != pubKeyLen) {
|
||||||
|
ERROR_OUT(WC_TEST_RET_ENC_EC(lenExported), out);
|
||||||
|
}
|
||||||
|
|
||||||
|
n_diff = XMEMCMP(pubExported, pubKey, pubKeyLen);
|
||||||
|
|
||||||
|
if (n_diff) {
|
||||||
|
ERROR_OUT(WC_TEST_RET_ENC_EC(n_diff), out);
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
wc_dilithium_free(key);
|
wc_dilithium_free(key);
|
||||||
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
XFREE(pubExported, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -765,6 +765,7 @@ int wc_dilithium_export_public(dilithium_key* key, byte* out, word32* outLen);
|
|||||||
#ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
|
#ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_dilithium_export_private(dilithium_key* key, byte* out, word32* outLen);
|
int wc_dilithium_export_private(dilithium_key* key, byte* out, word32* outLen);
|
||||||
|
#define wc_dilithium_export_private_only wc_dilithium_export_private
|
||||||
#endif
|
#endif
|
||||||
#ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
|
#ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
@ -841,7 +842,7 @@ WOLFSSL_API int wc_Dilithium_PrivateKeyToDer(dilithium_key* key, byte* output,
|
|||||||
#define wc_MlDsaKey_ExportPrivRaw(key, out, outLen) \
|
#define wc_MlDsaKey_ExportPrivRaw(key, out, outLen) \
|
||||||
wc_dilithium_export_private_only(key, out, outLen)
|
wc_dilithium_export_private_only(key, out, outLen)
|
||||||
#define wc_MlDsaKey_ImportPrivRaw(key, in, inLen) \
|
#define wc_MlDsaKey_ImportPrivRaw(key, in, inLen) \
|
||||||
wc_dilithium_import_private_only(out, outLen, key)
|
wc_dilithium_import_private_only(in, inLen, key)
|
||||||
#define wc_MlDsaKey_Sign(key, sig, sigSz, msg, msgSz, rng) \
|
#define wc_MlDsaKey_Sign(key, sig, sigSz, msg, msgSz, rng) \
|
||||||
wc_dilithium_sign_msg(msg, msgSz, sig, sigSz, key, rng)
|
wc_dilithium_sign_msg(msg, msgSz, sig, sigSz, key, rng)
|
||||||
#define wc_MlDsaKey_Free(key) \
|
#define wc_MlDsaKey_Free(key) \
|
||||||
@ -849,7 +850,7 @@ WOLFSSL_API int wc_Dilithium_PrivateKeyToDer(dilithium_key* key, byte* output,
|
|||||||
#define wc_MlDsaKey_ExportPubRaw(key, out, outLen) \
|
#define wc_MlDsaKey_ExportPubRaw(key, out, outLen) \
|
||||||
wc_dilithium_export_public(key, out, outLen)
|
wc_dilithium_export_public(key, out, outLen)
|
||||||
#define wc_MlDsaKey_ImportPubRaw(key, in, inLen) \
|
#define wc_MlDsaKey_ImportPubRaw(key, in, inLen) \
|
||||||
wc_dilithium_import_public(out, outLen, key)
|
wc_dilithium_import_public(in, inLen, key)
|
||||||
#define wc_MlDsaKey_Verify(key, sig, sigSz, msg, msgSz, res) \
|
#define wc_MlDsaKey_Verify(key, sig, sigSz, msg, msgSz, res) \
|
||||||
wc_dilithium_verify_msg(sig, sigSz, msg, msgSz, res, key)
|
wc_dilithium_verify_msg(sig, sigSz, msg, msgSz, res, key)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user