iaik.utils
Class CryptoUtils

java.lang.Object
  |
  +--iaik.utils.CryptoUtils

public final class CryptoUtils
extends Object

Some useful cryptography utilities.

Version:
File Revision 32

Method Summary
static int compareBlock(byte[] a, byte[] b)
          Checks two byte blocks for equality.
static int compareBlock(byte[] a, int aOff, byte[] b, int bOff, int len)
          Check the specified sub-sequences of the given byte arrays for equality.
static byte[] concatenate(byte[] a1, byte[] a2)
          Concatenate the given byte arrays.
static void copyBlock(byte[] src, byte[] dst)
          Copies one byte block to another.
static void copyBlock(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
          Copies the specified byte sequence of the given source array to the specified destination array.
static void copyBlock(int[] src, int[] dst)
          Copies one int block to another.
static void copyBlock(int[] src, int srcOff, int[] dst, int dstOff, int len)
          Copies the specified int sequence of the given source array to the specified destination array.
static void copyBlock(long[] src, int srcOff, long[] dst, int dstOff, int len)
          Copies the specified long sequence of the given source array to the specified destination array.
static void copyBlock(long[] src, long[] dst)
          Copies one long block to another.
static boolean equalsBlock(byte[] a, byte[] b)
          Checks two byte blocks for equality.
static boolean equalsBlock(byte[] a, int aOff, byte[] b, int bOff, int len)
          Check the specified sub-sequences of the given byte arrays for equality.
static int[] extGcd(int a, int b)
          Deprecated. use NumberTheory.extGcd() instead
static void fillBlock(byte[] block, byte b)
          Fills a block with a given byte.
static void fillBlock(byte[] block, int blockOff, byte b, int len)
          Fills the specified subsequence of the given byte array with the given byte.
static int gcd(int a, int b)
          Deprecated. use NumberTheory.gcd() instead
static BigInteger getStrongPrime(int x, Random random)
          Deprecated. use NumberTheory.getStrongPrime() instead
static byte[] increment(byte[] b)
          Increment the byte array by one.
static byte[] incrementExtended(byte[] number)
          This method increments the given byte array and return the result.
static void randomBlock(byte[] block)
          Fills the given byte array with random bytes.
static void randomBlock(byte[] block, int off, int len)
          Fills the specified sub-array of the given byte array with random bytes.
static byte[] resizeArray(byte[] array, int len)
          Resizes a byte array to the specified length.
static void reverseArray(byte[] array, int off, int len)
          Reverses the order of the bytes in the given array.
static void spreadIntsToBytes(int[] inInts, int inOff, byte[] outBytes, int outOff, int intLen)
          Spreads ints into bytes.
static void spreadIntsToBytesLE(int[] inInts, int inOff, byte[] outBytes, int outOff, int intLen)
          Spreads ints into bytes in little endian bytes ordering.
static void spreadShortsToBytesBE(int[] inShorts, int inOff, byte[] outBytes, int outOff, int shortLen)
          Spreads shorts into bytes in big-endian.
static void spreadShortsToBytesLE(int[] inShorts, int inOff, byte[] outBytes, int outOff, int shortLen)
          Spreads shorts into bytes in little-endian.
static void squashBytesToInts(byte[] inBytes, int inOff, int[] outInts, int outOff, int intLen)
          Squashes bytes down to ints.
static void squashBytesToIntsLE(byte[] inBytes, int inOff, int[] outInts, int outOff, int intLen)
          Squashes bytes down to ints assuming little endian byte ordering.
static int squashBytesToIntsLEPadZero(byte[] inBytes, int inOff, int[] outInts, int outOff, int byteLen)
           
static void squashBytesToIntsPadZero(byte[] inBytes, int inOff, int[] outInts, int outOff, int byteLen)
           
static void squashBytesToShortsBE(byte[] inBytes, int inOff, int[] outShorts, int outOff, int shortLen)
          Squashes bytes down to shorts in big-endian.
static void squashBytesToShortsLE(byte[] inBytes, int inOff, int[] outShorts, int outOff, int shortLen)
          Squashes bytes down to shorts in little-endian.
static void xorBlock(byte[] a, byte[] b, byte[] dst)
          XORs two byte blocks.
static void xorBlock(byte[] a, int aOff, byte[] b, int bOff, byte[] dst, int dstOff, int len)
          XORs the specified sub-arrays of the given byte blocks.
static void zeroBlock(byte[] block)
          Fills the given byte array with zeros.
static void zeroBlock(byte[] block, int off, int len)
          Fills the specified sub-array of the given byte array with zeros.
static void zeroBlock(int[] block)
          Fill an integer array with zeros.
static void zeroBlock(int[] block, int off, int len)
          Fill part of an integer array with zeros.
static void zeroBlock(long[] block)
          Fill a long array with zeros.
static void zeroBlock(long[] block, int off, int len)
          Fill part of a long array with zeros.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

zeroBlock

public static void zeroBlock(byte[] block,
                             int off,
                             int len)
Fills the specified sub-array of the given byte array with zeros.

Starting at the given off position, len bytes of the given array are set to zero. To, for instance, set three bytes to zero, starting at position 2, use:

 byte[] block = ...;
 CryptoUtils.zeroBlock(block, 2, 3);
 
Parameters:
block - the byte array of which some bytes have to be set to zero
off - the offset indicating the start position within the byte array; the following len bytes are set to zero
len - the number of bytes to be set to zero, starting at off

zeroBlock

public static void zeroBlock(int[] block,
                             int off,
                             int len)
Fill part of an integer array with zeros.

zeroBlock

public static void zeroBlock(long[] block,
                             int off,
                             int len)
Fill part of a long array with zeros.

zeroBlock

public static void zeroBlock(byte[] block)
Fills the given byte array with zeros.

Parameters:
block - the byte array to be filled with zeros

zeroBlock

public static void zeroBlock(int[] block)
Fill an integer array with zeros.

zeroBlock

public static void zeroBlock(long[] block)
Fill a long array with zeros.

randomBlock

public static void randomBlock(byte[] block,
                               int off,
                               int len)
Fills the specified sub-array of the given byte array with random bytes.

This method uses Math.random() for generating random numbers. Starting at the given off position, len bytes of the given array are randomly generated. To, for instance, set ten bytes at random, starting at position 2, use:

 byte[] block = new byte[20];
 CryptoUtils.randomBlock(block, 2, 10);
 
Parameters:
block - the byte array of which some bytes shall be randomly generated
off - the offset indicating the start position within the byte array; the following len bytes will be randomly generated
len - the number of bytes to be randomly generated, starting at off

randomBlock

public static void randomBlock(byte[] block)
Fills the given byte array with random bytes.

This method uses Math.random() for generating random numbers.

Parameters:
block - the byte array to be filled with random bytes

xorBlock

public static void xorBlock(byte[] a,
                            int aOff,
                            byte[] b,
                            int bOff,
                            byte[] dst,
                            int dstOff,
                            int len)
XORs the specified sub-arrays of the given byte blocks.

Beginning at aOff, len bytes of the given a array are XORed with the corresponding bytes of the b array, beginning at position bOff. The result is written to the destination byte array (dst), starting at position dstOff, e.g.:

 byte[] a = ...;
 byte[] b = ...;
 byte[] dst = new byte[8];
 CryptoUtils.xorBlock(a, 0, b, 0, dst, 0, 8);
 
Parameters:
a - the first byte array supplying bytes to be XORed
aOff - the offset indicating the start position within the first byte array; the following len bytes will be XORed with the corresponding number of bytes of the second byte array
b - the second byte array supplying bytes to be XORed
bOff - the offset indicating the start position within the second byte array; the following len bytes will be XORed with the corresponding number of bytes of the first byte array
dst - the destination byte array to which the result of the XOR operation is written
dstOff - the offset indicating the start position within the destination byte array, to which the result of the XOR operation is written
len - the number of bytes to be XORed

xorBlock

public static void xorBlock(byte[] a,
                            byte[] b,
                            byte[] dst)
XORs two byte blocks.

Every byte of the given a array is XORed with the corresponding byte of the b array. The result is written to the specified destination array, e.g.:

 byte[] a = ...;
 byte[] b = ...;
 byte[] dst = new byte[8];
 CryptoUtils.xorBlock(a, b, dst);
 
Parameters:
a - the first byte array to be XORed
b - the second byte array to be XORed
dst - the destination byte array to which the result is written

copyBlock

public static void copyBlock(byte[] src,
                             int srcOff,
                             byte[] dst,
                             int dstOff,
                             int len)
Copies the specified byte sequence of the given source array to the specified destination array.

Beginning at the specified srcOff position, len bytes of the source array are copied to the given destination array, starting at dstOff.

Parameters:
src - the source byte array
srcOff - the offset indicating the start position within the first byte array; the following len bytes will be copied to the destination array
dst - the destination array to which to copy the bytes
dstOff - the offset indicating the start position within the destination byte array, to which the bytes shall be copied
len - the number of bytes to be copied

copyBlock

public static void copyBlock(byte[] src,
                             byte[] dst)
Copies one byte block to another.
Parameters:
src - the source byte array
dst - the destination array to which to copy the bytes

copyBlock

public static void copyBlock(int[] src,
                             int srcOff,
                             int[] dst,
                             int dstOff,
                             int len)
Copies the specified int sequence of the given source array to the specified destination array.

Beginning at the specified srcOff position, len ints of the source array are copied to the given destination array, starting at dstOff.

Parameters:
src - the source int array
srcOff - the offset indicating the start position within the first int array; the following len ints will be copied to the destination array
dst - the destination array to which to copy the ints
dstOff - the offset indicating the start position within the destination int array, to which the ints shall be copied
len - the number of ints to be copied

copyBlock

public static void copyBlock(int[] src,
                             int[] dst)
Copies one int block to another.
Parameters:
src - the source int array
dst - the destination array to which to copy the ints

copyBlock

public static void copyBlock(long[] src,
                             int srcOff,
                             long[] dst,
                             int dstOff,
                             int len)
Copies the specified long sequence of the given source array to the specified destination array.

Beginning at the specified srcOff position, len longs of the source array are copied to the given destination array, starting at dstOff.

Parameters:
src - the source int array
srcOff - the offset indicating the start position within the first long array; the following len ints will be copied to the destination array
dst - the destination array to which to copy the longs
dstOff - the offset indicating the start position within the destination long array, to which the longs shall be copied
len - the number of longs to be copied

copyBlock

public static void copyBlock(long[] src,
                             long[] dst)
Copies one long block to another.
Parameters:
src - the source int array
dst - the destination array to which to copy the ints

equalsBlock

public static boolean equalsBlock(byte[] a,
                                  int aOff,
                                  byte[] b,
                                  int bOff,
                                  int len)
Check the specified sub-sequences of the given byte arrays for equality.
Parameters:
a - the first byte array
aOff - the offset indicating the start position within the first byte array; the following len bytes are compared with the corresponding number of bytes of the second byte array
b - the second byte array
bOff - the offset indicating the start position within the second byte array; the following len bytes are compared with the corresponding number of bytes of the first byte array
len - the number of bytes to be compared
Returns:
true if the two sub-arrays have the same contents, false if not

equalsBlock

public static boolean equalsBlock(byte[] a,
                                  byte[] b)
Checks two byte blocks for equality.
Parameters:
a - the first byte array to be compared with the second byte array
b - the second byte array to be compared with the first byte array
Returns:
true if the two blocks have the same contents, false if not

compareBlock

public static int compareBlock(byte[] a,
                               int aOff,
                               byte[] b,
                               int bOff,
                               int len)
Check the specified sub-sequences of the given byte arrays for equality.
Parameters:
a - the first byte array
aOff - the offset indicating the start position within the first byte array; the following len bytes are compared with the corresponding number of bytes of the second byte array
b - the second byte array
bOff - the offset indicating the start position within the second byte array; the following len bytes are compared with the corresponding number of bytes of the first byte array
len - the number of bytes to be compared
Returns:
-1 if the two sub-arrays have the same contents, the position of the first difference otherwies

compareBlock

public static int compareBlock(byte[] a,
                               byte[] b)
Checks two byte blocks for equality.
Parameters:
a - the first byte array to be compared with the second byte array
b - the second byte array to be compared with the first byte array
Returns:
-1 if the two blocks have the same contents, the position of the first difference otherwise (if the two arrays differ in their length only the output of this method will be the length of the smaller array)

fillBlock

public static void fillBlock(byte[] block,
                             int blockOff,
                             byte b,
                             int len)
Fills the specified subsequence of the given byte array with the given byte.

After calling this method all bytes of the given subarray will have the same value, e.g.

 byte[] block = ...;
 CryptoUtils.fillBlock(block, 2, (byte)0xBA, 3);
 
will set block[1] ... block[3] to 0xBA.
Parameters:
block - the byte array to which the specified byte shall be written repeatedly
blockOff - the offset indicating the start position within the given byte array; the following len bytes will be set to b
b - the byte value to be written repeatedly to the specified sub array
len - the number of bytes that have to be set to b, beginning at len

fillBlock

public static void fillBlock(byte[] block,
                             byte b)
Fills a block with a given byte.

After calling this method all the bytes of the given byte array will have the same value.

Parameters:
block - the byte array that shall be filled with the given byte
b - the byte value for filling the array

squashBytesToInts

public static void squashBytesToInts(byte[] inBytes,
                                     int inOff,
                                     int[] outInts,
                                     int outOff,
                                     int intLen)
Squashes bytes down to ints.

In Java, the primitive data type byte internally is represented as 8 bit signed number, and int denotes a signed 32 bit number. This method transforms the bytes of the given inBytes array into proper int values for the specified outInts int array. The bytes are grouped in sequences each of it consisting of 4 bytes (32 bits) to compute the corresponding int values. So, if the given inBytes array will consist of n bytes (n = 4 * m; m >= 1), the following "transformation" will take place (when both inOff and outOff, indicating the start position from where to read the bytes from the inBytes array and the destination position where to write the resulting int values to the outInts array, are set to 0):

  inBytes[0...3] goes to outInts[0]
  inBytes[4...7] goes to outInts[1]
    ...
  inBytes[n-4...n-1] goes to outInts[n/4-1]
 
The last parameter value intLen denotes the number of the resulting int values. To squash, for instance, a sequence of 8 bytes, set intLen to 2 indicating that two int values will result from the transforming computations:
 byte[] in = new byte[8];
 int[] out = new int[2];
  ...
 CryptoUtils.squashBytesToInts(in, 0, out, 0, 2);
 
Parameters:
inBytes - the byte array supplying the bytes to be squashed to ints
inOff - the offset indicating the start position within the input byte array; the following 4 * intLen bytes will be squashed to ints
outInts - the int array to which the resulting int values are written, starting at position outOff
outOff - the offset indicating the start position within the destination int array, to which the resulting int values are written
intLen - the number of int values that will result from the "bytes-to-ints" transformation

squashBytesToIntsPadZero

public static void squashBytesToIntsPadZero(byte[] inBytes,
                                            int inOff,
                                            int[] outInts,
                                            int outOff,
                                            int byteLen)

squashBytesToIntsLEPadZero

public static int squashBytesToIntsLEPadZero(byte[] inBytes,
                                             int inOff,
                                             int[] outInts,
                                             int outOff,
                                             int byteLen)

spreadIntsToBytes

public static void spreadIntsToBytes(int[] inInts,
                                     int inOff,
                                     byte[] outBytes,
                                     int outOff,
                                     int intLen)
Spreads ints into bytes.

In Java, the primitive data type byte internally is represented as 8 bit signed number, and int denotes a signed 32 bit number. This method transforms the int values of the given inInts array into proper byte values for the specified outBytes array. The transforming computation will yield four bytes for each int value of the specified sequence of the input int array. So, if the given inInts array will consist of n ints, the following "transformation" will take place (when both inOff and outOff, indicating the start position from where to read the int values from the inInts array and the destination position where to write the resulting byte values to the outBytes array, are set to 0):

  inInts[0] goes to outBytes[0...3]
  inInts[1] goes to outBytes[4...7]
    ...
  inInts[n-1] goes to outInts[n*4-4...n*4-1]
 
The last parameter value intLen denotes the size of the input int array. To spread, for instance, a sequence of 2 ints, set intLen to 2:
 int[] in = new int[2];
 byte[] out = new byte[8];
  ...
 CryptoUtils.squashBytesToInts(in, 0, out, 0, 2);
 
Parameters:
inInts - the int array supplying the integers to be spread to bytes
inOff - the offset indicating the start position within the input int array; the following intLen integers will be spread to bytes
outBytes - the byte array to which the resulting byte values are written, starting at position outOff
outOff - the offset indicating the start position within the destination byte array, to which the resulting byte values are written
intLen - the number of int values that have to spread to bytes

squashBytesToIntsLE

public static void squashBytesToIntsLE(byte[] inBytes,
                                       int inOff,
                                       int[] outInts,
                                       int outOff,
                                       int intLen)
Squashes bytes down to ints assuming little endian byte ordering. That means least significant byte first, most significant byte last.
See Also:
squashBytesToInts(byte[], int, int[], int, int)

spreadIntsToBytesLE

public static void spreadIntsToBytesLE(int[] inInts,
                                       int inOff,
                                       byte[] outBytes,
                                       int outOff,
                                       int intLen)
Spreads ints into bytes in little endian bytes ordering. That means least significant byte first, most significant byte last.
See Also:
spreadIntsToBytes(int[], int, byte[], int, int)

squashBytesToShortsBE

public static void squashBytesToShortsBE(byte[] inBytes,
                                         int inOff,
                                         int[] outShorts,
                                         int outOff,
                                         int shortLen)
Squashes bytes down to shorts in big-endian.

In Java, the primitive data type byte internally is represented as 8 bit signed number, and short denotes a signed 16 bit number. This method transforms the bytes of the given inBytes array into proper short values for the specified outShorts int array. The bytes are grouped in sequences each of it consisting of 2 bytes (16 bits) to compute the corresponding short values. So, if the given inBytes array will consist of n bytes (n = 2 * m; m >= 1), the following "transformation" will take place (when both inOff and outOff, indicating the start position from where to read the bytes from the inBytes array and the destination position where to write the resulting short values to the outShorts array, are set to 0):

  inBytes[0...1] goes to outShorts[0]
  inBytes[2...3] goes to outShorts[1]
    ...
  inBytes[n-2...n-1] goes to outShorts[n/2-1]
 
The last parameter value shortLen denotes the number of the resulting short values. To squash, for instance, a sequence of 8 bytes, set shortLen to 4 indicating that four short values will result from the transforming computations (note that outShorts is decleared as an int[] array; only the 16 low bits are significant):
 byte[] in = new byte[8];
 int[] out = new int[4];
  ...
 CryptoUtils.squashBytesToShortsBE(in, 0, out, 0, 4);
 
Each single "two-byte-to-one-short" transformation is performed according to the big-endian scheme where the leftmost byte (with a lower address) is most significant, mapping inBytes[i] to the lower byte of the corresponding short value and inBytes[i+1] to the higher byte, e.g.:
 two bytes:              00000000 00000001  {00, 01}
 result in one short:   00000000 00000001  {1}
 
Parameters:
inBytes - the byte array supplying the bytes to be squashed to shorts
inOff - the offset indicating the start position within the input byte array; the following 2 * shortLen bytes will be squashed to shorts
outShorts - the int array to which the resulting short values are written, starting at position outOff
outOff - the offset indicating the start position within the destination int (short) array, to which the resulting short values are written
shortLen - the number of short values that will result from the "bytes-to-shorts" transformation

squashBytesToShortsLE

public static void squashBytesToShortsLE(byte[] inBytes,
                                         int inOff,
                                         int[] outShorts,
                                         int outOff,
                                         int shortLen)
Squashes bytes down to shorts in little-endian.

In Java, the primitive data type byte internally is represented as 8 bit signed number, and short denotes a signed 16 bit number. This method transforms the bytes of the given inBytes array into proper short values for the specified outShorts int array. The bytes are grouped in sequences each of it consisting of 2 bytes (16 bits) to compute the corresponding short values. So, if the given inBytes array will consist of n bytes (n = 2 * m; m >= 1), the following "transformation" will take place (when both inOff and outOff, indicating the start position from where to read the bytes from the inBytes array and the destination position where to write the resulting short values to the outShorts array, are set to 0):

  inBytes[0...1] goes to outShorts[0]
  inBytes[2...3] goes to outShorts[1]
    ...
  inBytes[n-2...n-1] goes to outShorts[n/2-1]
 
The last parameter value shortLen denotes the number of the resulting short values. To squash, for instance, a sequence of 8 bytes, set shortLen to 4 indicating that four short values will result from the transforming computations (note that outShorts is decleared as an int[] array; only the 16 low bits are significant):
 byte[] in = new byte[8];
 int[] out = new int[4];
  ...
 CryptoUtils.squashBytesToShortsBE(in, 0, out, 0, 4);
 
Each single "two-byte-to-one-short" transformation is performed according to the little-endian scheme where the rightmost byte (with a higher address) is most significant, mapping inBytes[i] to the higher byte of the corresponding short value and inBytes[i+1] to the lower byte, e.g.:
 two bytes:             00000000 00000001  {00, 01}
 result in one short:   00000001 00000000  {256}
 
Parameters:
inBytes - the byte array supplying the bytes to be squashed to shorts
inOff - the offset indicating the start position within the input byte array; the following 2 * shortLen bytes will be squashed to shorts
outShorts - the int array to which the resulting short values are written, starting at position outOff
outOff - the offset indicating the start position within the destination int (short) array, to which the resulting short values are written
shortLen - the number of short values that will result from the "bytes-to-shorts" transformation

spreadShortsToBytesBE

public static void spreadShortsToBytesBE(int[] inShorts,
                                         int inOff,
                                         byte[] outBytes,
                                         int outOff,
                                         int shortLen)
Spreads shorts into bytes in big-endian.

In Java, the primitive data type byte internally is represented as 8 bit signed number, and short denotes a signed 16 bit number. This method transforms the short values of the given inShorts array into proper byte values for the specified outBytes array. The transforming computation will yield two bytes for each short value of the specified sequence of the input short array. So, if the given inShorts array will consist of n shorts, the following "transformation" will take place (when both inOff and outOff, indicating the start position from where to read the short values from the inShorts array and the destination position where to write the resulting byte values to the outBytes array, are set to 0):

  inShorts[0] goes to outBytes[0...1]
  inShorts[1] goes to outBytes[2...3]
    ...
  inShorts[n-1] goes to outInts[n*2-2...n*2-1]
 
The last parameter value shortLen denotes the size of the input int (short) array. To spread, for instance, a sequence of 4 shorts, set shortLen to 4 (note that inShorts is decleared as an int[] array; only the 16 low bits are significant):
 int[] in = new int[4];
 byte[] out = new byte[8];
  ...
 CryptoUtils.squashBytesToInts(in, 0, out, 0, 4);
 
Each single "one-short-to-two-bytes" transformation is performed according to the big-endian scheme where the leftmost byte (with a lower address) is most significant, mapping the lower byte of an input short value to the corresponding outBytes[i] byte and the higher byte to outBytes[i+1], e.g.:
 one short:              00000000 00000001  {1}
 results in two bytes:   00000000 00000001  {00, 01}
 
Parameters:
inShorts - the int array supplying the shorts to be spread to bytes
inOff - the offset indicating the start position within the input int (short) array; the following shortLen shorts will be spread to bytes
outBytes - the byte array to which the resulting byte values are written, starting at position outOff
outOff - the offset indicating the start position within the destination byte array, to which the resulting byte values are written
shortLen - the number of short values that have to spread to bytes

spreadShortsToBytesLE

public static void spreadShortsToBytesLE(int[] inShorts,
                                         int inOff,
                                         byte[] outBytes,
                                         int outOff,
                                         int shortLen)
Spreads shorts into bytes in little-endian.

In Java, the primitive data type byte internally is represented as 8 bit signed number, and short denotes a signed 16 bit number. This method transforms the short values of the given inShorts array into proper byte values for the specified outBytes array. The transforming computation will yield two bytes for each short value of the specified sequence of the input short array. So, if the given inShorts array will consist of n shorts, the following "transformation" will take place (when both inOff and outOff, indicating the start position from where to read the short values from the inShorts array and the destination position where to write the resulting byte values to the outBytes array, are set to 0):

  inShorts[0] goes to outBytes[0...1]
  inShorts[1] goes to outBytes[2...3]
    ...
  inShorts[n-1] goes to outInts[n*2-2...n*2-1]
 
The last parameter value shortLen denotes the size of the input int (short) array. To spread, for instance, a sequence of 4 shorts, set shortLen to 4 (note that inShorts is decleared as an int[] array; only the 16 low bits are significant):
 int[] in = new int[4];
 byte[] out = new byte[8];
  ...
 CryptoUtils.squashBytesToInts(in, 0, out, 0, 4);
 
Each single "one-short-to-two-bytes" transformation is performed according to the little-endian scheme where the rightmost byte (with a higher address) is most significant, mapping the lower byte of an input short value to the corresponding outBytes[i] byte and the higher byte to outBytes[i-1], e.g.:
 one short:              00000001 00000000  {256}
 results in two bytes:   00000000 00000001  {00, 01}
 
Parameters:
inShorts - the int array supplying the shorts to be spread to bytes
inOff - the offset indicating the start position within the input int (short) array; the following shortLen shorts will be spread to bytes
outBytes - the byte array to which the resulting byte values are written, starting at position outOff
outOff - the offset indicating the start position within the destination byte array, to which the resulting byte values are written
shortLen - the number of short values that have to spread to bytes

resizeArray

public static byte[] resizeArray(byte[] array,
                                 int len)
Resizes a byte array to the specified length.
Parameters:
array - the array to resize
len - the new length of the array
Returns:
the resized array

reverseArray

public static void reverseArray(byte[] array,
                                int off,
                                int len)
Reverses the order of the bytes in the given array. The most significant (first) byte is swapped with the least significant (last) byte, ... .
Parameters:
array - the array to be "reversed"
off - the start offset into the array
len - the number of bytes to be involved in the reversing operation, starting at off

increment

public static byte[] increment(byte[] b)
Increment the byte array by one. Assumes MSB byte order.

incrementExtended

public static byte[] incrementExtended(byte[] number)
This method increments the given byte array and return the result. It interpretes the given byte array as a positive integer with MSB first. If the result fits into the given byte array, the result is placed there and the returned array is the same as the given. If the result does not fit into the given array, a new one is created and returned. The given array is modified even in this case. Its content is the same as the result, but it is one byte shorter; i.e. the MSB is missing because there was an overflow.
Parameters:
number - The given number to increment.
Returns:
The incremented number.

concatenate

public static byte[] concatenate(byte[] a1,
                                 byte[] a2)
Concatenate the given byte arrays. The array a1 becomes the begining and a2 the end of the result; i.e. (result[0] == a1[0]) and (result[a1.length] == a2[0]).
Parameters:
a1 - The first part.
a2 - The second part.
Returns:
The concatenation of a1 and a2.

getStrongPrime

public static BigInteger getStrongPrime(int x,
                                        Random random)
Deprecated. use NumberTheory.getStrongPrime() instead


gcd

public static int gcd(int a,
                      int b)
Deprecated. use NumberTheory.gcd() instead


extGcd

public static int[] extGcd(int a,
                           int b)
Deprecated. use NumberTheory.extGcd() instead


This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK