src/java.base/share/classes/java/security/MessageDigest.java
author mullan
Wed, 13 Nov 2019 13:43:06 -0500
changeset 59059 27a266d5fb13
parent 58242 94bb65cb37d3
permissions -rw-r--r--
8214483: Remove algorithms that use MD5 or DES from security requirements Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 53018
diff changeset
     2
 * Copyright (c) 1996, 2019, 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: 4208
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: 4208
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: 4208
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4208
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4208
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 java.security;
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.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
26736
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
    33
import sun.security.util.Debug;
41471
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
    34
import sun.security.util.MessageDigestSpi2;
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
    35
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
    36
import javax.crypto.SecretKey;
26736
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This MessageDigest class provides applications the functionality of a
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    40
 * message digest algorithm, such as SHA-1 or SHA-256.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Message digests are secure one-way hash functions that take arbitrary-sized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * data and output a fixed-length hash value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>A MessageDigest object starts out initialized. The data is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * processed through it using the {@link #update(byte) update}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * methods. At any point {@link #reset() reset} can be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to reset the digest. Once all the data to be updated has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * updated, one of the {@link #digest() digest} methods should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * be called to complete the hash computation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    51
 * <p>The {@code digest} method can be called once for a given number
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    52
 * of updates. After {@code digest} has been called, the MessageDigest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * object is reset to its initialized state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>Implementations are free to implement the Cloneable interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Client applications can test cloneability by attempting cloning
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    57
 * and catching the CloneNotSupportedException:
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    58
 *
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    59
 * <pre>{@code
46053
6f7e93cb432a 8169080: Improve documentation examples for crypto applications
wetmore
parents: 45434
diff changeset
    60
 * MessageDigest md = MessageDigest.getInstance("SHA-256");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    62
 * try {
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    63
 *     md.update(toChapter1);
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    64
 *     MessageDigest tc1 = md.clone();
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    65
 *     byte[] toChapter1Digest = tc1.digest();
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    66
 *     md.update(toChapter2);
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    67
 *     ...etc.
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    68
 * } catch (CloneNotSupportedException cnse) {
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    69
 *     throw new DigestException("couldn't make digest of partial content");
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    70
 * }
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    71
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>Note that if a given implementation is not cloneable, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * still possible to compute intermediate digests by instantiating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * several instances, if the number of digests is known in advance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>Note that this class is abstract and extends from
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    78
 * {@code MessageDigestSpi} for historical reasons.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Application developers should only take notice of the methods defined in
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    80
 * this {@code MessageDigest} class; all the methods in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * the superclass are intended for cryptographic service providers who wish to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * supply their own implementations of message digest algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    84
 * <p> Every implementation of the Java platform is required to support
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    85
 * the following standard {@code MessageDigest} algorithms:
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    86
 * <ul>
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    87
 * <li>{@code SHA-1}</li>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    88
 * <li>{@code SHA-256}</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    89
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    90
 * These algorithms are described in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
    91
 * "{@docRoot}/../specs/security/standard-names.html#messagedigest-algorithms">
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    92
 * MessageDigest section</a> of the
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
    93
 * Java Security Standard Algorithm Names Specification.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    94
 * Consult the release documentation for your implementation to see if any
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    95
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    96
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @author Benjamin Renaud
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 45118
diff changeset
    98
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @see DigestInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see DigestOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
public abstract class MessageDigest extends MessageDigestSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
26736
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   106
    private static final Debug pdebug =
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   107
                        Debug.getInstance("provider", "Provider");
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   108
    private static final boolean skipDebug =
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   109
        Debug.isOn("engine=") && !Debug.isOn("messagedigest");
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   110
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // The state of this digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static final int INITIAL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static final int IN_PROGRESS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private int state = INITIAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Creates a message digest with the specified algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param algorithm the standard name of the digest algorithm.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   125
     * See the MessageDigest section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   126
     * "{@docRoot}/../specs/security/standard-names.html#messagedigest-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   127
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected MessageDigest(String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.algorithm = algorithm;
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
     * Returns a MessageDigest object that implements the specified digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * A new MessageDigest object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * MessageDigestSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31695
diff changeset
   147
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31695
diff changeset
   148
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   149
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   150
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31695
diff changeset
   151
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31695
diff changeset
   152
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31695
diff changeset
   153
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31695
diff changeset
   154
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param algorithm the name of the algorithm requested.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   156
     * See the MessageDigest section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   157
     * "{@docRoot}/../specs/security/standard-names.html#messagedigest-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   158
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   161
     * @return a {@code MessageDigest} object that implements the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   162
     *         specified algorithm
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   164
     * @throws NoSuchAlgorithmException if no {@code Provider} supports a
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   165
     *         {@code MessageDigestSpi} implementation for the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   166
     *         specified algorithm
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   167
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   168
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public static MessageDigest getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    throws NoSuchAlgorithmException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   174
        Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        try {
26736
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   176
            MessageDigest md;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            Object[] objs = Security.getImpl(algorithm, "MessageDigest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                             (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (objs[0] instanceof MessageDigest) {
26736
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   180
                md = (MessageDigest)objs[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            } else {
26736
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   182
                md = new Delegate((MessageDigestSpi)objs[0], algorithm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
26736
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   184
            md.provider = (Provider)objs[1];
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   185
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   186
            if (!skipDebug && pdebug != null) {
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   187
                pdebug.println("MessageDigest." + algorithm +
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   188
                    " algorithm from: " + md.provider.getName());
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   189
            }
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   190
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   191
            return md;
5a93000b26cd 8056026: Debug security logging should print Provider used for each crypto operation
vinnie
parents: 25859
diff changeset
   192
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        } catch(NoSuchProviderException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new NoSuchAlgorithmException(algorithm + " not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns a MessageDigest object that implements the specified digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <p> A new MessageDigest object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * MessageDigestSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param algorithm the name of the algorithm requested.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   211
     * See the MessageDigest section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   212
     * "{@docRoot}/../specs/security/standard-names.html#messagedigest-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   213
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   218
     * @return a {@code MessageDigest} object that implements the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   219
     *         specified algorithm
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   221
     * @throws IllegalArgumentException if the provider name is {@code null}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   222
     *         or empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   224
     * @throws NoSuchAlgorithmException if a {@code MessageDigestSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   225
     *         implementation for the specified algorithm is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   226
     *         available from the specified provider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   228
     * @throws NoSuchProviderException if the specified provider is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   229
     *         registered in the security provider list
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   230
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   231
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public static MessageDigest getInstance(String algorithm, String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        throws NoSuchAlgorithmException, NoSuchProviderException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   238
        Objects.requireNonNull(algorithm, "null algorithm name");
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   239
        if (provider == null || provider.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        Object[] objs = Security.getImpl(algorithm, "MessageDigest", provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (objs[0] instanceof MessageDigest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            MessageDigest md = (MessageDigest)objs[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            md.provider = (Provider)objs[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return md;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            MessageDigest delegate =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                new Delegate((MessageDigestSpi)objs[0], algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            delegate.provider = (Provider)objs[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return delegate;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Returns a MessageDigest object that implements the specified digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <p> A new MessageDigest object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * MessageDigestSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param algorithm the name of the algorithm requested.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   264
     * See the MessageDigest section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   265
     * "{@docRoot}/../specs/security/standard-names.html#messagedigest-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   266
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   271
     * @return a {@code MessageDigest} object that implements the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   272
     *         specified algorithm
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   273
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   274
     * @throws IllegalArgumentException if the specified provider is
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   275
     *         {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   277
     * @throws NoSuchAlgorithmException if a {@code MessageDigestSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   278
     *         implementation for the specified algorithm is not available
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   279
     *         from the specified {@code Provider} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   281
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public static MessageDigest getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                            Provider provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        throws NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 41471
diff changeset
   291
        Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (provider == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        Object[] objs = Security.getImpl(algorithm, "MessageDigest", provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (objs[0] instanceof MessageDigest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            MessageDigest md = (MessageDigest)objs[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            md.provider = (Provider)objs[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return md;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            MessageDigest delegate =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                new Delegate((MessageDigestSpi)objs[0], algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            delegate.provider = (Provider)objs[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return delegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Returns the provider of this message digest object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return the provider of this message digest object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Updates the digest using the specified byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param input the byte with which to update the digest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public void update(byte input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        engineUpdate(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        state = IN_PROGRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Updates the digest using the specified array of bytes, starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * at the specified offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param input the array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param offset the offset to start from in the array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param len the number of bytes to use, starting at
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   335
     * {@code offset}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public void update(byte[] input, int offset, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (input == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            throw new IllegalArgumentException("No input buffer given");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (input.length - offset < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            throw new IllegalArgumentException("Input buffer too short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        engineUpdate(input, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        state = IN_PROGRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Updates the digest using the specified array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param input the array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public void update(byte[] input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        engineUpdate(input, 0, input.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        state = IN_PROGRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Update the digest using the specified ByteBuffer. The digest is
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   360
     * updated using the {@code input.remaining()} bytes starting
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   361
     * at {@code input.position()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Upon return, the buffer's position will be equal to its limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * its limit will not have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @param input the ByteBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public final void update(ByteBuffer input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (input == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        engineUpdate(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        state = IN_PROGRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Completes the hash computation by performing final operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * such as padding. The digest is reset after this call is made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return the array of bytes for the resulting hash value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public byte[] digest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        /* Resetting is the responsibility of implementors. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        byte[] result = engineDigest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        state = INITIAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Completes the hash computation by performing final operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * such as padding. The digest is reset after this call is made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param buf output buffer for the computed digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param offset offset into the output buffer to begin storing the digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @param len number of bytes within buf allotted for the digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   399
     * @return the number of bytes placed into {@code buf}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 53018
diff changeset
   401
     * @throws    DigestException if an error occurs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public int digest(byte[] buf, int offset, int len) throws DigestException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (buf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            throw new IllegalArgumentException("No output buffer given");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (buf.length - offset < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                ("Output buffer too small for specified offset and length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        int numBytes = engineDigest(buf, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        state = INITIAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return numBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Performs a final update on the digest using the specified array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * of bytes, then completes the digest computation. That is, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * method first calls {@link #update(byte[]) update(input)},
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   420
     * passing the <i>input</i> array to the {@code update} method,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * then calls {@link #digest() digest()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @param input the input to be updated before the digest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @return the array of bytes for the resulting hash value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public byte[] digest(byte[] input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
42780
7781326fff20 8170876: NPE in JCE engine classes with java.security.debug=provider
mullan
parents: 41826
diff changeset
   433
    private String getProviderName() {
7781326fff20 8170876: NPE in JCE engine classes with java.security.debug=provider
mullan
parents: 41826
diff changeset
   434
        return (provider == null) ? "(no provider)" : provider.getName();
7781326fff20 8170876: NPE in JCE engine classes with java.security.debug=provider
mullan
parents: 41826
diff changeset
   435
    }
7781326fff20 8170876: NPE in JCE engine classes with java.security.debug=provider
mullan
parents: 41826
diff changeset
   436
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Returns a string representation of this message digest object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        PrintStream p = new PrintStream(baos);
42780
7781326fff20 8170876: NPE in JCE engine classes with java.security.debug=provider
mullan
parents: 41826
diff changeset
   443
        p.print(algorithm+" Message Digest from "+getProviderName()+", ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        case INITIAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            p.print("<initialized>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        case IN_PROGRESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            p.print("<in progress>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        p.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return (baos.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
39651
409deb371234 8136459: MessageDigest.isEqual is not a "simple byte compare"
valeriep
parents: 37348
diff changeset
   457
     * Compares two digests for equality. Two digests are equal if they have
409deb371234 8136459: MessageDigest.isEqual is not a "simple byte compare"
valeriep
parents: 37348
diff changeset
   458
     * the same length and all bytes at corresponding positions are equal.
409deb371234 8136459: MessageDigest.isEqual is not a "simple byte compare"
valeriep
parents: 37348
diff changeset
   459
     *
409deb371234 8136459: MessageDigest.isEqual is not a "simple byte compare"
valeriep
parents: 37348
diff changeset
   460
     * @implNote
409deb371234 8136459: MessageDigest.isEqual is not a "simple byte compare"
valeriep
parents: 37348
diff changeset
   461
     * If the digests are the same length, all bytes are examined to
409deb371234 8136459: MessageDigest.isEqual is not a "simple byte compare"
valeriep
parents: 37348
diff changeset
   462
     * determine equality.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @param digesta one of the digests to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @param digestb the other digest to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @return true if the digests are equal, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
4208
e14d48eee341 6863503: SECURITY: MessageDigest.isEqual introduces timing attack vulnerabilities
vinnie
parents: 2
diff changeset
   470
    public static boolean isEqual(byte[] digesta, byte[] digestb) {
31695
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 26736
diff changeset
   471
        if (digesta == digestb) return true;
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 26736
diff changeset
   472
        if (digesta == null || digestb == null) {
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 26736
diff changeset
   473
            return false;
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 26736
diff changeset
   474
        }
4208
e14d48eee341 6863503: SECURITY: MessageDigest.isEqual introduces timing attack vulnerabilities
vinnie
parents: 2
diff changeset
   475
        if (digesta.length != digestb.length) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            return false;
4208
e14d48eee341 6863503: SECURITY: MessageDigest.isEqual introduces timing attack vulnerabilities
vinnie
parents: 2
diff changeset
   477
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
4208
e14d48eee341 6863503: SECURITY: MessageDigest.isEqual introduces timing attack vulnerabilities
vinnie
parents: 2
diff changeset
   479
        int result = 0;
e14d48eee341 6863503: SECURITY: MessageDigest.isEqual introduces timing attack vulnerabilities
vinnie
parents: 2
diff changeset
   480
        // time-constant comparison
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        for (int i = 0; i < digesta.length; i++) {
4208
e14d48eee341 6863503: SECURITY: MessageDigest.isEqual introduces timing attack vulnerabilities
vinnie
parents: 2
diff changeset
   482
            result |= digesta[i] ^ digestb[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
4208
e14d48eee341 6863503: SECURITY: MessageDigest.isEqual introduces timing attack vulnerabilities
vinnie
parents: 2
diff changeset
   484
        return result == 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Resets the digest for further use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        engineReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        state = INITIAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Returns a string that identifies the algorithm, independent of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * implementation details. The name should be a standard
46053
6f7e93cb432a 8169080: Improve documentation examples for crypto applications
wetmore
parents: 45434
diff changeset
   498
     * Java Security name (such as "SHA-256").
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   499
     * See the MessageDigest section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   500
     * "{@docRoot}/../specs/security/standard-names.html#messagedigest-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42780
diff changeset
   501
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @return the name of the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Returns the length of the digest in bytes, or 0 if this operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * not supported by the provider and the implementation is not cloneable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @return the digest length in bytes, or 0 if this operation is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * supported by the provider and the implementation is not cloneable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public final int getDigestLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        int digestLen = engineGetDigestLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (digestLen == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                MessageDigest md = (MessageDigest)clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                byte[] digest = md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                return digest.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                return digestLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return digestLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Returns a clone if the implementation is cloneable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @return a clone if the implementation is cloneable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 53018
diff changeset
   538
     * @throws    CloneNotSupportedException if this is called on an
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   539
     * implementation that does not support {@code Cloneable}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public Object clone() throws CloneNotSupportedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if (this instanceof Cloneable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            throw new CloneNotSupportedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * The following class allows providers to extend from MessageDigestSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * rather than from MessageDigest. It represents a MessageDigest with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * encapsulated, provider-supplied SPI object (of type MessageDigestSpi).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * If the provider implementation is an instance of MessageDigestSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * the getInstance() methods above return an instance of this class, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * the SPI object encapsulated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * Note: All SPI methods from the original MessageDigest class have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * moved up the hierarchy into a new class (MessageDigestSpi), which has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * been interposed in the hierarchy between the API (MessageDigest)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * and its original parent (Object).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
41471
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   566
    static class Delegate extends MessageDigest implements MessageDigestSpi2 {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        // The provider implementation (delegate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        private MessageDigestSpi digestSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        public Delegate(MessageDigestSpi digestSpi, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            super(algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            this.digestSpi = digestSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
         * Returns a clone if the delegate is cloneable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         * @return a clone if the delegate is cloneable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 53018
diff changeset
   582
         * @throws    CloneNotSupportedException if this is called on a
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   583
         * delegate that does not support {@code Cloneable}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        public Object clone() throws CloneNotSupportedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            if (digestSpi instanceof Cloneable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                MessageDigestSpi digestSpiClone =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    (MessageDigestSpi)digestSpi.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                // Because 'algorithm', 'provider', and 'state' are private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                // members of our supertype, we must perform a cast to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                // access them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                MessageDigest that =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    new Delegate(digestSpiClone,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                 ((MessageDigest)this).algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                that.provider = ((MessageDigest)this).provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                that.state = ((MessageDigest)this).state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                return that;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                throw new CloneNotSupportedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        protected int engineGetDigestLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            return digestSpi.engineGetDigestLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        protected void engineUpdate(byte input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            digestSpi.engineUpdate(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        protected void engineUpdate(byte[] input, int offset, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            digestSpi.engineUpdate(input, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        protected void engineUpdate(ByteBuffer input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            digestSpi.engineUpdate(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
41471
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   619
        public void engineUpdate(SecretKey key) throws InvalidKeyException {
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   620
            if (digestSpi instanceof MessageDigestSpi2) {
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   621
                ((MessageDigestSpi2)digestSpi).engineUpdate(key);
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   622
            } else {
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   623
                throw new UnsupportedOperationException
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   624
                ("Digest does not support update of SecretKey object");
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   625
            }
18c0f074ed97 8165275: Replace the reflective call to the implUpdate method in HandshakeMessage::digestKey
valeriep
parents: 39651
diff changeset
   626
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        protected byte[] engineDigest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            return digestSpi.engineDigest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        protected int engineDigest(byte[] buf, int offset, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            throws DigestException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                return digestSpi.engineDigest(buf, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        protected void engineReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            digestSpi.engineReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
}