Class Pack
- java.lang.Object
-
- org.bouncycastle.util.Pack
-
public abstract class Pack extends java.lang.ObjectUtility methods for converting byte arrays into ints and longs, and back again.
-
-
Constructor Summary
Constructors Constructor Description Pack()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intbigEndianToInt(byte[] bs, int off)static voidbigEndianToInt(byte[] bs, int off, int[] ns)static voidbigEndianToInt(byte[] bs, int off, int[] ns, int nsOff, int nsLen)static intbigEndianToInt_High(byte[] bs, int off, int len)static intbigEndianToInt_Low(byte[] bs, int off, int len)static longbigEndianToLong(byte[] bs, int off)static voidbigEndianToLong(byte[] bs, int off, long[] ns)static voidbigEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen)static longbigEndianToLong_High(byte[] bs, int off, int len)static longbigEndianToLong_Low(byte[] bs, int off, int len)Reads thelenbytes atbs[off]as a big-endian value and returns it in the lowlenbytes of the result: alenof 3 returns whatbigEndianToLong(byte[], int)would return for those three bytes preceded by five zero ones.static shortbigEndianToShort(byte[] bs, int off)static byte[]intToBigEndian(int n)static byte[]intToBigEndian(int[] ns)static voidintToBigEndian(int[] ns, byte[] bs, int off)static voidintToBigEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)static voidintToBigEndian(int n, byte[] bs)static voidintToBigEndian(int n, byte[] bs, int off)static voidintToBigEndian_High(int n, byte[] bs, int off, int len)static voidintToBigEndian_Low(int n, byte[] bs, int off, int len)static byte[]intToLittleEndian(int n)static byte[]intToLittleEndian(int[] ns)static voidintToLittleEndian(int[] ns, byte[] bs, int off)static voidintToLittleEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)static voidintToLittleEndian(int n, byte[] bs, int off)static voidintToLittleEndian_High(int n, byte[] bs, int off, int len)static voidintToLittleEndian_Low(int n, byte[] bs, int off, int len)static intlittleEndianToInt(byte[] bs, int off)static int[]littleEndianToInt(byte[] bs, int off, int count)static voidlittleEndianToInt(byte[] bs, int off, int[] ns)static voidlittleEndianToInt(byte[] bs, int bOff, int[] ns, int nOff, int count)static intlittleEndianToInt_High(byte[] bs, int off, int len)static intlittleEndianToInt_Low(byte[] bs, int off, int len)static intlittleEndianToInt24(byte[] bs, int off)static longlittleEndianToLong(byte[] bs, int off)static long[]littleEndianToLong(byte[] bs, int off, int count)static voidlittleEndianToLong(byte[] bs, int off, long[] ns)static voidlittleEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen)static longlittleEndianToLong_High(byte[] bs, int off, int len)static longlittleEndianToLong_Low(byte[] bs, int off, int len)static shortlittleEndianToShort(byte[] bs, int off)static short[]littleEndianToShort(byte[] bs, int off, int count)static voidlittleEndianToShort(byte[] bs, int bOff, short[] ns)static voidlittleEndianToShort(byte[] bs, int bOff, short[] ns, int nOff, int count)static byte[]longToBigEndian(long n)static byte[]longToBigEndian(long[] ns)static voidlongToBigEndian(long[] ns, byte[] bs, int off)static voidlongToBigEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)static voidlongToBigEndian(long n, byte[] bs, int off)static voidlongToBigEndian_High(long n, byte[] bs, int off, int len)Writes the most significantlenbytes ofntobsatoff, in big-endian order: alenof 3 writes the three byteslongToBigEndian(long, byte[], int)would put atbs[off]tobs[off + 2], and drops the other five.static voidlongToBigEndian_Low(long n, byte[] bs, int off, int len)Writes the least significantlenbytes ofntobsatoff, in big-endian order: alenof 3 writes the three byteslongToBigEndian(long, byte[], int)would put atbs[off + 5]tobs[off + 7], and drops the other five.static byte[]longToLittleEndian(long n)static byte[]longToLittleEndian(long[] ns)static voidlongToLittleEndian(long[] ns, byte[] bs, int off)static voidlongToLittleEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)static voidlongToLittleEndian(long n, byte[] bs, int off)static voidlongToLittleEndian_High(long n, byte[] bs, int off, int len)static voidlongToLittleEndian_Low(long n, byte[] bs, int off, int len)static byte[]shortToBigEndian(short n)static voidshortToBigEndian(short n, byte[] bs, int off)static byte[]shortToLittleEndian(short n)static byte[]shortToLittleEndian(short[] ns)static voidshortToLittleEndian(short[] ns, byte[] bs, int bsOff)static voidshortToLittleEndian(short[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)static voidshortToLittleEndian(short n, byte[] bs, int off)
-
-
-
Method Detail
-
bigEndianToShort
public static short bigEndianToShort(byte[] bs, int off)
-
bigEndianToInt
public static int bigEndianToInt(byte[] bs, int off)
-
bigEndianToInt
public static void bigEndianToInt(byte[] bs, int off, int[] ns)
-
bigEndianToInt
public static void bigEndianToInt(byte[] bs, int off, int[] ns, int nsOff, int nsLen)
-
bigEndianToInt_High
public static int bigEndianToInt_High(byte[] bs, int off, int len)
-
bigEndianToInt_Low
public static int bigEndianToInt_Low(byte[] bs, int off, int len)
-
intToBigEndian
public static byte[] intToBigEndian(int n)
-
intToBigEndian
public static void intToBigEndian(int n, byte[] bs)
-
intToBigEndian
public static void intToBigEndian(int n, byte[] bs, int off)
-
intToBigEndian
public static byte[] intToBigEndian(int[] ns)
-
intToBigEndian
public static void intToBigEndian(int[] ns, byte[] bs, int off)
-
intToBigEndian
public static void intToBigEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
-
intToBigEndian_High
public static void intToBigEndian_High(int n, byte[] bs, int off, int len)
-
intToBigEndian_Low
public static void intToBigEndian_Low(int n, byte[] bs, int off, int len)
-
bigEndianToLong
public static long bigEndianToLong(byte[] bs, int off)
-
bigEndianToLong
public static void bigEndianToLong(byte[] bs, int off, long[] ns)
-
bigEndianToLong
public static void bigEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen)
-
bigEndianToLong_High
public static long bigEndianToLong_High(byte[] bs, int off, int len)
-
bigEndianToLong_Low
public static long bigEndianToLong_Low(byte[] bs, int off, int len)Reads thelenbytes atbs[off]as a big-endian value and returns it in the lowlenbytes of the result: alenof 3 returns whatbigEndianToLong(byte[], int)would return for those three bytes preceded by five zero ones.It is the read side of
longToBigEndian_Low(long, byte[], int, int)and carries the same unenforced 1..8 bound, for a related reason: the first byte is read ahead of the loop, so alenof 0 reads one byte anyway and returns it rather than returning zero, and alenabove 8 goes on shifting and so yields the last eight bytes read rather than the first. The callers here are the XMSS ones reading back RFC 8391's toByte(x, y): the index field of a stored private key, inXMSSPrivateKeyCodec, which is the one codec both families' keys are decoded through, and the index field of an XMSS^MT signature inXMSSMTSignature. Each passes the constant 4 or ceil(h/8) for a height its parameter class holds to 2..62, so both are inside the bound already, as are the reads the package's own tests make with the same two lengths.
-
longToBigEndian
public static byte[] longToBigEndian(long n)
-
longToBigEndian
public static void longToBigEndian(long n, byte[] bs, int off)
-
longToBigEndian
public static byte[] longToBigEndian(long[] ns)
-
longToBigEndian
public static void longToBigEndian(long[] ns, byte[] bs, int off)
-
longToBigEndian
public static void longToBigEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
-
longToBigEndian_High
public static void longToBigEndian_High(long n, byte[] bs, int off, int len)Writes the most significantlenbytes ofntobsatoff, in big-endian order: alenof 3 writes the three byteslongToBigEndian(long, byte[], int)would put atbs[off]tobs[off + 2], and drops the other five.It is the write side of
bigEndianToLong_High(byte[], int, int). The pair is shaped for the short final block of a big-endian sponge, where the bytes the block has occupy the top of the rate word and the remainder of that word is padding - so both conversions work against the high end of the word rather than the low one. The callers are the Ascon v1.2 classes (AsconEngine,AsconDigest,AsconXof), all three now deprecated: final Ascon is little-endian and goes throughlongToLittleEndian_Low(long, byte[], int, int).lenmust be 1..8, and nothing enforces it. The first store sits ahead of the loop, so alenof 0 writes one byte anyway -n's top one - and throwsArrayIndexOutOfBoundsExceptionwhere the array has no room for it; and because Java takes a shift distance mod 64, alenabove 8 wraps round and repeatsn's bytes rather than running to zero. Callers whose length can reach 0 guard the call themselves.
-
longToBigEndian_Low
public static void longToBigEndian_Low(long n, byte[] bs, int off, int len)Writes the least significantlenbytes ofntobsatoff, in big-endian order: alenof 3 writes the three byteslongToBigEndian(long, byte[], int)would put atbs[off + 5]tobs[off + 7], and drops the other five.It is
longToBigEndian_High(long, byte[], int, int)applied tonshifted up past the bytes being dropped, the write side ofbigEndianToLong_Low(byte[], int, int), and it carries the same unenforced 1..8 bound for the same reason. It is the low-end counterpart of the _High pair the Ascon v1.2 classes use; its callers here are the XMSS ones building RFC 8391's toByte(x, y), which pads left of the eight bytes rather than absorbing into the top of a word, so it wants the low end. Two of the five pass a length that is not a constant, and both are inside the bound because they say so:XMSSUtil.toBytesBigEndian, whose size is its caller's argument, andXMSSEngine's H_msg key, whose length is the security parameter, each taking a min() with 8. The other three are inside it by construction - the index field of a stored private key inXMSSPrivateKeyCodecand of an XMSS^MT signature inXMSSMTSignature, both 4 or ceil(h/8), andWOTSPlus's PRF index at the constant 8.
-
littleEndianToShort
public static short littleEndianToShort(byte[] bs, int off)
-
littleEndianToShort
public static void littleEndianToShort(byte[] bs, int bOff, short[] ns)
-
littleEndianToShort
public static void littleEndianToShort(byte[] bs, int bOff, short[] ns, int nOff, int count)
-
littleEndianToShort
public static short[] littleEndianToShort(byte[] bs, int off, int count)
-
littleEndianToInt24
public static int littleEndianToInt24(byte[] bs, int off)
-
littleEndianToInt
public static int littleEndianToInt(byte[] bs, int off)
-
littleEndianToInt_High
public static int littleEndianToInt_High(byte[] bs, int off, int len)
-
littleEndianToInt_Low
public static int littleEndianToInt_Low(byte[] bs, int off, int len)
-
littleEndianToInt
public static void littleEndianToInt(byte[] bs, int off, int[] ns)
-
littleEndianToInt
public static void littleEndianToInt(byte[] bs, int bOff, int[] ns, int nOff, int count)
-
littleEndianToInt
public static int[] littleEndianToInt(byte[] bs, int off, int count)
-
shortToLittleEndian
public static byte[] shortToLittleEndian(short n)
-
shortToLittleEndian
public static void shortToLittleEndian(short n, byte[] bs, int off)
-
shortToLittleEndian
public static void shortToLittleEndian(short[] ns, byte[] bs, int bsOff)
-
shortToLittleEndian
public static void shortToLittleEndian(short[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
-
shortToLittleEndian
public static byte[] shortToLittleEndian(short[] ns)
-
shortToBigEndian
public static byte[] shortToBigEndian(short n)
-
shortToBigEndian
public static void shortToBigEndian(short n, byte[] bs, int off)
-
intToLittleEndian
public static byte[] intToLittleEndian(int n)
-
intToLittleEndian
public static void intToLittleEndian(int n, byte[] bs, int off)
-
intToLittleEndian
public static byte[] intToLittleEndian(int[] ns)
-
intToLittleEndian
public static void intToLittleEndian(int[] ns, byte[] bs, int off)
-
intToLittleEndian
public static void intToLittleEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
-
intToLittleEndian_High
public static void intToLittleEndian_High(int n, byte[] bs, int off, int len)
-
intToLittleEndian_Low
public static void intToLittleEndian_Low(int n, byte[] bs, int off, int len)
-
littleEndianToLong
public static long littleEndianToLong(byte[] bs, int off)
-
littleEndianToLong
public static void littleEndianToLong(byte[] bs, int off, long[] ns)
-
littleEndianToLong
public static void littleEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen)
-
littleEndianToLong
public static long[] littleEndianToLong(byte[] bs, int off, int count)
-
littleEndianToLong_High
public static long littleEndianToLong_High(byte[] bs, int off, int len)
-
littleEndianToLong_Low
public static long littleEndianToLong_Low(byte[] bs, int off, int len)
-
longToLittleEndian
public static byte[] longToLittleEndian(long n)
-
longToLittleEndian
public static void longToLittleEndian(long n, byte[] bs, int off)
-
longToLittleEndian
public static byte[] longToLittleEndian(long[] ns)
-
longToLittleEndian
public static void longToLittleEndian(long[] ns, byte[] bs, int off)
-
longToLittleEndian
public static void longToLittleEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
-
longToLittleEndian_High
public static void longToLittleEndian_High(long n, byte[] bs, int off, int len)
-
longToLittleEndian_Low
public static void longToLittleEndian_Low(long n, byte[] bs, int off, int len)
-
-