/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* SecureRandom implementation class. Some tokens support only
* C_GenerateRandom() and not C_SeedRandom(). In order not to lose an
* application specified seed, we create a SHA1PRNG that we mix with in that
* case.
*
* Note that since SecureRandom is thread safe, we only need one
* instance per PKCS#11 token instance. It is created on demand and cached
* in the SunPKCS11 class.
*
* Also note that we obtain the PKCS#11 session on demand, no need to tie one
* up.
*
* @author Andreas Sterbenz
* @since 1.5
*/
// token instance
// PRNG for mixing, non-null if active (i.e. setSeed() has been called)
// buffer, if mixing is used
private byte[] mixBuffer;
// bytes remaining in mixBuffer, if mixing is used
private int buffered;
/*
* we buffer data internally for efficiency but limit the lifetime
* to avoid using stale bits.
*/
// lifetime in ms, currently 100 ms (0.1 s)
// size of the internal buffer
// internal buffer for the random bits
// number of bytes remain in iBuffer
// time that data was read into iBuffer
}
// see JCA spec
throw new NullPointerException("seed must not be null");
}
try {
} catch (PKCS11Exception e) {
// cannot set seed
// let a SHA1PRNG use that seed instead
} else {
try {
mixBuffer = new byte[20];
// initialize object before assigning to class field
} catch (NoSuchAlgorithmException ee) {
throw new ProviderException(ee);
}
}
} finally {
}
}
// see JCA spec
return;
}
int ofs = 0;
synchronized (iBuffer) {
// refill the internal buffer if empty or stale
if ((ibuffered == 0) ||
}
// copy the buffered bytes into 'bytes'
}
}
}
} else {
// avoid using the buffer - just fill bytes directly
}
}
// see JCA spec
byte[] b = new byte[numBytes];
engineNextBytes(b);
return b;
}
private void mix(byte[] b) {
// avoid mixing if setSeed() has never been called
return;
}
synchronized (this) {
int ofs = 0;
while (len-- > 0) {
if (buffered == 0) {
}
buffered--;
}
}
}
// fill up the specified buffer with random bytes, and mix them
try {
} catch (PKCS11Exception e) {
throw new ProviderException("nextBytes() failed", e);
} finally {
}
}
throws IOException, ClassNotFoundException {
// assign default values to non-null transient fields
iBuffer = new byte[IBUFFER_SIZE];
ibuffered = 0;
lastRead = 0L;
}
}