public final class Util extends Object
Note that the functions defined in this class are mainly designed to avoid code duplication throughout this library. So while many functions here are defined as public, they may change without further notice. Use these functions at your own risk.
References:
[1] ANSI X9.62-2005, "American National Standard for Financial Services - The Elliptic Curve Digital Signature Algorithm (ECDSA)" , ASC X9, November 2005.
[2] NIST SP800-57 - Part 1, "Recommendation for Key Management", March 2007
[3] NIST SP800-90, "Recommendation for Random Number Generators", March 2007
[4] IEEE P1363.2-2008, "IEEE Standard Specifications for Public-Key Cryptography", 2009
Modifier and Type | Method and Description |
---|---|
static BigInteger |
bytesInLEToInt(byte[] array)
Reads a byte array as unsigned 32bit LE BigInteger.
|
static BigInteger |
bytesInLEToInt(byte[] array,
int offset)
Reads a byte array as unsigned 32bit LE BigInteger.
|
static BigInteger |
bytesInLEToInt(byte[] array,
int offset,
int length)
Reads a byte array as unsigned 32bit LE BigInteger.
|
static void |
checkSecureRandom(SecureRandom random,
SecurityStrength securityStrength)
Checks whether the given PRNG is a valid NIST SP800-90 PRNG (see [3]) with
the required security strength.
|
static void |
checkSecureRandom(String randomAlgorithm,
SecurityStrength securityStrength)
Checks whether the given PRNG is a valid NIST SP800-90 PRNG (see [3]) with
the required security strength.
|
static byte[] |
intToLEBytes(BigInteger e,
int length)
Convert the given BigInteger to a byte array of the given size.
|
static byte[] |
intToOctetString(BigInteger elem,
int size)
Integer to Octet String Conversion Primitive or I2OSP as defined in IEEE
P1363 (see [4]).
|
static byte[] |
intToOctetString(byte[] elem,
int size)
Integer to Octet String Conversion Primitive or I2OSP as defined in IEEE
P1363 (see [4]).
|
static byte[] |
revertBytes(byte[] array)
Reverses the order of the elements of the given array.
|
static byte[] |
revertBytes(byte[] array,
int length)
Reverts the order of the elements of the given y-coordinate array.
|
static String[] |
splitName(String name)
Split names separated by |.
|
static BigDecimal |
sqrt(BigInteger n)
This method computes the square root of a
BigInteger . |
static String |
toString(byte[] arr)
Returns a representation of an byte array as a hex string.
|
static String |
toString(ECPoint p)
|
public static byte[] revertBytes(byte[] array)
array
- array to be reversedarray
in
reversed orderpublic static byte[] revertBytes(byte[] array, int length)
array
- the encoded point without the x-coordinate bitlength
- the length to be consideredpublic static byte[] intToLEBytes(BigInteger e, int length)
e
- the BigInteger to encodelength
- the length of the resulting byte array (trailing bits get lost)public static BigInteger bytesInLEToInt(byte[] array)
array
- the arraypublic static BigInteger bytesInLEToInt(byte[] array, int offset)
array
- the arrayoffset
- the offsetpublic static BigInteger bytesInLEToInt(byte[] array, int offset, int length)
array
- the arrayoffset
- the offsetlength
- the lengthpublic static byte[] intToOctetString(BigInteger elem, int size)
elem
- the integer to be convertedsize
- the length of the result array. if this parameter is shorter than
the required size it will be ignored.public static byte[] intToOctetString(byte[] elem, int size)
elem
- the integer to be convertedsize
- the length of the result array. If this parameter is shorter than
the required size it will be ignored.public static void checkSecureRandom(SecureRandom random, SecurityStrength securityStrength) throws IllegalArgumentException
random
- the PRNG instancesecurityStrength
- the desired security strengthIllegalArgumentException
- if the PRNG is not a NIST PRNG or if it does not have the
required security strengthpublic static void checkSecureRandom(String randomAlgorithm, SecurityStrength securityStrength) throws IllegalArgumentException
randomAlgorithm
- the PRNG algorithm namesecurityStrength
- the desired security strengthIllegalArgumentException
- if the PRNG is not a NIST PRNG or if it does not have the
required security strengthpublic static String toString(byte[] arr)
arr
- byte arrayarr
public static BigDecimal sqrt(BigInteger n)
BigInteger
.n
- the integern
Copyright © 2011–2022 Stiftung SIC. All rights reserved.