jdk/src/share/classes/com/sun/crypto/provider/DHKeyAgreement.java
author xuelei
Mon, 22 Oct 2012 07:28:51 -0700
changeset 16080 0e6266b88242
parent 12201 d77ed23f4992
child 17916 e02ddef88f77
permissions -rw-r--r--
7192392: Better validation of client keys Summary: Also reviewed by Andrew Gross<Andrew.Gross@Oracle.COM> Reviewed-by: vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.crypto.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.InvalidAlgorithmParameterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.InvalidKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.Key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.SecureRandom;
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
    36
import java.security.ProviderException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.spec.InvalidKeySpecException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.crypto.KeyAgreementSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.crypto.ShortBufferException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.crypto.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
16080
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 12201
diff changeset
    44
import sun.security.util.KeyUtil;
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 12201
diff changeset
    45
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * This class implements the Diffie-Hellman key agreement protocol between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * any number of parties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public final class DHKeyAgreement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
extends KeyAgreementSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private boolean generateSecret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private BigInteger init_p = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private BigInteger init_g = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private BigInteger x = BigInteger.ZERO; // the private value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private BigInteger y = BigInteger.ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
3353
ddbd63234844 6647452: Remove obfuscation, framework and provider self-verification checking
wetmore
parents: 2
diff changeset
    64
     * Empty constructor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public DHKeyAgreement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Initializes this key agreement with the given key and source of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * randomness. The given key is required to contain all the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * parameters required for this key agreement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p> If the key agreement algorithm requires random bytes, it gets them
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * from the given source of randomness, <code>random</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * However, if the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * algorithm implementation does not require any random bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * <code>random</code> is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param key the party's private information. For example, in the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * of the Diffie-Hellman key agreement, this would be the party's own
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Diffie-Hellman private key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param random the source of randomness
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @exception InvalidKeyException if the given key is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * inappropriate for this key agreement, e.g., is of the wrong type or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * has an incompatible algorithm type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected void engineInit(Key key, SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        throws InvalidKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            engineInit(key, null, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } catch (InvalidAlgorithmParameterException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            // never happens, because we did not pass any parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Initializes this key agreement with the given key, set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * algorithm parameters, and source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param key the party's private information. For example, in the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * of the Diffie-Hellman key agreement, this would be the party's own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Diffie-Hellman private key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param params the key agreement parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param random the source of randomness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @exception InvalidKeyException if the given key is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * inappropriate for this key agreement, e.g., is of the wrong type or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * has an incompatible algorithm type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @exception InvalidAlgorithmParameterException if the given parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * are inappropriate for this key agreement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected void engineInit(Key key, AlgorithmParameterSpec params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                              SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        throws InvalidKeyException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // ignore "random" parameter, because our implementation does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // require any source of randomness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        generateSecret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        init_p = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        init_g = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if ((params != null) && !(params instanceof DHParameterSpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            throw new InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                ("Diffie-Hellman parameters expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (!(key instanceof javax.crypto.interfaces.DHPrivateKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw new InvalidKeyException("Diffie-Hellman private key "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                          + "expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        javax.crypto.interfaces.DHPrivateKey dhPrivKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        dhPrivKey = (javax.crypto.interfaces.DHPrivateKey)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // check if private key parameters are compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // initialized ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (params != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            init_p = ((DHParameterSpec)params).getP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            init_g = ((DHParameterSpec)params).getG();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        BigInteger priv_p = dhPrivKey.getParams().getP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        BigInteger priv_g = dhPrivKey.getParams().getG();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (init_p != null && priv_p != null && !(init_p.equals(priv_p))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throw new InvalidKeyException("Incompatible parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (init_g != null && priv_g != null && !(init_g.equals(priv_g))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throw new InvalidKeyException("Incompatible parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if ((init_p == null && priv_p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            || (init_g == null && priv_g == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            throw new InvalidKeyException("Missing parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        init_p = priv_p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        init_g = priv_g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // store the x value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.x = dhPrivKey.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Executes the next phase of this key agreement with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * key that was received from one of the other parties involved in this key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * agreement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param key the key for this phase. For example, in the case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Diffie-Hellman between 2 parties, this would be the other party's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Diffie-Hellman public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param lastPhase flag which indicates whether or not this is the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * phase of this key agreement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the (intermediate) key resulting from this phase, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * this phase does not yield a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @exception InvalidKeyException if the given key is inappropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * this phase.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @exception IllegalStateException if this key agreement has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    protected Key engineDoPhase(Key key, boolean lastPhase)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        throws InvalidKeyException, IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (!(key instanceof javax.crypto.interfaces.DHPublicKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            throw new InvalidKeyException("Diffie-Hellman public key "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                          + "expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        javax.crypto.interfaces.DHPublicKey dhPubKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        dhPubKey = (javax.crypto.interfaces.DHPublicKey)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (init_p == null || init_g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            throw new IllegalStateException("Not initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // check if public key parameters are compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // initialized ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        BigInteger pub_p = dhPubKey.getParams().getP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        BigInteger pub_g = dhPubKey.getParams().getG();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (pub_p != null && !(init_p.equals(pub_p))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new InvalidKeyException("Incompatible parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (pub_g != null && !(init_g.equals(pub_g))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new InvalidKeyException("Incompatible parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
16080
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 12201
diff changeset
   205
        // validate the Diffie-Hellman public key
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 12201
diff changeset
   206
        KeyUtil.validate(dhPubKey);
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 12201
diff changeset
   207
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // store the y value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        this.y = dhPubKey.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // we've received a public key (from one of the other parties),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // so we are ready to create the secret, which may be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // intermediate secret, in which case we wrap it into a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // Diffie-Hellman public key object and return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        generateSecret = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (lastPhase == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            byte[] intermediate = engineGenerateSecret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return new DHPublicKey(new BigInteger(1, intermediate),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                   init_p, init_g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Generates the shared secret and returns it in a new buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p>This method resets this <code>KeyAgreementSpi</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * so that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * can be reused for further key agreements. Unless this key agreement is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * reinitialized with one of the <code>engineInit</code> methods, the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * private information and algorithm parameters will be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * subsequent key agreements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return the new buffer with the shared secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @exception IllegalStateException if this key agreement has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * completed yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    protected byte[] engineGenerateSecret()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    {
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   243
        int expectedLen = (init_p.bitLength() + 7) >>> 3;
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   244
        byte[] result = new byte[expectedLen];
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   245
        try {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   246
            engineGenerateSecret(result, 0);
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   247
        } catch (ShortBufferException sbe) {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   248
            // should never happen since length are identical
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   250
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Generates the shared secret, and places it into the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <code>sharedSecret</code>, beginning at <code>offset</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p>If the <code>sharedSecret</code> buffer is too small to hold the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * result, a <code>ShortBufferException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * In this case, this call should be repeated with a larger output buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <p>This method resets this <code>KeyAgreementSpi</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * so that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * can be reused for further key agreements. Unless this key agreement is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * reinitialized with one of the <code>engineInit</code> methods, the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * private information and algorithm parameters will be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * subsequent key agreements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param sharedSecret the buffer for the shared secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param offset the offset in <code>sharedSecret</code> where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * shared secret will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return the number of bytes placed into <code>sharedSecret</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @exception IllegalStateException if this key agreement has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * completed yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @exception ShortBufferException if the given output buffer is too small
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * to hold the secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    protected int engineGenerateSecret(byte[] sharedSecret, int offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        throws IllegalStateException, ShortBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (generateSecret == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            throw new IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                ("Key agreement has not been completed yet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (sharedSecret == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new ShortBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                ("No buffer provided for shared secret");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        BigInteger modulus = init_p;
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   293
        int expectedLen = (modulus.bitLength() + 7) >>> 3;
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   294
        if ((sharedSecret.length - offset) < expectedLen) {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   295
            throw new ShortBufferException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    ("Buffer too short for shared secret");
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   297
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   299
        // Reset the key agreement after checking for ShortBufferException
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   300
        // above, so user can recover w/o losing internal state
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   301
        generateSecret = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   303
        /*
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   304
         * NOTE: BigInteger.toByteArray() returns a byte array containing
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   305
         * the two's-complement representation of this BigInteger with
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   306
         * the most significant byte is in the zeroth element. This
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   307
         * contains the minimum number of bytes required to represent
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   308
         * this BigInteger, including at least one sign bit whose value
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   309
         * is always 0.
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   310
         *
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   311
         * Keys are always positive, and the above sign bit isn't
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   312
         * actually used when representing keys.  (i.e. key = new
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   313
         * BigInteger(1, byteArray))  To obtain an array containing
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   314
         * exactly expectedLen bytes of magnitude, we strip any extra
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   315
         * leading 0's, or pad with 0's in case of a "short" secret.
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   316
         */
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   317
        byte[] secret = this.y.modPow(this.x, modulus).toByteArray();
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   318
        if (secret.length == expectedLen) {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   319
            System.arraycopy(secret, 0, sharedSecret, offset,
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   320
                             secret.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        } else {
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   322
            // Array too short, pad it w/ leading 0s
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   323
            if (secret.length < expectedLen) {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   324
                System.arraycopy(secret, 0, sharedSecret,
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   325
                    offset + (expectedLen - secret.length),
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   326
                    secret.length);
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   327
            } else {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   328
                // Array too long, check and trim off the excess
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   329
                if ((secret.length == (expectedLen+1)) && secret[0] == 0) {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   330
                    // ignore the leading sign byte
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   331
                    System.arraycopy(secret, 1, sharedSecret, offset, expectedLen);
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   332
                } else {
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   333
                    throw new ProviderException("Generated secret is out-of-range");
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   334
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
12201
d77ed23f4992 7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents: 5506
diff changeset
   337
        return expectedLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Creates the shared secret and returns it as a secret key object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * of the requested algorithm type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <p>This method resets this <code>KeyAgreementSpi</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * so that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * can be reused for further key agreements. Unless this key agreement is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * reinitialized with one of the <code>engineInit</code> methods, the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * private information and algorithm parameters will be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * subsequent key agreements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param algorithm the requested secret key algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @return the shared secret key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @exception IllegalStateException if this key agreement has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * completed yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @exception NoSuchAlgorithmException if the requested secret key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @exception InvalidKeyException if the shared secret key material cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * be used to generate a secret key of the requested algorithm type (e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * the key material is too short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    protected SecretKey engineGenerateSecret(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        throws IllegalStateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            InvalidKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (algorithm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            throw new NoSuchAlgorithmException("null algorithm");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        byte[] secret = engineGenerateSecret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (algorithm.equalsIgnoreCase("DES")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            // DES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return new DESKey(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        } else if (algorithm.equalsIgnoreCase("DESede")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                   || algorithm.equalsIgnoreCase("TripleDES")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            // Triple DES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return new DESedeKey(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } else if (algorithm.equalsIgnoreCase("Blowfish")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            // Blowfish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            int keysize = secret.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (keysize >= BlowfishConstants.BLOWFISH_MAX_KEYSIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                keysize = BlowfishConstants.BLOWFISH_MAX_KEYSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            SecretKeySpec skey = new SecretKeySpec(secret, 0, keysize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                                   "Blowfish");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return skey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        } else if (algorithm.equalsIgnoreCase("AES")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            // AES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            int keysize = secret.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            SecretKeySpec skey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            int idx = AESConstants.AES_KEYSIZES.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            while (skey == null && idx >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                // Generate the strongest key using the shared secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                // assuming the key sizes in AESConstants class are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                // in ascending order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                if (keysize >= AESConstants.AES_KEYSIZES[idx]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    keysize = AESConstants.AES_KEYSIZES[idx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    skey = new SecretKeySpec(secret, 0, keysize, "AES");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                idx--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (skey == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                throw new InvalidKeyException("Key material is too short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return skey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } else if (algorithm.equals("TlsPremasterSecret")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            // return entire secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return new SecretKeySpec(secret, "TlsPremasterSecret");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            throw new NoSuchAlgorithmException("Unsupported secret key "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                               + "algorithm: "+ algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
}