jdk/src/java.base/share/classes/java/security/SecureRandomSpi.java
author coleenp
Wed, 30 Aug 2017 19:18:22 -0400
changeset 47098 e704f55561c3
parent 45118 e4258d800b54
permissions -rw-r--r--
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp Summary: Use load_acquire for accessing DictionaryEntry::_pd_set since it's accessed outside the SystemDictionary_lock Reviewed-by: zgu, twisti, dholmes, adinn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 44369
diff changeset
     2
 * Copyright (c) 1998, 2017, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    30
 * for the {@link SecureRandom} class.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    31
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * All the abstract methods in this class must be implemented by each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * service provider who wishes to supply the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * of a cryptographically strong pseudo-random number generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    36
 * @implSpec
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    37
 * If the {@link #SecureRandomSpi(SecureRandomParameters)}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    38
 * constructor is overridden in an implementation, it will always be called
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    39
 * whenever a {@code SecureRandom} is instantiated. Precisely, if an object is
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    40
 * instantiated with one of {@code SecureRandom}'s {@code getInstance} methods
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    41
 * <em>without</em> a {@link SecureRandomParameters} parameter,
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    42
 * the constructor will be called with a {@code null} argument and the
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    43
 * implementation is responsible for creating its own
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    44
 * {@code SecureRandomParameters} parameter for use when
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    45
 * {@link #engineGetParameters()} is called. If an object
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    46
 * is instantiated with one of {@code SecureRandom}'s {@code getInstance}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    47
 * methods <em>with</em> a {@code SecureRandomParameters} argument,
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    48
 * the constructor will be called with that argument. The
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    49
 * {@link #engineGetParameters()} method must not return {@code null}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    50
 * <p>
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    51
 * Otherwise, if the {@code SecureRandomSpi(SecureRandomParameters)}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    52
 * constructor is not overridden in an implementation, the
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    53
 * {@link #SecureRandomSpi()} constructor must be overridden and it will be
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    54
 * called if an object is instantiated with one of {@code SecureRandom}'s
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    55
 * {@code getInstance} methods <em>without</em> a
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    56
 * {@code SecureRandomParameters} argument. Calling one of
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    57
 * {@code SecureRandom}'s {@code getInstance} methods <em>with</em>
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    58
 * a {@code SecureRandomParameters} argument will never
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    59
 * return an instance of this implementation. The
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    60
 * {@link #engineGetParameters()} method must return {@code null}.
42161
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    61
 * <p>
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    62
 * See {@link SecureRandom} for additional details on thread safety. By
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    63
 * default, a {@code SecureRandomSpi} implementation is considered to be
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    64
 * not safe for use by multiple concurrent threads and {@code SecureRandom}
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    65
 * will synchronize access to each of the applicable engine methods
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    66
 * (see {@link SecureRandom} for the list of methods). However, if a
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    67
 * {@code SecureRandomSpi} implementation is thread-safe, the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 44369
diff changeset
    68
 * "{@docRoot}/../specs/security/standard-names.html#service-attributes">
42161
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    69
 * service provider attribute</a> "ThreadSafe" should be set to "true" during
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    70
 * its registration, as follows:
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    71
 * <blockquote><pre>
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    72
 * put("SecureRandom.AlgName ThreadSafe", "true");</pre>
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    73
 * </blockquote>
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    74
 * or
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    75
 * <blockquote><pre>
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    76
 * putService(new Service(this, "SecureRandom", "AlgName", className,
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    77
 *          null, Map.of("ThreadSafe", "true")));</pre>
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    78
 * </blockquote>
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    79
 * {@code SecureRandom} will call the applicable engine methods
5b0b84715c06 7004967: SecureRandom should be more explicit about threading
weijun
parents: 37796
diff changeset
    80
 * without any synchronization.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public abstract class SecureRandomSpi implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final long serialVersionUID = -2991854161009191830L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    90
     * Constructor without a parameter.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    91
     */
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    92
    public SecureRandomSpi() {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    93
        // ignored
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    94
    }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    95
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    96
    /**
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    97
     * Constructor with a parameter.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    98
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
    99
     * @param params the {@link SecureRandomParameters} object.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   100
     *               This argument can be {@code null}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   101
     * @throws IllegalArgumentException if {@code params} is
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   102
     *         unrecognizable or unsupported by this {@code SecureRandom}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   103
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   104
     * @since 9
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   105
     */
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   106
    protected SecureRandomSpi(SecureRandomParameters params) {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   107
        // ignored
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   108
    }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   109
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   110
    /**
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   111
     * Reseeds this random object with the given seed. The seed supplements,
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   112
     * rather than replaces, the existing seed. Thus, repeated calls
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   113
     * are guaranteed never to reduce randomness.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param seed the seed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected abstract void engineSetSeed(byte[] seed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Generates a user-specified number of random bytes.
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   121
     * <p>
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   122
     * Some random number generators can only generate a limited amount
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   123
     * of random bytes per invocation. If the size of {@code bytes}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   124
     * is greater than this limit, the implementation should invoke
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   125
     * its generation process multiple times to completely fill the
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   126
     * buffer before returning from this method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param bytes the array to be filled in with random bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected abstract void engineNextBytes(byte[] bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   133
     * Generates a user-specified number of random bytes with
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   134
     * additional parameters.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   135
     * <p>
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   136
     * Some random number generators can only generate a limited amount
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   137
     * of random bytes per invocation. If the size of {@code bytes}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   138
     * is greater than this limit, the implementation should invoke
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   139
     * its generation process multiple times to completely fill the
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   140
     * buffer before returning from this method.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   141
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   142
     * @implSpec The default implementation throws
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   143
     * an {@link UnsupportedOperationException}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   144
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   145
     * @param bytes the array to be filled in with random bytes
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   146
     * @param params additional parameters
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   147
     * @throws UnsupportedOperationException if the implementation
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   148
     *         has not overridden this method
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   149
     * @throws IllegalArgumentException if {@code params} is {@code null},
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   150
     *         illegal or unsupported by this {@code SecureRandom}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   151
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   152
     * @since 9
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   153
     */
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   154
    protected void engineNextBytes(
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   155
            byte[] bytes, SecureRandomParameters params) {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   156
        throw new UnsupportedOperationException();
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   157
    }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   158
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   159
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Returns the given number of seed bytes.  This call may be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * seed other random number generators.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param numBytes the number of seed bytes to generate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return the seed bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   167
    protected abstract byte[] engineGenerateSeed(int numBytes);
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   168
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   169
    /**
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   170
     * Reseeds this random object with entropy input read from its
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   171
     * entropy source with additional parameters.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   172
     * <p>
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   173
     * If this method is called by {@link SecureRandom#reseed()},
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   174
     * {@code params} will be {@code null}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   175
     * <p>
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   176
     * Do not override this method if the implementation does not
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   177
     * support reseeding.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   178
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   179
     * @implSpec The default implementation throws
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   180
     *           an {@link UnsupportedOperationException}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   181
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   182
     * @param params extra parameters, can be {@code null}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   183
     * @throws UnsupportedOperationException if the implementation
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   184
     *         has not overridden this method
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   185
     * @throws IllegalArgumentException if {@code params} is
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   186
     *         illegal or unsupported by this {@code SecureRandom}
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   187
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   188
     * @since 9
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   189
     */
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   190
    protected void engineReseed(SecureRandomParameters params) {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   191
        throw new UnsupportedOperationException();
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   192
    }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   193
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   194
    /**
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   195
     * Returns the effective {@link SecureRandomParameters} for this
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   196
     * {@code SecureRandom} instance.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   197
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   198
     * @implSpec The default implementation returns {@code null}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   199
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   200
     * @return the effective {@link SecureRandomParameters} parameters,
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   201
     * or {@code null} if no parameters were used.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   202
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   203
     * @since 9
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   204
     */
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   205
    protected SecureRandomParameters engineGetParameters() {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   206
        return null;
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   207
    }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   208
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   209
    /**
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   210
     * Returns a Human-readable string representation of this
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   211
     * {@code SecureRandom}.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   212
     *
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   213
     * @return the string representation
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   214
     */
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   215
    @Override
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   216
    public String toString() {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   217
        return getClass().getSimpleName();
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 25859
diff changeset
   218
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
}