Home | History | Annotate | Download | only in security
      1 /*
      2  * Copyright (c) 1998, 2013, 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
     23  * questions.
     24  */
     25 
     26 package java.security;
     27 
     28 /**
     29  * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
     30  * for the {@code SecureRandom} class.
     31  * All the abstract methods in this class must be implemented by each
     32  * service provider who wishes to supply the implementation
     33  * of a cryptographically strong pseudo-random number generator.
     34  *
     35  *
     36  * @see SecureRandom
     37  * @since 1.2
     38  */
     39 
     40 public abstract class SecureRandomSpi implements java.io.Serializable {
     41 
     42     private static final long serialVersionUID = -2991854161009191830L;
     43 
     44     /**
     45      * Reseeds this random object. The given seed supplements, rather than
     46      * replaces, the existing seed. Thus, repeated calls are guaranteed
     47      * never to reduce randomness.
     48      *
     49      * @param seed the seed.
     50      */
     51     protected abstract void engineSetSeed(byte[] seed);
     52 
     53     /**
     54      * Generates a user-specified number of random bytes.
     55      *
     56      * <p> If a call to {@code engineSetSeed} had not occurred previously,
     57      * the first call to this method forces this SecureRandom implementation
     58      * to seed itself.  This self-seeding will not occur if
     59      * {@code engineSetSeed} was previously called.
     60      *
     61      * @param bytes the array to be filled in with random bytes.
     62      */
     63     protected abstract void engineNextBytes(byte[] bytes);
     64 
     65     /**
     66      * Returns the given number of seed bytes.  This call may be used to
     67      * seed other random number generators.
     68      *
     69      * @param numBytes the number of seed bytes to generate.
     70      *
     71      * @return the seed bytes.
     72      */
     73      protected abstract byte[] engineGenerateSeed(int numBytes);
     74 }
     75