@@ -3312,6 +3312,23 @@ static WC_INLINE void AddSuiteHashSigAlgo(byte* hashSigAlgo, byte macAlgo,
33123312 #endif
33133313 }
33143314 else
3315+ #endif
3316+ #ifdef HAVE_ECC_BRAINPOOL
3317+ if (sigAlgo == ecc_brainpool_sa_algo) {
3318+ if (macAlgo == sha512_mac) {
3319+ ADD_HASH_SIG_ALGO(hashSigAlgo, inOutIdx, NEW_SA_MAJOR,
3320+ ECDSA_BRAINPOOLP512R1TLS13_SHA512_MINOR);
3321+ }
3322+ else if (macAlgo == sha384_mac) {
3323+ ADD_HASH_SIG_ALGO(hashSigAlgo, inOutIdx, NEW_SA_MAJOR,
3324+ ECDSA_BRAINPOOLP384R1TLS13_SHA384_MINOR);
3325+ }
3326+ else if (macAlgo == sha256_mac) {
3327+ ADD_HASH_SIG_ALGO(hashSigAlgo, inOutIdx, NEW_SA_MAJOR,
3328+ ECDSA_BRAINPOOLP256R1TLS13_SHA256_MINOR);
3329+ }
3330+ }
3331+ else
33153332#endif
33163333 {
33173334 ADD_HASH_SIG_ALGO(hashSigAlgo, inOutIdx, macAlgo, sigAlgo);
@@ -3320,11 +3337,12 @@ static WC_INLINE void AddSuiteHashSigAlgo(byte* hashSigAlgo, byte macAlgo,
33203337}
33213338
33223339void InitSuitesHashSigAlgo(byte* hashSigAlgo, int haveSig, int tls1_2,
3323- int keySz, word16* len)
3340+ int tls1_3, int keySz, word16* len)
33243341{
33253342 word16 idx = 0;
33263343
33273344 (void)tls1_2;
3345+ (void)tls1_3;
33283346 (void)keySz;
33293347
33303348#if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
@@ -3333,14 +3351,32 @@ void InitSuitesHashSigAlgo(byte* hashSigAlgo, int haveSig, int tls1_2,
33333351 #ifdef WOLFSSL_SHA512
33343352 AddSuiteHashSigAlgo(hashSigAlgo, sha512_mac, ecc_dsa_sa_algo, keySz,
33353353 &idx);
3354+ #ifdef HAVE_ECC_BRAINPOOL
3355+ if (tls1_3) {
3356+ AddSuiteHashSigAlgo(hashSigAlgo, sha512_mac, ecc_brainpool_sa_algo,
3357+ keySz, &idx);
3358+ }
3359+ #endif
33363360 #endif
33373361 #ifdef WOLFSSL_SHA384
33383362 AddSuiteHashSigAlgo(hashSigAlgo, sha384_mac, ecc_dsa_sa_algo, keySz,
33393363 &idx);
3364+ #ifdef HAVE_ECC_BRAINPOOL
3365+ if (tls1_3) {
3366+ AddSuiteHashSigAlgo(hashSigAlgo, sha384_mac, ecc_brainpool_sa_algo,
3367+ keySz, &idx);
3368+ }
3369+ #endif
33403370 #endif
33413371 #ifndef NO_SHA256
33423372 AddSuiteHashSigAlgo(hashSigAlgo, sha256_mac, ecc_dsa_sa_algo, keySz,
33433373 &idx);
3374+ #ifdef HAVE_ECC_BRAINPOOL
3375+ if (tls1_3) {
3376+ AddSuiteHashSigAlgo(hashSigAlgo, sha256_mac, ecc_brainpool_sa_algo,
3377+ keySz, &idx);
3378+ }
3379+ #endif
33443380 #endif
33453381 #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
33463382 defined(WOLFSSL_ALLOW_TLS_SHA1))
@@ -3465,9 +3501,7 @@ void InitSuites(Suites* suites, ProtocolVersion pv, int keySz, word16 haveRSA,
34653501 word16 idx = 0;
34663502 int tls = pv.major == SSLv3_MAJOR && pv.minor >= TLSv1_MINOR;
34673503 int tls1_2 = pv.major == SSLv3_MAJOR && pv.minor >= TLSv1_2_MINOR;
3468- #ifdef WOLFSSL_TLS13
34693504 int tls1_3 = IsAtLeastTLSv1_3(pv);
3470- #endif
34713505 int dtls = 0;
34723506 int haveRSAsig = 1;
34733507
@@ -3484,6 +3518,7 @@ void InitSuites(Suites* suites, ProtocolVersion pv, int keySz, word16 haveRSA,
34843518
34853519 (void)tls; /* shut up compiler */
34863520 (void)tls1_2;
3521+ (void)tls1_3;
34873522 (void)dtls;
34883523 (void)haveDH;
34893524 (void)havePSK;
@@ -4511,8 +4546,8 @@ void InitSuites(Suites* suites, ProtocolVersion pv, int keySz, word16 haveRSA,
45114546 suites->suiteSz = idx;
45124547
45134548 if (suites->hashSigAlgoSz == 0) {
4514- InitSuitesHashSigAlgo(suites->hashSigAlgo, SIG_ALL, tls1_2, keySz ,
4515- &suites->hashSigAlgoSz);
4549+ InitSuitesHashSigAlgo(suites->hashSigAlgo, SIG_ALL, tls1_2, tls1_3 ,
4550+ keySz, &suites->hashSigAlgoSz);
45164551 }
45174552
45184553 /* Moved to the end as we set some of the vars but never use them */
@@ -4571,6 +4606,22 @@ void DecodeSigAlg(const byte* input, byte* hashAlgo, byte* hsType)
45714606 *hashAlgo = PSS_PSS_HASH_TO_MAC(input[1]);
45724607 }
45734608 else
4609+ #endif
4610+ #ifdef HAVE_ECC_BRAINPOOL
4611+ /* RFC 8734 TLS 1.3 Brainpool curves */
4612+ if (input[1] == ECDSA_BRAINPOOLP256R1TLS13_SHA256_MINOR) {
4613+ *hsType = ecc_brainpool_sa_algo;
4614+ *hashAlgo = sha256_mac;
4615+ }
4616+ else if (input[1] == ECDSA_BRAINPOOLP384R1TLS13_SHA384_MINOR) {
4617+ *hsType = ecc_brainpool_sa_algo;
4618+ *hashAlgo = sha384_mac;
4619+ }
4620+ else if (input[1] == ECDSA_BRAINPOOLP512R1TLS13_SHA512_MINOR) {
4621+ *hsType = ecc_brainpool_sa_algo;
4622+ *hashAlgo = sha512_mac;
4623+ }
4624+ else
45744625 #endif
45754626 {
45764627 *hsType = input[0];
@@ -28273,6 +28324,7 @@ static int ParseCipherList(Suites* suites,
2827328324 word16 haveSHA1 = 1; /* allowed by default if compiled in */
2827428325 word16 haveRC4 = 1; /* allowed by default if compiled in */
2827528326#endif
28327+ int tls1_3 = 0;
2827628328 const int suiteSz = GetCipherNamesSize();
2827728329 const char* next = list;
2827828330
@@ -28598,6 +28650,7 @@ static int ParseCipherList(Suites* suites,
2859828650 (cipher_names[i].cipherSuite0 == ECC_BYTE &&
2859928651 (cipher_names[i].cipherSuite == TLS_SHA256_SHA256 ||
2860028652 cipher_names[i].cipherSuite == TLS_SHA384_SHA384))) {
28653+ tls1_3 = 1;
2860128654 #ifndef NO_RSA
2860228655 haveSig |= SIG_RSA;
2860328656 #endif
@@ -28701,8 +28754,8 @@ static int ParseCipherList(Suites* suites,
2870128754 #endif
2870228755 {
2870328756 suites->suiteSz = (word16)idx;
28704- InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, keySz ,
28705- &suites->hashSigAlgoSz);
28757+ InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, tls1_3 ,
28758+ keySz, &suites->hashSigAlgoSz);
2870628759 }
2870728760
2870828761#ifdef HAVE_RENEGOTIATION_INDICATION
@@ -28775,6 +28828,7 @@ int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites, const byte* list,
2877528828 int haveFalconSig = 0;
2877628829 int haveDilithiumSig = 0;
2877728830 int haveAnon = 0;
28831+ int tls1_3 = 0;
2877828832
2877928833 if (suites == NULL || list == NULL) {
2878028834 WOLFSSL_MSG("SetCipherListFromBytes parameter error");
@@ -28834,6 +28888,7 @@ int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites, const byte* list,
2883428888 secondByte == TLS_SHA384_SHA384)) ||
2883528889 (firstByte == CIPHER_BYTE && (secondByte == TLS_SM4_GCM_SM3 ||
2883628890 secondByte == TLS_SM4_CCM_SM3))) {
28891+ tls1_3 = 1;
2883728892 #ifndef NO_RSA
2883828893 haveRSAsig = 1;
2883928894 #endif
@@ -28885,8 +28940,8 @@ int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites, const byte* list,
2888528940 haveSig |= haveFalconSig ? SIG_FALCON : 0;
2888628941 haveSig |= haveDilithiumSig ? SIG_DILITHIUM : 0;
2888728942 haveSig |= haveAnon ? SIG_ANON : 0;
28888- InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, keySz ,
28889- &suites->hashSigAlgoSz);
28943+ InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, tls1_3 ,
28944+ keySz, &suites->hashSigAlgoSz);
2889028945#ifdef HAVE_RENEGOTIATION_INDICATION
2889128946 if (ctx->method->side == WOLFSSL_CLIENT_END) {
2889228947 if (suites->suiteSz > WOLFSSL_MAX_SUITE_SZ - 2) {
@@ -29067,7 +29122,7 @@ int SetSuitesHashSigAlgo(Suites* suites, const char* list)
2906729122
2906829123#endif /* OPENSSL_EXTRA */
2906929124
29070- #if !defined(NO_WOLFSSL_SERVER) || !defined(NO_CERTS)
29125+ #if !defined(NO_TLS) && (!defined( NO_WOLFSSL_SERVER) || !defined(NO_CERTS) )
2907129126static int MatchSigAlgo(WOLFSSL* ssl, int sigAlgo)
2907229127{
2907329128#ifdef HAVE_ED25519
@@ -29134,6 +29189,41 @@ static int MatchSigAlgo(WOLFSSL* ssl, int sigAlgo)
2913429189 if (sigAlgo == rsa_pss_sa_algo)
2913529190 return 1;
2913629191 }
29192+ #endif
29193+ #ifdef HAVE_ECC_BRAINPOOL
29194+ if ((ssl->pkCurveOID == ECC_BRAINPOOLP256R1_OID) ||
29195+ (ssl->pkCurveOID == ECC_BRAINPOOLP384R1_OID) ||
29196+ (ssl->pkCurveOID == ECC_BRAINPOOLP512R1_OID)) {
29197+ if (IsAtLeastTLSv1_3(ssl->version)) {
29198+ /* Certificate has an ECC Brainpool key, only match with the
29199+ * specified ECDSA brainpool signature algorithms for TLS 1.3 */
29200+ return sigAlgo == ecc_brainpool_sa_algo;
29201+ }
29202+ else {
29203+ /* Certificate has an ECC Brainpool key, match with ECDSA in TLS 1.2
29204+ * case, but only when the related Brainpool curve is present in
29205+ * the supported_groups extension. */
29206+ if (ssl->pkCurveOID == ECC_BRAINPOOLP256R1_OID &&
29207+ TLSX_SupportedCurve_IsSupported(ssl,
29208+ WOLFSSL_ECC_BRAINPOOLP256R1)) {
29209+ return sigAlgo == ecc_dsa_sa_algo;
29210+ }
29211+ else if (ssl->pkCurveOID == ECC_BRAINPOOLP384R1_OID &&
29212+ TLSX_SupportedCurve_IsSupported(ssl,
29213+ WOLFSSL_ECC_BRAINPOOLP384R1)) {
29214+ return sigAlgo == ecc_dsa_sa_algo;
29215+ }
29216+ else if (ssl->pkCurveOID == ECC_BRAINPOOLP512R1_OID &&
29217+ TLSX_SupportedCurve_IsSupported(ssl,
29218+ WOLFSSL_ECC_BRAINPOOLP512R1)) {
29219+ return sigAlgo == ecc_dsa_sa_algo;
29220+ }
29221+ else {
29222+ /* Curve not supported in supported_groups extension. */
29223+ return 0;
29224+ }
29225+ }
29226+ }
2913729227#endif
2913829228 /* Signature algorithm matches certificate. */
2913929229 return sigAlgo == ssl->options.sigAlgo;
@@ -29299,6 +29389,15 @@ int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz,
2929929389 break;
2930029390 }
2930129391 #endif /* HAVE_DILITHIUM */
29392+ #if defined(HAVE_ECC_BRAINPOOL)
29393+ if (ssl->pkCurveOID == ECC_BRAINPOOLP256R1_OID ||
29394+ ssl->pkCurveOID == ECC_BRAINPOOLP384R1_OID ||
29395+ ssl->pkCurveOID == ECC_BRAINPOOLP512R1_OID) {
29396+ /* Matched ECC Brainpool. Set sigAlgo to "normal" ECDSA here
29397+ * for compatibility with TLS 1.2. */
29398+ sigAlgo = ecc_dsa_sa_algo;
29399+ }
29400+ #endif
2930229401
2930329402 #if defined(WOLFSSL_ECDSA_MATCH_HASH) && defined(USE_ECDSA_KEYSZ_HASH_ALGO)
2930429403 #error "WOLFSSL_ECDSA_MATCH_HASH and USE_ECDSA_KEYSZ_HASH_ALGO cannot "
@@ -29439,7 +29538,7 @@ int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz,
2943929538
2944029539 return ret;
2944129540}
29442- #endif /* !defined(NO_WOLFSSL_SERVER) || !defined(NO_CERTS) */
29541+ #endif /* !NO_TLS && (! defined(NO_WOLFSSL_SERVER) || !defined(NO_CERTS) ) */
2944329542
2944429543#if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
2944529544
0 commit comments