Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: net/third_party/nss/ssl/ssl3ecc.c

Issue 14522022: Update NSS libSSL to NSS_3_15_BETA2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * SSL3 Protocol 2 * SSL3 Protocol
3 * 3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public 4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 7
8 /* ECC code moved here from ssl3con.c */ 8 /* ECC code moved here from ssl3con.c */
9 /* $Id: ssl3ecc.c,v 1.29 2012/06/11 02:38:30 emaldona%redhat.com Exp $ */ 9 /* $Id$ */
10 10
11 #include "nss.h" 11 #include "nss.h"
12 #include "cert.h" 12 #include "cert.h"
13 #include "ssl.h" 13 #include "ssl.h"
14 #include "cryptohi.h" /* for DSAU_ stuff */ 14 #include "cryptohi.h" /* for DSAU_ stuff */
15 #include "keyhi.h" 15 #include "keyhi.h"
16 #include "secder.h" 16 #include "secder.h"
17 #include "secitem.h" 17 #include "secitem.h"
18 18
19 #include "sslimpl.h" 19 #include "sslimpl.h"
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 } 962 }
963 } 963 }
964 } 964 }
965 965
966 /* Ask: is ANY ECC cipher suite enabled on this socket? */ 966 /* Ask: is ANY ECC cipher suite enabled on this socket? */
967 /* Order(N^2). Yuk. Also, this ignores export policy. */ 967 /* Order(N^2). Yuk. Also, this ignores export policy. */
968 PRBool 968 PRBool
969 ssl3_IsECCEnabled(sslSocket * ss) 969 ssl3_IsECCEnabled(sslSocket * ss)
970 { 970 {
971 const ssl3CipherSuite * suite; 971 const ssl3CipherSuite * suite;
972 PK11SlotInfo *slot;
972 973
974 /* make sure we can do ECC */
975 slot = PK11_GetBestSlot(CKM_ECDH1_DERIVE, ss->pkcs11PinArg);
976 if (!slot) {
977 return PR_FALSE;
978 }
979 PK11_FreeSlot(slot);
980
981 /* make sure an ECC cipher is enabled */
973 for (suite = ecSuites; *suite; ++suite) { 982 for (suite = ecSuites; *suite; ++suite) {
974 PRBool enabled = PR_FALSE; 983 PRBool enabled = PR_FALSE;
975 SECStatus rv = ssl3_CipherPrefGet(ss, *suite, &enabled); 984 SECStatus rv = ssl3_CipherPrefGet(ss, *suite, &enabled);
976 985
977 PORT_Assert(rv == SECSuccess); /* else is coding error */ 986 PORT_Assert(rv == SECSuccess); /* else is coding error */
978 if (rv == SECSuccess && enabled) 987 if (rv == SECSuccess && enabled)
979 return PR_TRUE; 988 return PR_TRUE;
980 } 989 }
981 return PR_FALSE; 990 return PR_FALSE;
982 } 991 }
983 992
984 #define BE(n) 0, n 993 #define BE(n) 0, n
985 994
986 #ifndef NSS_ECC_MORE_THAN_SUITE_B
987 /* Prefabricated TLS client hello extension, Elliptic Curves List, 995 /* Prefabricated TLS client hello extension, Elliptic Curves List,
988 * offers only 3 curves, the Suite B curves, 23-25 996 * offers only 3 curves, the Suite B curves, 23-25
989 */ 997 */
990 static const PRUint8 EClist[12] = { 998 static const PRUint8 suiteBECList[12] = {
991 BE(10), /* Extension type */ 999 BE(10), /* Extension type */
992 BE( 8), /* octets that follow ( 3 pairs + 1 length pair) */ 1000 BE( 8), /* octets that follow ( 3 pairs + 1 length pair) */
993 BE( 6), /* octets that follow ( 3 pairs) */ 1001 BE( 6), /* octets that follow ( 3 pairs) */
994 BE(23), BE(24), BE(25) 1002 BE(23), BE(24), BE(25)
995 }; 1003 };
996 #else 1004
997 /* Prefabricated TLS client hello extension, Elliptic Curves List, 1005 /* Prefabricated TLS client hello extension, Elliptic Curves List,
998 * offers curves 1-25. 1006 * offers curves 1-25.
999 */ 1007 */
1000 static const PRUint8 EClist[56] = { 1008 static const PRUint8 tlsECList[56] = {
1001 BE(10), /* Extension type */ 1009 BE(10), /* Extension type */
1002 BE(52), /* octets that follow (25 pairs + 1 length pair) */ 1010 BE(52), /* octets that follow (25 pairs + 1 length pair) */
1003 BE(50), /* octets that follow (25 pairs) */ 1011 BE(50), /* octets that follow (25 pairs) */
1004 BE( 1), BE( 2), BE( 3), BE( 4), BE( 5), BE( 6), BE( 7), 1012 BE( 1), BE( 2), BE( 3), BE( 4), BE( 5), BE( 6), BE( 7),
1005 BE( 8), BE( 9), BE(10), BE(11), BE(12), BE(13), BE(14), BE(15), 1013 BE( 8), BE( 9), BE(10), BE(11), BE(12), BE(13), BE(14), BE(15),
1006 BE(16), BE(17), BE(18), BE(19), BE(20), BE(21), BE(22), BE(23), 1014 BE(16), BE(17), BE(18), BE(19), BE(20), BE(21), BE(22), BE(23),
1007 BE(24), BE(25) 1015 BE(24), BE(25)
1008 }; 1016 };
1009 #endif
1010 1017
1011 static const PRUint8 ECPtFmt[6] = { 1018 static const PRUint8 ECPtFmt[6] = {
1012 BE(11), /* Extension type */ 1019 BE(11), /* Extension type */
1013 BE( 2), /* octets that follow */ 1020 BE( 2), /* octets that follow */
1014 1, /* octets that follow */ 1021 1, /* octets that follow */
1015 0 /* uncompressed type only */ 1022 0 /* uncompressed type only */
1016 }; 1023 };
1017 1024
1025 /* This function already presumes we can do ECC, ssl_IsECCEnabled must be
1026 * called before this function. It looks to see if we have a token which
1027 * is capable of doing smaller than SuiteB curves. If the token can, we
1028 * presume the token can do the whole SSL suite of curves. If it can't we
1029 * presume the token that allowed ECC to be enabled can only do suite B
1030 * curves. */
1031 static PRBool
1032 ssl3_SuiteBOnly(sslSocket *ss)
1033 {
1034 /* look to see if we can handle certs less than 163 bits */
1035 PK11SlotInfo *slot =
1036 PK11_GetBestSlotWithAttributes(CKM_ECDH1_DERIVE, 0, 163,
1037 ss ? ss->pkcs11PinArg : NULL);
1038
1039 if (!slot) {
1040 /* nope, presume we can only do suite B */
1041 return PR_TRUE;
1042 }
1043 /* we can, presume we can do all curves */
1044 PK11_FreeSlot(slot);
1045 return PR_FALSE;
1046 }
1047
1018 /* Send our "canned" (precompiled) Supported Elliptic Curves extension, 1048 /* Send our "canned" (precompiled) Supported Elliptic Curves extension,
1019 * which says that we support all TLS-defined named curves. 1049 * which says that we support all TLS-defined named curves.
1020 */ 1050 */
1021 PRInt32 1051 PRInt32
1022 ssl3_SendSupportedCurvesXtn( 1052 ssl3_SendSupportedCurvesXtn(
1023 sslSocket * ss, 1053 sslSocket * ss,
1024 PRBool append, 1054 PRBool append,
1025 PRUint32 maxBytes) 1055 PRUint32 maxBytes)
1026 { 1056 {
1057 int ECListSize = 0;
1058 const PRUint8 *ECList = NULL;
1059
1027 if (!ss || !ssl3_IsECCEnabled(ss)) 1060 if (!ss || !ssl3_IsECCEnabled(ss))
1028 return 0; 1061 return 0;
1029 if (append && maxBytes >= (sizeof EClist)) { 1062
1030 » SECStatus rv = ssl3_AppendHandshake(ss, EClist, (sizeof EClist)); 1063 if (ssl3_SuiteBOnly(ss)) {
1064 » ECListSize = sizeof (suiteBECList);
1065 » ECList = suiteBECList;
1066 } else {
1067 » ECListSize = sizeof (tlsECList);
1068 » ECList = tlsECList;
1069 }
1070
1071 if (append && maxBytes >= ECListSize) {
1072 » SECStatus rv = ssl3_AppendHandshake(ss, ECList, ECListSize);
1031 if (rv != SECSuccess) 1073 if (rv != SECSuccess)
1032 return -1; 1074 return -1;
1033 if (!ss->sec.isServer) { 1075 if (!ss->sec.isServer) {
1034 TLSExtensionData *xtnData = &ss->xtnData; 1076 TLSExtensionData *xtnData = &ss->xtnData;
1035 xtnData->advertised[xtnData->numAdvertised++] = 1077 xtnData->advertised[xtnData->numAdvertised++] =
1036 ssl_elliptic_curves_xtn; 1078 ssl_elliptic_curves_xtn;
1037 } 1079 }
1038 } 1080 }
1039 return (sizeof EClist); 1081 return ECListSize;
1082 }
1083
1084 PRInt32
1085 ssl3_GetSupportedECCCurveMask(sslSocket *ss)
1086 {
1087 if (ssl3_SuiteBOnly(ss)) {
1088 » return SSL3_SUITE_B_SUPPORTED_CURVES_MASK;
1089 }
1090 return SSL3_ALL_SUPPORTED_CURVES_MASK;
1040 } 1091 }
1041 1092
1042 /* Send our "canned" (precompiled) Supported Point Formats extension, 1093 /* Send our "canned" (precompiled) Supported Point Formats extension,
1043 * which says that we only support uncompressed points. 1094 * which says that we only support uncompressed points.
1044 */ 1095 */
1045 PRInt32 1096 PRInt32
1046 ssl3_SendSupportedPointFormatsXtn( 1097 ssl3_SendSupportedPointFormatsXtn(
1047 sslSocket * ss, 1098 sslSocket * ss,
1048 PRBool append, 1099 PRBool append,
1049 PRUint32 maxBytes) 1100 PRUint32 maxBytes)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 ssl3_DisableECCSuites(ss, ecdhe_ecdsa_suites); 1209 ssl3_DisableECCSuites(ss, ecdhe_ecdsa_suites);
1159 return SECFailure; 1210 return SECFailure;
1160 1211
1161 loser: 1212 loser:
1162 /* no common curve supported */ 1213 /* no common curve supported */
1163 ssl3_DisableECCSuites(ss, ecSuites); 1214 ssl3_DisableECCSuites(ss, ecSuites);
1164 return SECFailure; 1215 return SECFailure;
1165 } 1216 }
1166 1217
1167 #endif /* NSS_ENABLE_ECC */ 1218 #endif /* NSS_ENABLE_ECC */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698