jdk/src/share/classes/com/sun/crypto/provider/SslMacCore.java
author valeriep
Tue, 08 May 2012 17:57:48 -0700
changeset 12685 8a448b5b9006
parent 5506 202f599c92aa
permissions -rw-r--r--
4963723: Implement SHA-224 Summary: Add support for SHA-224, SHA224withRSA, SHA224withECDSA, HmacSHA224 and OAEPwithSHA-224AndMGF1Padding. Reviewed-by: vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
     2
 * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3353
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.crypto.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.crypto.MacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import static com.sun.crypto.provider.TlsPrfGenerator.genPad;
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 file contains the code for the SslMacMD5 and SslMacSHA1 implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The SSL 3.0 MAC is a variation of the HMAC algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Note that we don't implement Cloneable as that is not needed for SSL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
final class SslMacCore {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private final MessageDigest md;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private final byte[] pad1, pad2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
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
    private byte[] secret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Standard constructor, creates a new SslMacCore instance instantiating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * a MessageDigest of the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    SslMacCore(String digestAlgorithm, byte[] pad1, byte[] pad2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        md = MessageDigest.getInstance(digestAlgorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.pad1 = pad1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.pad2 = pad2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Returns the length of the Mac in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @return the Mac length in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    int getDigestLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return md.getDigestLength();
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
     * Initializes the Mac with the given secret key and algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param key the secret key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param params the algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @exception InvalidKeyException if the given key is inappropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * initializing this MAC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @exception InvalidAlgorithmParameterException if the given algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * parameters are inappropriate for this MAC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    void init(Key key, AlgorithmParameterSpec params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throws InvalidKeyException, InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (params != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                ("SslMac does not use parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (!(key instanceof SecretKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new InvalidKeyException("Secret key expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        secret = key.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (secret == null || secret.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new InvalidKeyException("Missing key data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Processes the given byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param input the input byte to be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    void update(byte input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            md.update(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            md.update(pad1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // add the passed byte to the inner digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        md.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Processes the first <code>len</code> bytes in <code>input</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * starting at <code>offset</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param input the input buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param offset the offset in <code>input</code> where the input starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param len the number of bytes to process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    void update(byte input[], int offset, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            md.update(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            md.update(pad1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // add the selected part of an array of bytes to the inner digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        md.update(input, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    void update(ByteBuffer input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            md.update(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            md.update(pad1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        md.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Completes the Mac computation and resets the Mac for further use,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * maintaining the secret key that the Mac was initialized with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return the Mac result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    byte[] doFinal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (first == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            // compute digest for 1st pass; start with inner pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            md.update(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            md.update(pad1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            // finish the inner digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            byte[] tmp = md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // compute digest for 2nd pass; start with outer pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            md.update(secret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            md.update(pad2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // add result of 1st hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            md.update(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            md.digest(tmp, 0, tmp.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } catch (DigestException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            // should never occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Resets the Mac for further use, maintaining the secret key that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Mac was initialized with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (first == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            md.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            first = true;
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
    // nested static class for the SslMacMD5 implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public static final class SslMacMD5 extends MacSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        private final SslMacCore core;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        public SslMacMD5() throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            core = new SslMacCore("MD5", md5Pad1, md5Pad2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        protected int engineGetMacLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return core.getDigestLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        protected void engineInit(Key key, AlgorithmParameterSpec params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                throws InvalidKeyException, InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            core.init(key, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        protected void engineUpdate(byte input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            core.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        protected void engineUpdate(byte input[], int offset, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            core.update(input, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        protected void engineUpdate(ByteBuffer input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            core.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        protected byte[] engineDoFinal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return core.doFinal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        protected void engineReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            core.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        static final byte[] md5Pad1 = genPad((byte)0x36, 48);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        static final byte[] md5Pad2 = genPad((byte)0x5c, 48);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    // nested static class for the SslMacMD5 implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public static final class SslMacSHA1 extends MacSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        private final SslMacCore core;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        public SslMacSHA1() throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            core = new SslMacCore("SHA", shaPad1, shaPad2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        protected int engineGetMacLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return core.getDigestLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        protected void engineInit(Key key, AlgorithmParameterSpec params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                throws InvalidKeyException, InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            core.init(key, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        protected void engineUpdate(byte input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            core.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        protected void engineUpdate(byte input[], int offset, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            core.update(input, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        protected void engineUpdate(ByteBuffer input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            core.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        protected byte[] engineDoFinal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return core.doFinal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        protected void engineReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            core.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        static final byte[] shaPad1 = genPad((byte)0x36, 40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        static final byte[] shaPad2 = genPad((byte)0x5c, 40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
}