jdk/src/java.base/share/classes/com/sun/crypto/provider/HmacCore.java
author weijun
Fri, 06 May 2016 11:38:44 +0800
changeset 37796 256c45c4af5d
parent 25859 3317bb8137f4
child 40267 5936f75b27c1
permissions -rw-r--r--
8051408: NIST SP 800-90A SecureRandom implementations Reviewed-by: wetmore, xuelei, coffeys
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
     2
 * Copyright (c) 2002, 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: 4348
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: 4348
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: 4348
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4348
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4348
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.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.crypto.MacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class constitutes the core of HMAC-<MD> algorithms, where
4348
5b1eb97d243a 6879540: enable empty password for kerberos 5
weijun
parents: 3353
diff changeset
    39
 * <MD> can be SHA1 or MD5, etc. See RFC 2104 for spec.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
    41
 * It also contains the implementation classes for SHA-224, SHA-256,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * SHA-384, and SHA-512 HMACs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
    46
abstract class HmacCore extends MacSpi implements Cloneable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
    48
    private MessageDigest md;
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
    49
    private byte[] k_ipad; // inner padding - key XORd with ipad
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
    50
    private byte[] k_opad; // outer padding - key XORd with opad
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private boolean first;       // Is this the first data to be processed?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final int blockLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Standard constructor, creates a new HmacCore instance using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * specified MessageDigest object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    HmacCore(MessageDigest md, int bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        this.md = md;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.blockLen = bl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.k_ipad = new byte[blockLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.k_opad = new byte[blockLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Standard constructor, creates a new HmacCore instance instantiating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * a MessageDigest of the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    HmacCore(String digestAlgorithm, int bl) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this(MessageDigest.getInstance(digestAlgorithm), bl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Returns the length of the HMAC in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @return the HMAC length in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
    80
    protected int engineGetMacLength() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return this.md.getDigestLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Initializes the HMAC with the given secret key and algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param key the secret key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param params the algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @exception InvalidKeyException if the given key is inappropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * initializing this MAC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @exception InvalidAlgorithmParameterException if the given algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * parameters are inappropriate for this MAC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
    95
    protected void engineInit(Key key, AlgorithmParameterSpec params)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throws InvalidKeyException, InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (params != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            throw new InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                ("HMAC does not use parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (!(key instanceof SecretKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            throw new InvalidKeyException("Secret key expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        byte[] secret = key.getEncoded();
4348
5b1eb97d243a 6879540: enable empty password for kerberos 5
weijun
parents: 3353
diff changeset
   107
        if (secret == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new InvalidKeyException("Missing key data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // if key is longer than the block length, reset it using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // the message digest object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (secret.length > blockLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            byte[] tmp = md.digest(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            // now erase the secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            Arrays.fill(secret, (byte)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            secret = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // XOR k with ipad and opad, respectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        for (int i = 0; i < blockLen; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            int si = (i < secret.length) ? secret[i] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            k_ipad[i] = (byte)(si ^ 0x36);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            k_opad[i] = (byte)(si ^ 0x5c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // now erase the secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        Arrays.fill(secret, (byte)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        secret = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   131
        engineReset();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Processes the given byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param input the input byte to be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   139
    protected void engineUpdate(byte input) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            md.update(k_ipad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // add the passed byte to the inner digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        md.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Processes the first <code>len</code> bytes in <code>input</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * starting at <code>offset</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param input the input buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param offset the offset in <code>input</code> where the input starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param len the number of bytes to process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   158
    protected void engineUpdate(byte input[], int offset, int len) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            md.update(k_ipad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // add the selected part of an array of bytes to the inner digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        md.update(input, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   169
    /**
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   170
     * Processes the <code>input.remaining()</code> bytes in the ByteBuffer
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   171
     * <code>input</code>.
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   172
     *
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   173
     * @param input the input byte buffer.
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   174
     */
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   175
    protected void engineUpdate(ByteBuffer input) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            md.update(k_ipad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        md.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Completes the HMAC computation and resets the HMAC for further use,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * maintaining the secret key that the HMAC was initialized with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the HMAC result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   191
    protected byte[] engineDoFinal() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            md.update(k_ipad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // finish the inner digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            byte[] tmp = md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            // compute digest for 2nd pass; start with outer pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            md.update(k_opad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            // add result of 1st hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            md.update(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            md.digest(tmp, 0, tmp.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (DigestException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // should never occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Resets the HMAC for further use, maintaining the secret key that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * HMAC was initialized with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   220
    protected void engineReset() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (first == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            md.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Clones this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public Object clone() throws CloneNotSupportedException {
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   231
        HmacCore copy = (HmacCore) super.clone();
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   232
        copy.md = (MessageDigest) md.clone();
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   233
        copy.k_ipad = k_ipad.clone();
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   234
        copy.k_opad = k_opad.clone();
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   235
        return copy;
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   236
    }
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   237
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   238
    // nested static class for the HmacSHA224 implementation
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   239
    public static final class HmacSHA224 extends HmacCore {
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   240
        public HmacSHA224() throws NoSuchAlgorithmException {
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   241
            super("SHA-224", 64);
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   242
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    // nested static class for the HmacSHA256 implementation
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   246
    public static final class HmacSHA256 extends HmacCore {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        public HmacSHA256() throws NoSuchAlgorithmException {
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   248
            super("SHA-256", 64);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    // nested static class for the HmacSHA384 implementation
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   253
    public static final class HmacSHA384 extends HmacCore {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        public HmacSHA384() throws NoSuchAlgorithmException {
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   255
            super("SHA-384", 128);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    // nested static class for the HmacSHA512 implementation
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   260
    public static final class HmacSHA512 extends HmacCore {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        public HmacSHA512() throws NoSuchAlgorithmException {
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   262
            super("SHA-512", 128);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   265
    public static final class HmacSHA512_224 extends HmacCore {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   266
        public HmacSHA512_224() throws NoSuchAlgorithmException {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   267
            super("SHA-512/224", 128);
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   268
        }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   269
    }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   270
    public static final class HmacSHA512_256 extends HmacCore {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   271
        public HmacSHA512_256() throws NoSuchAlgorithmException {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   272
            super("SHA-512/256", 128);
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   273
        }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   274
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}