Path: blob/master/src/java.base/share/classes/sun/security/provider/MoreDrbgParameters.java
41159 views
/*1* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.provider;2627import java.io.IOException;28import java.io.Serializable;29import java.security.DrbgParameters;30import java.security.SecureRandomParameters;3132/**33* Exported and non-exported parameters that can be used by DRBGs.34*/35public class MoreDrbgParameters implements SecureRandomParameters, Serializable {3637@java.io.Serial38private static final long serialVersionUID = 9L;3940final transient EntropySource es;4142final String mech;43final String algorithm;44final boolean usedf;45final int strength;46final DrbgParameters.Capability capability;4748// The following 2 fields will be reassigned in readObject and49// thus cannot be final50byte[] nonce;51byte[] personalizationString;5253/**54* Creates a new {@code MoreDrbgParameters} object.55*56* @param es the {@link EntropySource} to use. If set to {@code null},57* a default entropy source will be used.58* @param mech mech name. If set to {@code null}, the one in59* securerandom.drbg.config is used. This argument is ignored60* when passing to HashDrbg/HmacDrbg/CtrDrbg.61* @param algorithm the requested algorithm to use. If set to {@code null},62* the algorithm will be decided by strength.63* @param nonce the nonce to use. If set to {@code null},64* a nonce will be assigned.65* @param usedf whether a derivation function should be used66* @param config a {@link DrbgParameters.Instantiation} object67*/68public MoreDrbgParameters(EntropySource es, String mech,69String algorithm, byte[] nonce, boolean usedf,70DrbgParameters.Instantiation config) {71this.mech = mech;72this.algorithm = algorithm;73this.es = es;74this.nonce = (nonce == null) ? null : nonce.clone();75this.usedf = usedf;7677this.strength = config.getStrength();78this.capability = config.getCapability();79this.personalizationString = config.getPersonalizationString();80}8182@Override83public String toString() {84return mech + "," + algorithm + "," + usedf + "," + strength85+ "," + capability + "," + personalizationString;86}8788@java.io.Serial89private void readObject(java.io.ObjectInputStream s)90throws IOException, ClassNotFoundException {91s.defaultReadObject();92if (nonce != null) {93nonce = nonce.clone();94}95if (personalizationString != null) {96personalizationString = personalizationString.clone();97}98if (capability == null) {99throw new IllegalArgumentException("Input data is corrupted");100}101}102}103104105