@@ -1039,7 +1039,7 @@ int wolfCLU_genKey_RSA(WC_RNG* rng, char* fName, int directive, int fmt, int
10391039int wolfCLU_genKey_Dilithium (WC_RNG * rng , char * fName , int directive , int fmt ,
10401040 int keySz , int level , int withAlg )
10411041{
1042- #ifdef HAVE_DILITHIUM
1042+ #ifdef HAVE_DILITHIUM
10431043 int ret = WOLFCLU_SUCCESS ;
10441044
10451045 XFILE file = NULL ;
@@ -1076,11 +1076,11 @@ int wolfCLU_genKey_Dilithium(WC_RNG* rng, char* fName, int directive, int fmt,
10761076
10771077 /* init the dilithium key */
10781078 if (wc_dilithium_init (key ) != 0 ) {
1079- wolfCLU_LogError ("Failed to initialize Dilithium Key.\nRET: %d" , ret );
1079+ wolfCLU_LogError ("Failed to initialize Dilithium Key." );
10801080 #ifdef WOLFSSL_SMALL_STACK
10811081 XFREE (key , HEAP_HINT , DYNAMIC_TYPE_DILITHIUM );
10821082 #endif
1083- return ret ;
1083+ return WOLFCLU_FATAL_ERROR ;
10841084 }
10851085
10861086 /* set the level of the dilithium key */
@@ -1113,12 +1113,6 @@ int wolfCLU_genKey_Dilithium(WC_RNG* rng, char* fName, int directive, int fmt,
11131113 if (ret == WOLFCLU_SUCCESS ) {
11141114 XMEMSET (fOutNameBuf , 0 , fNameSz + fExtSz );
11151115 XMEMCPY (fOutNameBuf , fName , fNameSz );
1116-
1117- derBuf = (byte * )XMALLOC (keySz , HEAP_HINT ,
1118- DYNAMIC_TYPE_TMP_BUFFER );
1119- if (derBuf == NULL ) {
1120- ret = MEMORY_E ;
1121- }
11221116 }
11231117
11241118 if (ret == WOLFCLU_SUCCESS ) {
@@ -1129,6 +1123,13 @@ int wolfCLU_genKey_Dilithium(WC_RNG* rng, char* fName, int directive, int fmt,
11291123 case PRIV_ONLY_FILE :
11301124 /* add on the final part of the file name ".priv" */
11311125 XMEMCPY (fOutNameBuf + fNameSz , fExtPriv , fExtSz );
1126+
1127+ derBuf = (byte * )XMALLOC (keySz , HEAP_HINT ,
1128+ DYNAMIC_TYPE_TMP_BUFFER );
1129+ if (derBuf == NULL ) {
1130+ ret = MEMORY_E ;
1131+ break ;
1132+ }
11321133 WOLFCLU_LOG (WOLFCLU_L0 , "Private key file = %s" , fOutNameBuf );
11331134
11341135 /* Private key to der */
@@ -1184,16 +1185,17 @@ int wolfCLU_genKey_Dilithium(WC_RNG* rng, char* fName, int directive, int fmt,
11841185
11851186 FALL_THROUGH ;
11861187 case PUB_ONLY_FILE :
1187- /* add on the final part of the file name ".priv " */
1188+ /* add on the final part of the file name ".pub " */
11881189 XMEMCPY (fOutNameBuf + fNameSz , fExtPub , fExtSz );
11891190 WOLFCLU_LOG (WOLFCLU_L0 , "Public key file = %s" , fOutNameBuf );
11901191
11911192 derBuf = (byte * )XMALLOC (keySz , HEAP_HINT ,
11921193 DYNAMIC_TYPE_TMP_BUFFER );
11931194 if (derBuf == NULL ) {
11941195 ret = MEMORY_E ;
1196+ break ;
11951197 }
1196-
1198+
11971199 derBufSz = wc_Dilithium_PublicKeyToDer (key , derBuf ,
11981200 (word32 )keySz , withAlg );
11991201 if (derBufSz < 0 ) {
0 commit comments