@@ -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))
@@ -4511,8 +4547,8 @@ void InitSuites(Suites* suites, ProtocolVersion pv, int keySz, word16 haveRSA,
45114547 suites->suiteSz = idx;
45124548
45134549 if (suites->hashSigAlgoSz == 0) {
4514- InitSuitesHashSigAlgo(suites->hashSigAlgo, SIG_ALL, tls1_2, keySz ,
4515- &suites->hashSigAlgoSz);
4550+ InitSuitesHashSigAlgo(suites->hashSigAlgo, SIG_ALL, tls1_2, tls1_3 ,
4551+ keySz, &suites->hashSigAlgoSz);
45164552 }
45174553
45184554 /* Moved to the end as we set some of the vars but never use them */
@@ -4571,6 +4607,22 @@ void DecodeSigAlg(const byte* input, byte* hashAlgo, byte* hsType)
45714607 *hashAlgo = PSS_PSS_HASH_TO_MAC(input[1]);
45724608 }
45734609 else
4610+ #endif
4611+ #ifdef HAVE_ECC_BRAINPOOL
4612+ /* RFC 8734 TLS 1.3 Brainpool curves */
4613+ if (input[1] == ECDSA_BRAINPOOLP256R1TLS13_SHA256_MINOR) {
4614+ *hsType = ecc_brainpool_sa_algo;
4615+ *hashAlgo = sha256_mac;
4616+ }
4617+ else if (input[1] == ECDSA_BRAINPOOLP384R1TLS13_SHA384_MINOR) {
4618+ *hsType = ecc_brainpool_sa_algo;
4619+ *hashAlgo = sha384_mac;
4620+ }
4621+ else if (input[1] == ECDSA_BRAINPOOLP512R1TLS13_SHA512_MINOR) {
4622+ *hsType = ecc_brainpool_sa_algo;
4623+ *hashAlgo = sha512_mac;
4624+ }
4625+ else
45744626 #endif
45754627 {
45764628 *hsType = input[0];
@@ -28273,6 +28325,7 @@ static int ParseCipherList(Suites* suites,
2827328325 word16 haveSHA1 = 1; /* allowed by default if compiled in */
2827428326 word16 haveRC4 = 1; /* allowed by default if compiled in */
2827528327#endif
28328+ int tls1_3 = 0;
2827628329 const int suiteSz = GetCipherNamesSize();
2827728330 const char* next = list;
2827828331
@@ -28598,6 +28651,7 @@ static int ParseCipherList(Suites* suites,
2859828651 (cipher_names[i].cipherSuite0 == ECC_BYTE &&
2859928652 (cipher_names[i].cipherSuite == TLS_SHA256_SHA256 ||
2860028653 cipher_names[i].cipherSuite == TLS_SHA384_SHA384))) {
28654+ tls1_3 = 1;
2860128655 #ifndef NO_RSA
2860228656 haveSig |= SIG_RSA;
2860328657 #endif
@@ -28701,8 +28755,8 @@ static int ParseCipherList(Suites* suites,
2870128755 #endif
2870228756 {
2870328757 suites->suiteSz = (word16)idx;
28704- InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, keySz ,
28705- &suites->hashSigAlgoSz);
28758+ InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, tls1_3 ,
28759+ keySz, &suites->hashSigAlgoSz);
2870628760 }
2870728761
2870828762#ifdef HAVE_RENEGOTIATION_INDICATION
@@ -28775,6 +28829,7 @@ int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites, const byte* list,
2877528829 int haveFalconSig = 0;
2877628830 int haveDilithiumSig = 0;
2877728831 int haveAnon = 0;
28832+ int tls1_3 = 0;
2877828833
2877928834 if (suites == NULL || list == NULL) {
2878028835 WOLFSSL_MSG("SetCipherListFromBytes parameter error");
@@ -28834,6 +28889,7 @@ int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites, const byte* list,
2883428889 secondByte == TLS_SHA384_SHA384)) ||
2883528890 (firstByte == CIPHER_BYTE && (secondByte == TLS_SM4_GCM_SM3 ||
2883628891 secondByte == TLS_SM4_CCM_SM3))) {
28892+ tls1_3 = 1;
2883728893 #ifndef NO_RSA
2883828894 haveRSAsig = 1;
2883928895 #endif
@@ -28885,8 +28941,8 @@ int SetCipherListFromBytes(WOLFSSL_CTX* ctx, Suites* suites, const byte* list,
2888528941 haveSig |= haveFalconSig ? SIG_FALCON : 0;
2888628942 haveSig |= haveDilithiumSig ? SIG_DILITHIUM : 0;
2888728943 haveSig |= haveAnon ? SIG_ANON : 0;
28888- InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, keySz ,
28889- &suites->hashSigAlgoSz);
28944+ InitSuitesHashSigAlgo(suites->hashSigAlgo, haveSig, 1, tls1_3 ,
28945+ keySz, &suites->hashSigAlgoSz);
2889028946#ifdef HAVE_RENEGOTIATION_INDICATION
2889128947 if (ctx->method->side == WOLFSSL_CLIENT_END) {
2889228948 if (suites->suiteSz > WOLFSSL_MAX_SUITE_SZ - 2) {
@@ -29134,6 +29190,41 @@ static int MatchSigAlgo(WOLFSSL* ssl, int sigAlgo)
2913429190 if (sigAlgo == rsa_pss_sa_algo)
2913529191 return 1;
2913629192 }
29193+ #endif
29194+ #ifdef HAVE_ECC_BRAINPOOL
29195+ if ((ssl->pkCurveOID == ECC_BRAINPOOLP256R1_OID) ||
29196+ (ssl->pkCurveOID == ECC_BRAINPOOLP384R1_OID) ||
29197+ (ssl->pkCurveOID == ECC_BRAINPOOLP512R1_OID)) {
29198+ if (IsAtLeastTLSv1_3(ssl->version)) {
29199+ /* Certificate has an ECC Brainpool key, only match with the
29200+ * specified ECDSA brainpool signature algorithms for TLS 1.3 */
29201+ return sigAlgo == ecc_brainpool_sa_algo;
29202+ }
29203+ else {
29204+ /* Certificate has an ECC Brainpool key, match with ECDSA in TLS 1.2
29205+ * case, but only when the related Brainpool curve is present in
29206+ * the supported_groups extension. */
29207+ if (ssl->pkCurveOID == ECC_BRAINPOOLP256R1_OID &&
29208+ TLSX_SupportedCurve_IsSupported(ssl,
29209+ WOLFSSL_ECC_BRAINPOOLP256R1)) {
29210+ return sigAlgo == ecc_dsa_sa_algo;
29211+ }
29212+ else if (ssl->pkCurveOID == ECC_BRAINPOOLP384R1_OID &&
29213+ TLSX_SupportedCurve_IsSupported(ssl,
29214+ WOLFSSL_ECC_BRAINPOOLP384R1)) {
29215+ return sigAlgo == ecc_dsa_sa_algo;
29216+ }
29217+ else if (ssl->pkCurveOID == ECC_BRAINPOOLP512R1_OID &&
29218+ TLSX_SupportedCurve_IsSupported(ssl,
29219+ WOLFSSL_ECC_BRAINPOOLP512R1)) {
29220+ return sigAlgo == ecc_dsa_sa_algo;
29221+ }
29222+ else {
29223+ /* Curve not supported in supported_groups extension. */
29224+ return 0;
29225+ }
29226+ }
29227+ }
2913729228#endif
2913829229 /* Signature algorithm matches certificate. */
2913929230 return sigAlgo == ssl->options.sigAlgo;
@@ -29299,6 +29390,15 @@ int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz,
2929929390 break;
2930029391 }
2930129392 #endif /* HAVE_DILITHIUM */
29393+ #if defined(HAVE_ECC_BRAINPOOL)
29394+ if (ssl->pkCurveOID == ECC_BRAINPOOLP256R1_OID ||
29395+ ssl->pkCurveOID == ECC_BRAINPOOLP384R1_OID ||
29396+ ssl->pkCurveOID == ECC_BRAINPOOLP512R1_OID) {
29397+ /* Matched ECC Brainpool. Set sigAlgo to "normal" ECDSA here
29398+ * for compatibilty with TLS 1.2. */
29399+ sigAlgo = ecc_dsa_sa_algo;
29400+ }
29401+ #endif
2930229402
2930329403 #if defined(WOLFSSL_ECDSA_MATCH_HASH) && defined(USE_ECDSA_KEYSZ_HASH_ALGO)
2930429404 #error "WOLFSSL_ECDSA_MATCH_HASH and USE_ECDSA_KEYSZ_HASH_ALGO cannot "
0 commit comments