Skip to content

Commit 8a01c6d

Browse files
committed
Addressed review comments
1 parent 95c91af commit 8a01c6d

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/sign-verify/clu_sign.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ int wolfCLU_sign_data_rsa(byte* data, char* out, word32 dataSz, char* privKey,
280280
ret = BAD_FUNC_ARG;
281281
}
282282
else {
283-
XFWRITE(outBuf, 1, outBufSz, s);
283+
if ((int)XFWRITE(outBuf, 1, outBufSz, s) <= 0) {
284+
ret = OUTPUT_FILE_ERROR;
285+
}
284286
XFCLOSE(s);
285287
}
286288
}
@@ -455,7 +457,9 @@ int wolfCLU_sign_data_ecc(byte* data, char* out, word32 fSz, char* privKey,
455457
ret = BAD_FUNC_ARG;
456458
}
457459
else {
458-
XFWRITE(outBuf, 1, outLen, s);
460+
if ((int)XFWRITE(outBuf, 1, outLen, s) <= 0) {
461+
ret = OUTPUT_FILE_ERROR;
462+
}
459463
XFCLOSE(s);
460464
}
461465
}
@@ -618,7 +622,9 @@ int wolfCLU_sign_data_ed25519 (byte* data, char* out, word32 fSz, char* privKey,
618622
ret = BAD_FUNC_ARG;
619623
}
620624
else {
621-
XFWRITE(outBuf, 1, outLen, s);
625+
if ((int)XFWRITE(outBuf, 1, outLen, s) <= 0) {
626+
ret = OUTPUT_FILE_ERROR;
627+
}
622628
XFCLOSE(s);
623629
}
624630
}
@@ -734,7 +740,7 @@ int wolfCLU_sign_data_dilithium (byte* data, char* out, word32 dataSz, char* pri
734740
privBufSz = privFileSz;
735741
if (XFSEEK(privKeyFile, 0, SEEK_SET) != 0 ||
736742
(int)XFREAD(privBuf, 1, privFileSz, privKeyFile) != privFileSz) {
737-
wolfCLU_LogError("Incorrect private key file size: %d", privFileSz);
743+
wolfCLU_LogError("Failed to read private key file.");
738744
ret = WOLFCLU_FATAL_ERROR;
739745
}
740746
}
@@ -788,7 +794,9 @@ int wolfCLU_sign_data_dilithium (byte* data, char* out, word32 dataSz, char* pri
788794
wolfCLU_LogError("Failed to open output file %s", out);
789795
ret = BAD_FUNC_ARG;
790796
} else {
791-
XFWRITE(outBuf, 1, outBufSz, outFile);
797+
if ((int)XFWRITE(outBuf, 1, outBufSz, outFile) <= 0) {
798+
ret = OUTPUT_FILE_ERROR;
799+
}
792800
XFCLOSE(outFile);
793801
}
794802
}

src/sign-verify/clu_verify.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,16 @@ int wolfCLU_verify_signature_rsa(byte* sig, char* out, int sigSz, char* keyPath,
450450

451451
/* write the output to the specified file */
452452
if (ret > 0) {
453+
int writeSz = ret;
453454
XFILE s = XFOPEN(out, "wb");
454455
if (s == NULL) {
455456
wolfCLU_LogError("Unable to open file %s", out);
456457
ret = BAD_FUNC_ARG;
457458
}
458459
else {
459-
XFWRITE(outBuf, 1, ret, s);
460+
if ((int)XFWRITE(outBuf, 1, writeSz, s) <= 0) {
461+
ret = OUTPUT_FILE_ERROR;
462+
}
460463
XFCLOSE(s);
461464
}
462465
}
@@ -814,7 +817,7 @@ int wolfCLU_verify_signature_dilithium(byte* sig, int sigSz, byte* msg,
814817
/* open and read public key */
815818
keyFile = XFOPEN(keyPath, "rb");
816819
if (keyFile == NULL) {
817-
wolfCLU_LogError("Failed to open Private key FILE.");
820+
wolfCLU_LogError("Failed to open public key FILE.");
818821
wc_dilithium_free(key);
819822
#ifdef WOLFSSL_SMALL_STACK
820823
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);

tests/genkey_sign_ver/genkey-sign-ver-test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ def test_sign_corrupted_key_fails(self):
356356
corrupt_key = "mldsakey_corrupt.priv"
357357
bad_sig = "mldsa_bad_corrupt.sig"
358358
self._track(corrupt_key, bad_sig)
359-
with open(corrupt_key, "w") as f:
360-
f.write("INVALID KEY DATA")
359+
with open(corrupt_key, "wb") as f:
360+
f.write(b"INVALID KEY DATA")
361361
r = run_wolfssl("-dilithium", "-sign", "-inkey", corrupt_key,
362362
"-inform", "der", "-in", self.SIGN_FILE,
363363
"-out", bad_sig)

0 commit comments

Comments
 (0)