Merge upstream master

Changes the message text of a couple exceptions and fixes Wycheproof's
EcdhTest.

Bug: 68855787
Test: cts -m CtsLibcoreTestCases
Test: cts -m CtsLibcoreWycheproofConscryptTestCases
Test: cts -m CtsLibcoreOkHttpTestCases
Change-Id: I132645ba0d74d2ddb81531ffa668d2fb65d660bd
diff --git a/common/src/main/java/org/conscrypt/OpenSSLCipherChaCha20.java b/common/src/main/java/org/conscrypt/OpenSSLCipherChaCha20.java
index 9689ed4..c233ff3 100644
--- a/common/src/main/java/org/conscrypt/OpenSSLCipherChaCha20.java
+++ b/common/src/main/java/org/conscrypt/OpenSSLCipherChaCha20.java
@@ -58,7 +58,7 @@
         } else {
             if (!isEncrypting()) {
                 throw new InvalidAlgorithmParameterException(
-                        "IV must be specified when encrypting");
+                        "IV must be specified when decrypting");
             }
             iv = new byte[NONCE_SIZE_BYTES];
             if (random != null) {
diff --git a/common/src/main/java/org/conscrypt/OpenSSLECGroupContext.java b/common/src/main/java/org/conscrypt/OpenSSLECGroupContext.java
index 71abafa..c71b276 100644
--- a/common/src/main/java/org/conscrypt/OpenSSLECGroupContext.java
+++ b/common/src/main/java/org/conscrypt/OpenSSLECGroupContext.java
@@ -119,7 +119,7 @@
                 break;
             case 521:
                 if (p.toString(16).equals("1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") &&
-                    b.toString(16).equals("051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00") &&
+                    b.toString(16).equals("51953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00") &&
                     x.toString(16).equals("c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66") &&
                     y.toString(16).equals("11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")) {
                     curveName = "secp521r1";
diff --git a/common/src/main/java/org/conscrypt/SSLUtils.java b/common/src/main/java/org/conscrypt/SSLUtils.java
index 09ce91e..583ebcc 100644
--- a/common/src/main/java/org/conscrypt/SSLUtils.java
+++ b/common/src/main/java/org/conscrypt/SSLUtils.java
@@ -46,6 +46,7 @@
 import java.security.cert.CertificateEncodingException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 import javax.net.ssl.SSLException;
@@ -359,7 +360,9 @@
             int protocolLength = protocols[i];
             if (protocolLength < 0 || protocolLength > protocols.length - i) {
                 throw new IllegalArgumentException(
-                        "Protocol has invalid length (" + protocolLength + "): " + protocols[i]);
+                    "Protocol has invalid length (" + protocolLength + " at position " + i
+                        + "): " + (protocols.length < 50
+                        ? Arrays.toString(protocols) : protocols.length + " byte array"));
             }
 
             numProtocols++;