@@ -1314,7 +1314,11 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
13141314#ifndef WOLFSSL_AESGCM_STREAM
13151315 if ((ctx -> authBuffer && ctx -> authBufferLen > 0 )
13161316 || (ctx -> authBufferLen == 0 )) {
1317- if (ctx -> enc )
1317+ if (ctx -> authBufferLen > 0 && out == NULL ) {
1318+ ret = WOLFSSL_FAILURE ;
1319+ * outl = 0 ;
1320+ }
1321+ else if (ctx -> enc )
13181322 ret = wc_AesGcmEncrypt (& ctx -> cipher .aes , out ,
13191323 ctx -> authBuffer , ctx -> authBufferLen ,
13201324 ctx -> iv , ctx -> ivSz , ctx -> authTag , ctx -> authTagSz ,
@@ -1397,7 +1401,11 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
13971401 case WC_AES_256_CCM_TYPE :
13981402 if ((ctx -> authBuffer && ctx -> authBufferLen > 0 )
13991403 || (ctx -> authBufferLen == 0 )) {
1400- if (ctx -> enc ) {
1404+ if (ctx -> authBufferLen > 0 && out == NULL ) {
1405+ ret = WOLFSSL_FAILURE ;
1406+ * outl = 0 ;
1407+ }
1408+ else if (ctx -> enc ) {
14011409 ret = wc_AesCcmEncrypt (& ctx -> cipher .aes , out ,
14021410 ctx -> authBuffer , (word32 )ctx -> authBufferLen ,
14031411 ctx -> iv , (word32 )ctx -> ivSz , ctx -> authTag ,
@@ -4309,16 +4317,16 @@ int wolfSSL_EVP_SignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sigret,
43094317#ifndef NO_DSA
43104318 case WC_EVP_PKEY_DSA : {
43114319 int bytes ;
4312- ret = wolfSSL_DSA_do_sign (md , sigret , pkey -> dsa );
4313- /* wolfSSL_DSA_do_sign() can return WOLFSSL_FATAL_ERROR */
4314- if (ret != WOLFSSL_SUCCESS )
4315- return ret ;
43164320 bytes = wolfSSL_BN_num_bytes (pkey -> dsa -> q );
43174321 if (bytes == WC_NO_ERR_TRACE (WOLFSSL_FAILURE ) ||
4318- ( int ) * siglen < bytes * 2 )
4322+ bytes * 2 > ( int ) * siglen )
43194323 {
43204324 return WOLFSSL_FAILURE ;
43214325 }
4326+ ret = wolfSSL_DSA_do_sign (md , sigret , pkey -> dsa );
4327+ /* wolfSSL_DSA_do_sign() can return WOLFSSL_FATAL_ERROR */
4328+ if (ret != WOLFSSL_SUCCESS )
4329+ return ret ;
43224330 * siglen = (unsigned int )(bytes * 2 );
43234331 return WOLFSSL_SUCCESS ;
43244332 }
@@ -4398,7 +4406,8 @@ int wolfSSL_EVP_VerifyFinal(WOLFSSL_EVP_MD_CTX *ctx,
43984406 unsigned char md [WC_MAX_DIGEST_SIZE ];
43994407 unsigned int mdsize ;
44004408
4401- if (ctx == NULL ) return WOLFSSL_FAILURE ;
4409+ if (ctx == NULL || pkey == NULL || sig == NULL )
4410+ return WOLFSSL_FAILURE ;
44024411 WOLFSSL_ENTER ("EVP_VerifyFinal" );
44034412 ret = wolfSSL_EVP_DigestFinal (ctx , md , & mdsize );
44044413 if (ret <= 0 )
@@ -4459,6 +4468,9 @@ WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_mac_key(int type, WOLFSSL_ENGINE* e,
44594468 if (type != WC_EVP_PKEY_HMAC || (key == NULL && keylen != 0 ))
44604469 return NULL ;
44614470
4471+ if (keylen < 0 )
4472+ return NULL ;
4473+
44624474 pkey = wolfSSL_EVP_PKEY_new ();
44634475 if (pkey != NULL ) {
44644476 pkey -> pkey .ptr = (char * )XMALLOC ((size_t )keylen , NULL ,
@@ -4870,6 +4882,9 @@ int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sig,
48704882 return WOLFSSL_SUCCESS ;
48714883 }
48724884 }
4885+ else if (ctx -> pctx == NULL || ctx -> pctx -> pkey == NULL ) {
4886+ return WOLFSSL_FAILURE ;
4887+ }
48734888#ifndef NO_RSA
48744889 else if (ctx -> pctx -> pkey -> type == WC_EVP_PKEY_RSA ) {
48754890 if (sig == NULL ) {
@@ -5006,6 +5021,8 @@ int wolfSSL_EVP_DigestVerifyFinal(WOLFSSL_EVP_MD_CTX *ctx,
50065021 return WOLFSSL_FAILURE ;
50075022 }
50085023 else {
5024+ if (ctx -> pctx == NULL || ctx -> pctx -> pkey == NULL )
5025+ return WOLFSSL_FAILURE ;
50095026 /* Verify the signature with the digest. */
50105027 switch (ctx -> pctx -> pkey -> type ) {
50115028 #if !defined(NO_RSA )
@@ -10232,6 +10249,9 @@ int wolfSSL_EVP_Digest(const unsigned char* in, int inSz, unsigned char* out,
1023210249 return WOLFSSL_FAILURE ;
1023310250 }
1023410251
10252+ if (inSz < 0 )
10253+ return WOLFSSL_FAILURE ;
10254+
1023510255 err = wolfSSL_EVP_get_hashinfo (evp , & hashType , & hashSz );
1023610256 if (err != WOLFSSL_SUCCESS )
1023710257 return err ;
@@ -11279,6 +11299,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
1127911299 enum wc_HashType macType ;
1128011300
1128111301 WOLFSSL_ENTER ("wolfSSL_EVP_DigestFinal" );
11302+
1128211303 macType = EvpMd2MacType (wolfSSL_EVP_MD_CTX_md (ctx ));
1128311304 switch (macType ) {
1128411305 case WC_HASH_TYPE_MD4 :
@@ -11304,16 +11325,18 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
1130411325
1130511326 case WC_HASH_TYPE_SHAKE128 :
1130611327 #if defined(WOLFSSL_SHA3 ) && defined(WOLFSSL_SHAKE128 )
11307- * s = 16 ; /* if mixing up XOF with plain digest 128 bit is
11308- * default for SHAKE128 */
11328+ if (s != NULL )
11329+ * s = 16 ; /* if mixing up XOF with plain digest 128 bit is
11330+ * default for SHAKE128 */
1130911331 #else
1131011332 return WOLFSSL_FAILURE ;
1131111333 #endif
1131211334 break ;
1131311335 case WC_HASH_TYPE_SHAKE256 :
1131411336 #if defined(WOLFSSL_SHA3 ) && defined(WOLFSSL_SHAKE256 )
11315- * s = 32 ; /* if mixing up XOF with plain digest 256 bit is
11316- * default for SHAKE256 */
11337+ if (s != NULL )
11338+ * s = 32 ; /* if mixing up XOF with plain digest 256 bit is
11339+ * default for SHAKE256 */
1131711340 #else
1131811341 return WOLFSSL_FAILURE ;
1131911342 #endif
@@ -12881,6 +12904,9 @@ int wolfSSL_EVP_EncodeBlock(unsigned char *out, const unsigned char *in,
1288112904 if (out == NULL || in == NULL )
1288212905 return WOLFSSL_FATAL_ERROR ;
1288312906
12907+ if (inLen < 0 )
12908+ return WOLFSSL_FATAL_ERROR ;
12909+
1288412910 if (Base64_Encode_NoNl (in , (word32 )inLen , out , & ret ) == 0 )
1288512911 return (int )ret ;
1288612912 else
@@ -12897,6 +12923,9 @@ int wolfSSL_EVP_DecodeBlock(unsigned char *out, const unsigned char *in,
1289712923 if (out == NULL || in == NULL )
1289812924 return WOLFSSL_FATAL_ERROR ;
1289912925
12926+ if (inLen < 0 )
12927+ return WOLFSSL_FATAL_ERROR ;
12928+
1290012929 if (Base64_Decode (in , (word32 )inLen , out , & ret ) == 0 )
1290112930 return (int )ret ;
1290212931 else
0 commit comments