@@ -27368,7 +27368,45 @@ static byte MinHashAlgo(WOLFSSL* ssl)
2736827368 return sha_mac;
2736927369}
2737027370
27371+ /* Check if a given peer hashSigAlgo is supported in our ssl->suites or
27372+ * ssl->ctx->suites.
27373+ *
27374+ * Returns 1 on match.
27375+ * Returns 0 otherwise.
27376+ * */
27377+ static int SupportedHashSigAlgo(WOLFSSL* ssl, const byte * hashSigAlgo)
27378+ {
27379+ const Suites * suites = NULL;
27380+ word32 i = 0;
27381+
27382+ if (ssl == NULL || hashSigAlgo == NULL) {
27383+ return 0;
27384+ }
27385+
27386+ suites = WOLFSSL_SUITES(ssl);
27387+
27388+ if (suites == NULL || suites->hashSigAlgoSz == 0) {
27389+ return 0;
27390+ }
27391+
27392+ for (i = 0; (i+1) < suites->hashSigAlgoSz; i += HELLO_EXT_SIGALGO_SZ) {
27393+ if (XMEMCMP(&suites->hashSigAlgo[i], hashSigAlgo,
27394+ HELLO_EXT_SIGALGO_SZ) == 0) {
27395+ /* Match found. */
27396+ return 1;
27397+ }
27398+ }
27399+
27400+ return 0;
27401+ }
27402+
2737127403int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz)
27404+ {
27405+ return PickHashSigAlgo_ex(ssl, hashSigAlgo, hashSigAlgoSz, 0);
27406+ }
27407+
27408+ int PickHashSigAlgo_ex(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz,
27409+ int matchSuites)
2737227410{
2737327411 word32 i;
2737427412 int ret = WC_NO_ERR_TRACE(MATCH_SUITE_ERROR);
@@ -27409,6 +27447,14 @@ int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz)
2740927447 if (!MatchSigAlgo(ssl, sigAlgo))
2741027448 continue;
2741127449
27450+ if (matchSuites) {
27451+ /* Keep looking if peer algorithm isn't supported in our ssl->suites
27452+ * or ssl->ctx->suites. */
27453+ if (!SupportedHashSigAlgo(ssl, &hashSigAlgo[i])) {
27454+ continue;
27455+ }
27456+ }
27457+
2741227458 #ifdef HAVE_ED25519
2741327459 if (ssl->pkCurveOID == ECC_ED25519_OID) {
2741427460 /* Matched Ed25519 - set chosen and finished. */
@@ -35913,8 +35959,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3591335959 ret = SetCipherSpecs(ssl);
3591435960 if (ret != 0)
3591535961 return ret;
35916- ret = PickHashSigAlgo (ssl, peerSuites->hashSigAlgo,
35917- peerSuites->hashSigAlgoSz);
35962+ ret = PickHashSigAlgo_ex (ssl, peerSuites->hashSigAlgo,
35963+ peerSuites->hashSigAlgoSz, 1 );
3591835964 if (ret != 0)
3591935965 return ret;
3592035966
0 commit comments