8216045: The size of key_exchange may be wrong on FFDHE
authorxuelei
Wed, 16 Jan 2019 11:19:43 -0800
changeset 53359 cb4212fda8e4
parent 53358 659b004b6a1b
child 53360 58e25974ede4
child 53371 06a3625e41b8
8216045: The size of key_exchange may be wrong on FFDHE Reviewed-by: jnimeh
src/java.base/share/classes/sun/security/ssl/DHKeyExchange.java
--- a/src/java.base/share/classes/sun/security/ssl/DHKeyExchange.java	Wed Jan 16 23:56:32 2019 +0530
+++ b/src/java.base/share/classes/sun/security/ssl/DHKeyExchange.java	Wed Jan 16 11:19:43 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -220,8 +220,8 @@
         public byte[] encode() {
             // Note: the DH public value is encoded as a big-endian integer
             // and padded to the left with zeros to the size of p in bytes.
-            byte[] encoded = publicKey.getY().toByteArray();
-            int pSize = KeyUtil.getKeySize(publicKey);
+            byte[] encoded = Utilities.toByteArray(publicKey.getY());
+            int pSize = (KeyUtil.getKeySize(publicKey) + 7) >>> 3;
             if (pSize > 0 && encoded.length < pSize) {
                 byte[] buffer = new byte[pSize];
                 System.arraycopy(encoded, 0,