< prev index next >

src/java.base/unix/classes/sun/security/provider/NativePRNG.java

Print this page

  1 /*
  2  * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

186                                 " Couldn't read Files.");
187                         }
188                         return null;
189                     }
190 
191                     try {
192                         return new RandomIO(seedFile, nextFile);
193                     } catch (Exception e) {
194                         return null;
195                     }
196                 }
197         });
198     }
199 
200     // return whether the NativePRNG is available
201     static boolean isAvailable() {
202         return INSTANCE != null;
203     }
204 
205     // constructor, called by the JCA framework
206     public NativePRNG() {
207         super();
208         if (INSTANCE == null) {
209             throw new AssertionError("NativePRNG not available");
210         }



211     }
212 
213     // set the seed
214     @Override
215     protected void engineSetSeed(byte[] seed) {
216         INSTANCE.implSetSeed(seed);
217     }
218 
219     // get pseudo random bytes
220     @Override
221     protected void engineNextBytes(byte[] bytes) {
222         INSTANCE.implNextBytes(bytes);
223     }
224 
225     // get true random bytes
226     @Override
227     protected byte[] engineGenerateSeed(int numBytes) {
228         return INSTANCE.implGenerateSeed(numBytes);
229     }
230 

234      *
235      * Note that it does not respect the egd properties, since we have
236      * no way of knowing what those qualities are.
237      *
238      * This is very similar to the outer NativePRNG class, minimizing any
239      * breakage to the serialization of the existing implementation.
240      *
241      * @since   1.8
242      */
243     public static final class Blocking extends SecureRandomSpi {
244         private static final long serialVersionUID = -6396183145759983347L;
245 
246         private static final RandomIO INSTANCE = initIO(Variant.BLOCKING);
247 
248         // return whether this is available
249         static boolean isAvailable() {
250             return INSTANCE != null;
251         }
252 
253         // constructor, called by the JCA framework
254         public Blocking() {
255             super();
256             if (INSTANCE == null) {
257                 throw new AssertionError("NativePRNG$Blocking not available");
258             }



259         }
260 
261         // set the seed
262         @Override
263         protected void engineSetSeed(byte[] seed) {
264             INSTANCE.implSetSeed(seed);
265         }
266 
267         // get pseudo random bytes
268         @Override
269         protected void engineNextBytes(byte[] bytes) {
270             INSTANCE.implNextBytes(bytes);
271         }
272 
273         // get true random bytes
274         @Override
275         protected byte[] engineGenerateSeed(int numBytes) {
276             return INSTANCE.implGenerateSeed(numBytes);
277         }
278     }

283      *
284      * Note that it does not respect the egd properties, since we have
285      * no way of knowing what those qualities are.
286      *
287      * This is very similar to the outer NativePRNG class, minimizing any
288      * breakage to the serialization of the existing implementation.
289      *
290      * @since   1.8
291      */
292     public static final class NonBlocking extends SecureRandomSpi {
293         private static final long serialVersionUID = -1102062982994105487L;
294 
295         private static final RandomIO INSTANCE = initIO(Variant.NONBLOCKING);
296 
297         // return whether this is available
298         static boolean isAvailable() {
299             return INSTANCE != null;
300         }
301 
302         // constructor, called by the JCA framework
303         public NonBlocking() {
304             super();
305             if (INSTANCE == null) {
306                 throw new AssertionError(
307                     "NativePRNG$NonBlocking not available");
308             }



309         }
310 
311         // set the seed
312         @Override
313         protected void engineSetSeed(byte[] seed) {
314             INSTANCE.implSetSeed(seed);
315         }
316 
317         // get pseudo random bytes
318         @Override
319         protected void engineNextBytes(byte[] bytes) {
320             INSTANCE.implNextBytes(bytes);
321         }
322 
323         // get true random bytes
324         @Override
325         protected byte[] engineGenerateSeed(int numBytes) {
326             return INSTANCE.implGenerateSeed(numBytes);
327         }
328     }

  1 /*
  2  * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

186                                 " Couldn't read Files.");
187                         }
188                         return null;
189                     }
190 
191                     try {
192                         return new RandomIO(seedFile, nextFile);
193                     } catch (Exception e) {
194                         return null;
195                     }
196                 }
197         });
198     }
199 
200     // return whether the NativePRNG is available
201     static boolean isAvailable() {
202         return INSTANCE != null;
203     }
204 
205     // constructor, called by the JCA framework
206     public NativePRNG(SecureRandomParameters params) {

207         if (INSTANCE == null) {
208             throw new AssertionError("NativePRNG not available");
209         }
210         if (params != null) {
211             throw new IllegalArgumentException("Unsupported params: " + params.getClass());
212         }
213     }
214 
215     // set the seed
216     @Override
217     protected void engineSetSeed(byte[] seed) {
218         INSTANCE.implSetSeed(seed);
219     }
220 
221     // get pseudo random bytes
222     @Override
223     protected void engineNextBytes(byte[] bytes) {
224         INSTANCE.implNextBytes(bytes);
225     }
226 
227     // get true random bytes
228     @Override
229     protected byte[] engineGenerateSeed(int numBytes) {
230         return INSTANCE.implGenerateSeed(numBytes);
231     }
232 

236      *
237      * Note that it does not respect the egd properties, since we have
238      * no way of knowing what those qualities are.
239      *
240      * This is very similar to the outer NativePRNG class, minimizing any
241      * breakage to the serialization of the existing implementation.
242      *
243      * @since   1.8
244      */
245     public static final class Blocking extends SecureRandomSpi {
246         private static final long serialVersionUID = -6396183145759983347L;
247 
248         private static final RandomIO INSTANCE = initIO(Variant.BLOCKING);
249 
250         // return whether this is available
251         static boolean isAvailable() {
252             return INSTANCE != null;
253         }
254 
255         // constructor, called by the JCA framework
256         public Blocking(SecureRandomParameters params) {

257             if (INSTANCE == null) {
258                 throw new AssertionError("NativePRNG$Blocking not available");
259             }
260             if (params != null) {
261                 throw new IllegalArgumentException("Unsupported params: " + params.getClass());
262             }
263         }
264 
265         // set the seed
266         @Override
267         protected void engineSetSeed(byte[] seed) {
268             INSTANCE.implSetSeed(seed);
269         }
270 
271         // get pseudo random bytes
272         @Override
273         protected void engineNextBytes(byte[] bytes) {
274             INSTANCE.implNextBytes(bytes);
275         }
276 
277         // get true random bytes
278         @Override
279         protected byte[] engineGenerateSeed(int numBytes) {
280             return INSTANCE.implGenerateSeed(numBytes);
281         }
282     }

287      *
288      * Note that it does not respect the egd properties, since we have
289      * no way of knowing what those qualities are.
290      *
291      * This is very similar to the outer NativePRNG class, minimizing any
292      * breakage to the serialization of the existing implementation.
293      *
294      * @since   1.8
295      */
296     public static final class NonBlocking extends SecureRandomSpi {
297         private static final long serialVersionUID = -1102062982994105487L;
298 
299         private static final RandomIO INSTANCE = initIO(Variant.NONBLOCKING);
300 
301         // return whether this is available
302         static boolean isAvailable() {
303             return INSTANCE != null;
304         }
305 
306         // constructor, called by the JCA framework
307         public NonBlocking(SecureRandomParameters params) {

308             if (INSTANCE == null) {
309                 throw new AssertionError(
310                     "NativePRNG$NonBlocking not available");
311             }
312             if (params != null) {
313                 throw new IllegalArgumentException("Unsupported params: " + params.getClass());
314             }
315         }
316 
317         // set the seed
318         @Override
319         protected void engineSetSeed(byte[] seed) {
320             INSTANCE.implSetSeed(seed);
321         }
322 
323         // get pseudo random bytes
324         @Override
325         protected void engineNextBytes(byte[] bytes) {
326             INSTANCE.implNextBytes(bytes);
327         }
328 
329         // get true random bytes
330         @Override
331         protected byte[] engineGenerateSeed(int numBytes) {
332             return INSTANCE.implGenerateSeed(numBytes);
333         }
334     }
< prev index next >