本文整理汇总了Java中org.bouncycastle.util.Pack.littleEndianToInt方法的典型用法代码示例。如果您正苦于以下问题:Java Pack.littleEndianToInt方法的具体用法?Java Pack.littleEndianToInt怎么用?Java Pack.littleEndianToInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.Pack
的用法示例。
在下文中一共展示了Pack.littleEndianToInt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setKey
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
/**
* XSalsa20 key generation: process 256 bit input key and 128 bits of the input nonce
* using a core Salsa20 function without input addition to produce 256 bit working key
* and use that with the remaining 64 bits of nonce to initialize a standard Salsa20 engine state.
*/
protected void setKey(byte[] keyBytes, byte[] ivBytes)
{
if (keyBytes == null)
{
throw new IllegalArgumentException(getAlgorithmName() + " doesn't support re-init with null key");
}
if (keyBytes.length != 32)
{
throw new IllegalArgumentException(getAlgorithmName() + " requires a 256 bit key");
}
// Set key for HSalsa20
super.setKey(keyBytes, ivBytes);
// Pack next 64 bits of IV into engine state instead of counter
engineState[8] = Pack.littleEndianToInt(ivBytes, 8);
engineState[9] = Pack.littleEndianToInt(ivBytes, 12);
// Process engine state to generate Salsa20 key
int[] hsalsa20Out = new int[engineState.length];
salsaCore(20, engineState, hsalsa20Out);
// Set new key, removing addition in last round of salsaCore
engineState[1] = hsalsa20Out[0] - engineState[0];
engineState[2] = hsalsa20Out[5] - engineState[5];
engineState[3] = hsalsa20Out[10] - engineState[10];
engineState[4] = hsalsa20Out[15] - engineState[15];
engineState[11] = hsalsa20Out[6] - engineState[6];
engineState[12] = hsalsa20Out[7] - engineState[7];
engineState[13] = hsalsa20Out[8] - engineState[8];
engineState[14] = hsalsa20Out[9] - engineState[9];
// Last 64 bits of input IV
engineState[6] = Pack.littleEndianToInt(ivBytes, 16);
engineState[7] = Pack.littleEndianToInt(ivBytes, 20);
}
示例2: unpackBlock
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
private void unpackBlock(byte[] bytes, int off)
{
this.C0 = Pack.littleEndianToInt(bytes, off);
this.C1 = Pack.littleEndianToInt(bytes, off + 4);
this.C2 = Pack.littleEndianToInt(bytes, off + 8);
this.C3 = Pack.littleEndianToInt(bytes, off + 12);
}
示例3: MFcrypt
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
private static byte[] MFcrypt(byte[] P, byte[] S, int N, int r, int p, int dkLen)
{
int MFLenBytes = r * 128;
byte[] bytes = SingleIterationPBKDF2(P, S, p * MFLenBytes);
int[] B = null;
try
{
int BLen = bytes.length >>> 2;
B = new int[BLen];
Pack.littleEndianToInt(bytes, 0, B);
int MFLenWords = MFLenBytes >>> 2;
for (int BOff = 0; BOff < BLen; BOff += MFLenWords)
{
// TODO These can be done in parallel threads
SMix(B, BOff, N, r);
}
Pack.intToLittleEndian(B, bytes, 0);
return SingleIterationPBKDF2(P, bytes, dkLen);
}
finally
{
Clear(bytes);
Clear(B);
}
}
示例4: setKey
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
private void setKey(byte[] keyBytes)
{
workingKey = keyBytes;
if (engineState == null)
{
engineState = new int[stateArraySize];
}
if (results == null)
{
results = new int[stateArraySize];
}
int i, j, k;
// Reset state
for (i = 0; i < stateArraySize; i++)
{
engineState[i] = results[i] = 0;
}
a = b = c = 0;
// Reset index counter for output
index = 0;
// Convert the key bytes to ints and put them into results[] for initialization
byte[] t = new byte[keyBytes.length + (keyBytes.length & 3)];
System.arraycopy(keyBytes, 0, t, 0, keyBytes.length);
for (i = 0; i < t.length; i+=4)
{
results[i >>> 2] = Pack.littleEndianToInt(t, i);
}
// It has begun?
int[] abcdefgh = new int[sizeL];
for (i = 0; i < sizeL; i++)
{
abcdefgh[i] = 0x9e3779b9; // Phi (golden ratio)
}
for (i = 0; i < 4; i++)
{
mix(abcdefgh);
}
for (i = 0; i < 2; i++)
{
for (j = 0; j < stateArraySize; j+=sizeL)
{
for (k = 0; k < sizeL; k++)
{
abcdefgh[k] += (i<1) ? results[j+k] : engineState[j+k];
}
mix(abcdefgh);
for (k = 0; k < sizeL; k++)
{
engineState[j+k] = abcdefgh[k];
}
}
}
isaac();
initialised = true;
}
示例5: encryptBlock
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
/**
* Encrypt one block of plaintext.
*
* @param input the array containing the input data.
* @param inOff offset into the in array the data starts at.
* @param output the array the output data will be copied into.
* @param outOff the offset into the out array the output will start at.
*/
protected void encryptBlock(
byte[] input,
int inOff,
byte[] output,
int outOff)
{
X0 = Pack.littleEndianToInt(input, inOff);
X1 = Pack.littleEndianToInt(input, inOff + 4);
X2 = Pack.littleEndianToInt(input, inOff + 8);
X3 = Pack.littleEndianToInt(input, inOff + 12);
sb0(wKey[0] ^ X0, wKey[1] ^ X1, wKey[2] ^ X2, wKey[3] ^ X3); LT();
sb1(wKey[4] ^ X0, wKey[5] ^ X1, wKey[6] ^ X2, wKey[7] ^ X3); LT();
sb2(wKey[8] ^ X0, wKey[9] ^ X1, wKey[10] ^ X2, wKey[11] ^ X3); LT();
sb3(wKey[12] ^ X0, wKey[13] ^ X1, wKey[14] ^ X2, wKey[15] ^ X3); LT();
sb4(wKey[16] ^ X0, wKey[17] ^ X1, wKey[18] ^ X2, wKey[19] ^ X3); LT();
sb5(wKey[20] ^ X0, wKey[21] ^ X1, wKey[22] ^ X2, wKey[23] ^ X3); LT();
sb6(wKey[24] ^ X0, wKey[25] ^ X1, wKey[26] ^ X2, wKey[27] ^ X3); LT();
sb7(wKey[28] ^ X0, wKey[29] ^ X1, wKey[30] ^ X2, wKey[31] ^ X3); LT();
sb0(wKey[32] ^ X0, wKey[33] ^ X1, wKey[34] ^ X2, wKey[35] ^ X3); LT();
sb1(wKey[36] ^ X0, wKey[37] ^ X1, wKey[38] ^ X2, wKey[39] ^ X3); LT();
sb2(wKey[40] ^ X0, wKey[41] ^ X1, wKey[42] ^ X2, wKey[43] ^ X3); LT();
sb3(wKey[44] ^ X0, wKey[45] ^ X1, wKey[46] ^ X2, wKey[47] ^ X3); LT();
sb4(wKey[48] ^ X0, wKey[49] ^ X1, wKey[50] ^ X2, wKey[51] ^ X3); LT();
sb5(wKey[52] ^ X0, wKey[53] ^ X1, wKey[54] ^ X2, wKey[55] ^ X3); LT();
sb6(wKey[56] ^ X0, wKey[57] ^ X1, wKey[58] ^ X2, wKey[59] ^ X3); LT();
sb7(wKey[60] ^ X0, wKey[61] ^ X1, wKey[62] ^ X2, wKey[63] ^ X3); LT();
sb0(wKey[64] ^ X0, wKey[65] ^ X1, wKey[66] ^ X2, wKey[67] ^ X3); LT();
sb1(wKey[68] ^ X0, wKey[69] ^ X1, wKey[70] ^ X2, wKey[71] ^ X3); LT();
sb2(wKey[72] ^ X0, wKey[73] ^ X1, wKey[74] ^ X2, wKey[75] ^ X3); LT();
sb3(wKey[76] ^ X0, wKey[77] ^ X1, wKey[78] ^ X2, wKey[79] ^ X3); LT();
sb4(wKey[80] ^ X0, wKey[81] ^ X1, wKey[82] ^ X2, wKey[83] ^ X3); LT();
sb5(wKey[84] ^ X0, wKey[85] ^ X1, wKey[86] ^ X2, wKey[87] ^ X3); LT();
sb6(wKey[88] ^ X0, wKey[89] ^ X1, wKey[90] ^ X2, wKey[91] ^ X3); LT();
sb7(wKey[92] ^ X0, wKey[93] ^ X1, wKey[94] ^ X2, wKey[95] ^ X3); LT();
sb0(wKey[96] ^ X0, wKey[97] ^ X1, wKey[98] ^ X2, wKey[99] ^ X3); LT();
sb1(wKey[100] ^ X0, wKey[101] ^ X1, wKey[102] ^ X2, wKey[103] ^ X3); LT();
sb2(wKey[104] ^ X0, wKey[105] ^ X1, wKey[106] ^ X2, wKey[107] ^ X3); LT();
sb3(wKey[108] ^ X0, wKey[109] ^ X1, wKey[110] ^ X2, wKey[111] ^ X3); LT();
sb4(wKey[112] ^ X0, wKey[113] ^ X1, wKey[114] ^ X2, wKey[115] ^ X3); LT();
sb5(wKey[116] ^ X0, wKey[117] ^ X1, wKey[118] ^ X2, wKey[119] ^ X3); LT();
sb6(wKey[120] ^ X0, wKey[121] ^ X1, wKey[122] ^ X2, wKey[123] ^ X3); LT();
sb7(wKey[124] ^ X0, wKey[125] ^ X1, wKey[126] ^ X2, wKey[127] ^ X3);
Pack.intToLittleEndian(wKey[128] ^ X0, output, outOff);
Pack.intToLittleEndian(wKey[129] ^ X1, output, outOff + 4);
Pack.intToLittleEndian(wKey[130] ^ X2, output, outOff + 8);
Pack.intToLittleEndian(wKey[131] ^ X3, output, outOff + 12);
}
示例6: setKey
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
protected void setKey(byte[] keyBytes, byte[] ivBytes)
{
if (keyBytes != null)
{
if ((keyBytes.length != 16) && (keyBytes.length != 32))
{
throw new IllegalArgumentException(getAlgorithmName() + " requires 128 bit or 256 bit key");
}
// Key
engineState[1] = Pack.littleEndianToInt(keyBytes, 0);
engineState[2] = Pack.littleEndianToInt(keyBytes, 4);
engineState[3] = Pack.littleEndianToInt(keyBytes, 8);
engineState[4] = Pack.littleEndianToInt(keyBytes, 12);
byte[] constants;
int offset;
if (keyBytes.length == 32)
{
constants = sigma;
offset = 16;
}
else
{
constants = tau;
offset = 0;
}
engineState[11] = Pack.littleEndianToInt(keyBytes, offset);
engineState[12] = Pack.littleEndianToInt(keyBytes, offset + 4);
engineState[13] = Pack.littleEndianToInt(keyBytes, offset + 8);
engineState[14] = Pack.littleEndianToInt(keyBytes, offset + 12);
engineState[0 ] = Pack.littleEndianToInt(constants, 0);
engineState[5 ] = Pack.littleEndianToInt(constants, 4);
engineState[10] = Pack.littleEndianToInt(constants, 8);
engineState[15] = Pack.littleEndianToInt(constants, 12);
}
// IV
engineState[6] = Pack.littleEndianToInt(ivBytes, 0);
engineState[7] = Pack.littleEndianToInt(ivBytes, 4);
}
示例7: setKey
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
protected void setKey(byte[] keyBytes, byte[] ivBytes)
{
if (keyBytes != null)
{
if ((keyBytes.length != 16) && (keyBytes.length != 32))
{
throw new IllegalArgumentException(getAlgorithmName() + " requires 128 bit or 256 bit key");
}
// Key
engineState[4] = Pack.littleEndianToInt(keyBytes, 0);
engineState[5] = Pack.littleEndianToInt(keyBytes, 4);
engineState[6] = Pack.littleEndianToInt(keyBytes, 8);
engineState[7] = Pack.littleEndianToInt(keyBytes, 12);
byte[] constants;
int offset;
if (keyBytes.length == 32)
{
constants = sigma;
offset = 16;
}
else
{
constants = tau;
offset = 0;
}
engineState[8] = Pack.littleEndianToInt(keyBytes, offset);
engineState[9] = Pack.littleEndianToInt(keyBytes, offset + 4);
engineState[10] = Pack.littleEndianToInt(keyBytes, offset + 8);
engineState[11] = Pack.littleEndianToInt(keyBytes, offset + 12);
engineState[0] = Pack.littleEndianToInt(constants, 0);
engineState[1] = Pack.littleEndianToInt(constants, 4);
engineState[2] = Pack.littleEndianToInt(constants, 8);
engineState[3] = Pack.littleEndianToInt(constants, 12);
}
// IV
engineState[14] = Pack.littleEndianToInt(ivBytes, 0);
engineState[15] = Pack.littleEndianToInt(ivBytes, 4);
}
示例8: setKey
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
private void setKey(final byte[] key, final byte[] nonce)
{
if (cipher != null && (nonce == null || nonce.length != BLOCK_SIZE))
{
throw new IllegalArgumentException("Poly1305 requires a 128 bit IV.");
}
Poly1305KeyGenerator.checkKey(key);
// Extract r portion of key
int t0 = Pack.littleEndianToInt(key, BLOCK_SIZE + 0);
int t1 = Pack.littleEndianToInt(key, BLOCK_SIZE + 4);
int t2 = Pack.littleEndianToInt(key, BLOCK_SIZE + 8);
int t3 = Pack.littleEndianToInt(key, BLOCK_SIZE + 12);
r0 = t0 & 0x3ffffff; t0 >>>= 26; t0 |= t1 << 6;
r1 = t0 & 0x3ffff03; t1 >>>= 20; t1 |= t2 << 12;
r2 = t1 & 0x3ffc0ff; t2 >>>= 14; t2 |= t3 << 18;
r3 = t2 & 0x3f03fff; t3 >>>= 8;
r4 = t3 & 0x00fffff;
// Precompute multipliers
s1 = r1 * 5;
s2 = r2 * 5;
s3 = r3 * 5;
s4 = r4 * 5;
final byte[] kBytes;
if (cipher == null)
{
kBytes = key;
}
else
{
// Compute encrypted nonce
kBytes = new byte[BLOCK_SIZE];
cipher.init(true, new KeyParameter(key, 0, BLOCK_SIZE));
cipher.processBlock(nonce, 0, kBytes, 0);
}
k0 = Pack.littleEndianToInt(kBytes, 0);
k1 = Pack.littleEndianToInt(kBytes, 4);
k2 = Pack.littleEndianToInt(kBytes, 8);
k3 = Pack.littleEndianToInt(kBytes, 12);
}
示例9: processBlock
import org.bouncycastle.util.Pack; //导入方法依赖的package包/类
private void processBlock()
{
if (currentBlockOffset < BLOCK_SIZE)
{
currentBlock[currentBlockOffset] = 1;
for (int i = currentBlockOffset + 1; i < BLOCK_SIZE; i++)
{
currentBlock[i] = 0;
}
}
final long t0 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 0);
final long t1 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 4);
final long t2 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 8);
final long t3 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 12);
h0 += t0 & 0x3ffffff;
h1 += (((t1 << 32) | t0) >>> 26) & 0x3ffffff;
h2 += (((t2 << 32) | t1) >>> 20) & 0x3ffffff;
h3 += (((t3 << 32) | t2) >>> 14) & 0x3ffffff;
h4 += (t3 >>> 8);
if (currentBlockOffset == BLOCK_SIZE)
{
h4 += (1 << 24);
}
long tp0 = mul32x32_64(h0,r0) + mul32x32_64(h1,s4) + mul32x32_64(h2,s3) + mul32x32_64(h3,s2) + mul32x32_64(h4,s1);
long tp1 = mul32x32_64(h0,r1) + mul32x32_64(h1,r0) + mul32x32_64(h2,s4) + mul32x32_64(h3,s3) + mul32x32_64(h4,s2);
long tp2 = mul32x32_64(h0,r2) + mul32x32_64(h1,r1) + mul32x32_64(h2,r0) + mul32x32_64(h3,s4) + mul32x32_64(h4,s3);
long tp3 = mul32x32_64(h0,r3) + mul32x32_64(h1,r2) + mul32x32_64(h2,r1) + mul32x32_64(h3,r0) + mul32x32_64(h4,s4);
long tp4 = mul32x32_64(h0,r4) + mul32x32_64(h1,r3) + mul32x32_64(h2,r2) + mul32x32_64(h3,r1) + mul32x32_64(h4,r0);
long b;
h0 = (int)tp0 & 0x3ffffff; b = (tp0 >>> 26);
tp1 += b; h1 = (int)tp1 & 0x3ffffff; b = ((tp1 >>> 26) & 0xffffffff);
tp2 += b; h2 = (int)tp2 & 0x3ffffff; b = ((tp2 >>> 26) & 0xffffffff);
tp3 += b; h3 = (int)tp3 & 0x3ffffff; b = (tp3 >>> 26);
tp4 += b; h4 = (int)tp4 & 0x3ffffff; b = (tp4 >>> 26);
h0 += b * 5;
}