src/java.base/share/classes/sun/security/ssl/DHKeyExchange.java
changeset 53359 cb4212fda8e4
parent 53064 103ed9569fc8
child 53734 cb1642ccc732
equal deleted inserted replaced
53358:659b004b6a1b 53359:cb4212fda8e4
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   218 
   218 
   219         @Override
   219         @Override
   220         public byte[] encode() {
   220         public byte[] encode() {
   221             // Note: the DH public value is encoded as a big-endian integer
   221             // Note: the DH public value is encoded as a big-endian integer
   222             // and padded to the left with zeros to the size of p in bytes.
   222             // and padded to the left with zeros to the size of p in bytes.
   223             byte[] encoded = publicKey.getY().toByteArray();
   223             byte[] encoded = Utilities.toByteArray(publicKey.getY());
   224             int pSize = KeyUtil.getKeySize(publicKey);
   224             int pSize = (KeyUtil.getKeySize(publicKey) + 7) >>> 3;
   225             if (pSize > 0 && encoded.length < pSize) {
   225             if (pSize > 0 && encoded.length < pSize) {
   226                 byte[] buffer = new byte[pSize];
   226                 byte[] buffer = new byte[pSize];
   227                 System.arraycopy(encoded, 0,
   227                 System.arraycopy(encoded, 0,
   228                         buffer, pSize - encoded.length, encoded.length);
   228                         buffer, pSize - encoded.length, encoded.length);
   229                 encoded = buffer;
   229                 encoded = buffer;