本文整理汇总了Java中org.bouncycastle.crypto.util.Pack.littleEndianToInt方法的典型用法代码示例。如果您正苦于以下问题:Java Pack.littleEndianToInt方法的具体用法?Java Pack.littleEndianToInt怎么用?Java Pack.littleEndianToInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.util.Pack
的用法示例。
在下文中一共展示了Pack.littleEndianToInt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MFcrypt
import org.bouncycastle.crypto.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);
}
}
示例2: setKey
import org.bouncycastle.crypto.util.Pack; //导入方法依赖的package包/类
protected void setKey(byte[] keyBytes, byte[] ivBytes)
{
if ((keyBytes.length != 16) && (keyBytes.length != 32)) {
throw new IllegalArgumentException(getAlgorithmName() + " requires 128 bit or 256 bit key");
}
int offset = 0;
byte[] constants;
// 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);
if (keyBytes.length == 32)
{
constants = sigma;
offset = 16;
}
else
{
constants = tau;
}
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);
resetCounter();
}
示例3: setKey
import org.bouncycastle.crypto.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.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);
// Counter reset
resetCounter();
}
示例4: setKey
import org.bouncycastle.crypto.util.Pack; //导入方法依赖的package包/类
private void setKey(final byte[] key, final byte[] nonce)
{
if (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;
// Compute encrypted nonce
final byte[] cipherKey = new byte[BLOCK_SIZE];
System.arraycopy(key, 0, cipherKey, 0, cipherKey.length);
cipher.init(true, new KeyParameter(cipherKey));
cipher.processBlock(nonce, 0, cipherKey, 0);
k0 = Pack.littleEndianToInt(cipherKey, 0);
k1 = Pack.littleEndianToInt(cipherKey, 4);
k2 = Pack.littleEndianToInt(cipherKey, 8);
k3 = Pack.littleEndianToInt(cipherKey, 12);
}
示例5: setKey
import org.bouncycastle.crypto.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;
}
示例6: setKey
import org.bouncycastle.crypto.util.Pack; //导入方法依赖的package包/类
private void setKey(byte[] keyBytes, byte[] ivBytes)
{
workingKey = keyBytes;
workingIV = ivBytes;
index = 0;
resetCounter();
int offset = 0;
byte[] constants;
// Key
engineState[1] = Pack.littleEndianToInt(workingKey, 0);
engineState[2] = Pack.littleEndianToInt(workingKey, 4);
engineState[3] = Pack.littleEndianToInt(workingKey, 8);
engineState[4] = Pack.littleEndianToInt(workingKey, 12);
if (workingKey.length == 32)
{
constants = sigma;
offset = 16;
}
else
{
constants = tau;
}
engineState[11] = Pack.littleEndianToInt(workingKey, offset);
engineState[12] = Pack.littleEndianToInt(workingKey, offset+4);
engineState[13] = Pack.littleEndianToInt(workingKey, offset+8);
engineState[14] = Pack.littleEndianToInt(workingKey, 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(workingIV, 0);
engineState[7] = Pack.littleEndianToInt(workingIV, 4);
engineState[8] = engineState[9] = 0;
initialised = true;
}
示例7: setKey
import org.bouncycastle.crypto.util.Pack; //导入方法依赖的package包/类
protected void setKey(byte[] keyBytes, byte[] ivBytes)
{
if ((keyBytes.length != 16) && (keyBytes.length != 32))
{
throw new IllegalArgumentException(getAlgorithmName() + " requires 128 bit or 256 bit key");
}
int offset = 0;
byte[] constants;
// 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);
if (keyBytes.length == 32)
{
constants = sigma;
offset = 16;
} else
{
constants = tau;
}
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);
// Counter
engineState[12] = engineState[13] = 0;
// IV
engineState[14] = Pack.littleEndianToInt(ivBytes, 0);
engineState[15] = Pack.littleEndianToInt(ivBytes, 4);
}
示例8: processBlock
import org.bouncycastle.crypto.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;
}