
org.apache.milagro.amcl.RAND Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of milagro-crypto-java Show documentation
Show all versions of milagro-crypto-java Show documentation
MCJL - Milagro Crypto Java Library
The newest version!
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/*
* Cryptographic strong random number generator
*
* Unguessable seed -> SHA -> PRNG internal state -> SHA -> random numbers
* Slow - but secure
*
* See ftp://ftp.rsasecurity.com/pub/pdfs/bull-1.pdf for a justification
*/
/* Marsaglia & Zaman Random number generator constants */
package org.apache.milagro.amcl;
public class RAND {
/* Cryptographically strong pseudo-random number generator */
private static final int NK=21;
private static final int NJ=6;
private static final int NV=8;
private int[] ira=new int[NK]; /* random number... */
private int rndptr; /* ...array & pointer */
private int borrow;
private int pool_ptr;
private byte[] pool=new byte[32]; /* random pool */
public RAND()
{
clean();
}
private int sbrand()
{ /* Marsaglia & Zaman random number generator */
int i,k;
long pdiff,t;
rndptr++;
if (rndptrt) borrow=1;
ira[i]=(int)(pdiff&0xffffffffL);
}
return ira[0];
}
public void sirand(int seed)
{
int i,in;
int t,m=1;
borrow=0;
rndptr=0;
ira[0]^=seed;
for (i=1;i0)
{
for (i=0;i=32) fill_pool();
return (r&0xff);
}
/* test main program */
/*
public static void main(String[] args) {
int i;
byte[] raw=new byte[100];
RAND rng=new RAND();
rng.clean();
for (i=0;i<100;i++) raw[i]=(byte)i;
rng.seed(100,raw);
for (i=0;i<1000;i++)
System.out.format("%03d ",rng.getByte());
} */
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy