Top Description Inners Fields Constructors Methods
org.bouncycastle.util

public final Class BigIntegers

extends Object
Class Inheritance
Imports
java.math.BigInteger, java.security.SecureRandom, java.util.Map, .WeakHashMap, org.bouncycastle.math.raw.Mod, .Nat

BigInteger utilities.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
public static final BigInteger
private static final BigInteger
private static final BigInteger
public static final BigInteger
public static final BigInteger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

a byte array without a leading zero byte if present in the signed encoding.
asUnsignedByteArray
(BigInteger
the value to be converted.
value
)

Return the passed in value as an unsigned byte array.

public static byte[]

Returns:

a byte array padded to a fixed length with leading zeros.
asUnsignedByteArray
(int
the fixed length of the result
length
,
BigInteger
the value to be converted.
value
)

Return the passed in value as an unsigned byte array of the specified length, padded with leading zeros as necessary..

public static void
asUnsignedByteArray(BigInteger
the value to be converted.
value
,
byte[]
the buffer to which the value is written.
buf
,
int
the start offset in array buf at which the data is written.
off
,
int
the fixed length of data written (possibly padded with leading zeros).
len
)

Write the passed in value as unsigned bytes to the specified buffer range, padded with leading zeros as necessary.

public static byte
private static byte[]
createRandom(int bitLength, SecureRandom random)

public static BigInteger

Returns:

a positive BigInteger
createRandomBigInteger
(int
maximum bit length for the generated BigInteger.
bitLength
,
SecureRandom
a source of randomness.
random
)

Return a positive BigInteger in the range of 0 to 2**bitLength - 1.

public static BigInteger

Returns:

a random BigInteger value in the range [min,max]
createRandomInRange
(BigInteger
the least value that may be generated
min
,
BigInteger
the greatest value that may be generated
max
,
SecureRandom
the source of randomness
random
)

Return a random BigInteger not less than 'min' and not greater than 'max'

public static BigInteger

Returns:

a positive BigInteger of numBits length
createRandomPrime
(int
bit length for the generated BigInteger.
bitLength
,
int certainty, SecureRandom
a source of randomness.
random
)

Return a prime number candidate of the specified bit length.

public static BigInteger
public static BigInteger
fromUnsignedByteArray(byte[] buf, int off, int length)

public static int
public static int
public static long
public static BigInteger
public static BigInteger
public static boolean
public static boolean
public static short
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_ITERATIONSback to summary
private static final int MAX_ITERATIONS
MAX_SMALLback to summary
private static final int MAX_SMALL
ONEback to summary
public static final BigInteger ONE
SMALL_PRIMES_PRODUCTback to summary
private static final BigInteger SMALL_PRIMES_PRODUCT
THREEback to summary
private static final BigInteger THREE
TWOback to summary
public static final BigInteger TWO
ZEROback to summary
public static final BigInteger ZERO

Constructor Detail

BigIntegersback to summary
public BigIntegers()

Method Detail

asUnsignedByteArrayback to summary
public static byte[] asUnsignedByteArray(BigInteger value)

Return the passed in value as an unsigned byte array.

Parameters
value:BigInteger

the value to be converted.

Returns:byte[]

a byte array without a leading zero byte if present in the signed encoding.

asUnsignedByteArrayback to summary
public static byte[] asUnsignedByteArray(int length, BigInteger value)

Return the passed in value as an unsigned byte array of the specified length, padded with leading zeros as necessary..

Parameters
length:int

the fixed length of the result

value:BigInteger

the value to be converted.

Returns:byte[]

a byte array padded to a fixed length with leading zeros.

asUnsignedByteArrayback to summary
public static void asUnsignedByteArray(BigInteger value, byte[] buf, int off, int len)

Write the passed in value as unsigned bytes to the specified buffer range, padded with leading zeros as necessary.

Parameters
value:BigInteger

the value to be converted.

buf:byte[]

the buffer to which the value is written.

off:int

the start offset in array buf at which the data is written.

len:int

the fixed length of data written (possibly padded with leading zeros).

byteValueExactback to summary
public static byte byteValueExact(BigInteger x)
createRandomback to summary
private static byte[] createRandom(int bitLength, SecureRandom random) throws IllegalArgumentException
createRandomBigIntegerback to summary
public static BigInteger createRandomBigInteger(int bitLength, SecureRandom random)

Return a positive BigInteger in the range of 0 to 2**bitLength - 1.

Parameters
bitLength:int

maximum bit length for the generated BigInteger.

random:SecureRandom

a source of randomness.

Returns:BigInteger

a positive BigInteger

createRandomInRangeback to summary
public static BigInteger createRandomInRange(BigInteger min, BigInteger max, SecureRandom random)

Return a random BigInteger not less than 'min' and not greater than 'max'

Parameters
min:BigInteger

the least value that may be generated

max:BigInteger

the greatest value that may be generated

random:SecureRandom

the source of randomness

Returns:BigInteger

a random BigInteger value in the range [min,max]

createRandomPrimeback to summary
public static BigInteger createRandomPrime(int bitLength, int certainty, SecureRandom random)

Return a prime number candidate of the specified bit length.

Parameters
bitLength:int

bit length for the generated BigInteger.

random:SecureRandom

a source of randomness.

Returns:BigInteger

a positive BigInteger of numBits length

fromUnsignedByteArrayback to summary
public static BigInteger fromUnsignedByteArray(byte[] buf)
fromUnsignedByteArrayback to summary
public static BigInteger fromUnsignedByteArray(byte[] buf, int off, int length)
getUnsignedByteLengthback to summary
public static int getUnsignedByteLength(BigInteger n)
intValueExactback to summary
public static int intValueExact(BigInteger x)
longValueExactback to summary
public static long longValueExact(BigInteger x)
modOddInverseback to summary
public static BigInteger modOddInverse(BigInteger M, BigInteger X)
modOddInverseVarback to summary
public static BigInteger modOddInverseVar(BigInteger M, BigInteger X)
modOddIsCoprimeback to summary
public static boolean modOddIsCoprime(BigInteger M, BigInteger X)
modOddIsCoprimeVarback to summary
public static boolean modOddIsCoprimeVar(BigInteger M, BigInteger X)
shortValueExactback to summary
public static short shortValueExact(BigInteger x)
org.bouncycastle.util back to summary

public Class BigIntegers.Cache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final BigInteger[]
private int
private final Map<BigInteger, Boolean>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
add(BigInteger value)

public synchronized void
public synchronized boolean
public synchronized int
size()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

preserveback to summary
private final BigInteger[] preserve
preserveCounterback to summary
private int preserveCounter
valuesback to summary
private final Map<BigInteger, Boolean> values

Constructor Detail

Cacheback to summary
public Cache()

Method Detail

addback to summary
public synchronized void add(BigInteger value)
clearback to summary
public synchronized void clear()
containsback to summary
public synchronized boolean contains(BigInteger value)
sizeback to summary
public synchronized int size()