org.spongycastle.util.Arrays类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中org.spongycastle.util.Arrays类的一些代码示例,展示了Arrays类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Arrays类的具体详情如下:
包路径:org.spongycastle.util.Arrays
类名称:Arrays

Arrays介绍

[英]General array utilities.
[中]通用阵列实用程序。

代码示例

代码示例来源:origin: ethereum/ethereumj

/**
 * Pack nibbles to binary
 *
 * @param nibbles sequence. may have a terminator
 * @return hex-encoded byte array
 */
public static byte[] packNibbles(byte[] nibbles) {
  int terminator = 0;
  if (nibbles[nibbles.length - 1] == TERMINATOR) {
    terminator = 1;
    nibbles = copyOf(nibbles, nibbles.length - 1);
  }
  int oddlen = nibbles.length % 2;
  int flag = 2 * terminator + oddlen;
  if (oddlen != 0) {
    byte[] flags = new byte[]{(byte) flag};
    nibbles = concatenate(flags, nibbles);
  } else {
    byte[] flags = new byte[]{(byte) flag, 0};
    nibbles = concatenate(flags, nibbles);
  }
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  for (int i = 0; i < nibbles.length; i += 2) {
    buffer.write(16 * nibbles[i] + nibbles[i + 1]);
  }
  return buffer.toByteArray();
}

代码示例来源:origin: ethereum/ethereumj

byte[] T1 = Arrays.copyOfRange(in_enc, end - mac.getMacSize(), end);
if (!Arrays.constantTimeAreEqual(T1, T2))
return Arrays.copyOfRange(M, 0, len);

代码示例来源:origin: ethereum/ethereumj

private static BlockInfo getBlockInfoForHash(List<BlockInfo> blocks, byte[] hash){
  for (BlockInfo blockInfo : blocks)
    if (areEqual(hash, blockInfo.getHash())) return blockInfo;
  return null;
}

代码示例来源:origin: ethereum/ethereumj

public byte[] calcPowValue() {
  // nonce bytes are expected in Little Endian order, reverting
  byte[] nonceReverted = Arrays.reverse(nonce);
  byte[] hashWithoutNonce = HashUtil.sha3(getEncodedWithoutNonce());
  byte[] seed = Arrays.concatenate(hashWithoutNonce, nonceReverted);
  byte[] seedHash = HashUtil.sha512(seed);
  byte[] concat = Arrays.concatenate(seedHash, mixHash);
  return HashUtil.sha3(concat);
}

代码示例来源:origin: com.madgag.spongycastle/core

protected static byte[] derForm(byte[] data, int padBits)
{
  byte[] rv = Arrays.clone(data);
  // DER requires pad bits be zero
  if (padBits > 0)
  {
    rv[data.length - 1] &= 0xff << padBits;
  }
  return rv;
}

代码示例来源:origin: ethereum/ethereumj

public final int[] calcDatasetItem(final int[] cache, final int i) {
  final int r = params.getHASH_BYTES() / params.getWORD_BYTES();
  final int n = cache.length / r;
  int[] mix = Arrays.copyOfRange(cache, i % n * r, (i % n + 1) * r);
  mix[0] = i ^ mix[0];
  mix = sha512(mix, false);
  final int dsParents = (int) params.getDATASET_PARENTS();
  final int mixLen = mix.length;
  for (int j = 0; j < dsParents; j++) {
    int cacheIdx = fnv(i ^ j, mix[j % r]);
    cacheIdx = remainderUnsigned(cacheIdx, n);
    int off = cacheIdx * r;
    for (int k = 0; k < mixLen; k++) {
      mix[k] = fnv(mix[k], cache[off + k]);
    }
  }
  return sha512(mix, false);
}

代码示例来源:origin: ethereum/ethereumj

@Override
  public int hashCode() {
    return Arrays.hashCode(getHash());
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

private boolean checkCMSKeyChecksum(
    byte[] key,
    byte[] checksum)
  {
    return Arrays.constantTimeAreEqual(calculateCMSKeyChecksum(key), checksum);
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
 * Overwrite the key
 * if it is no longer used (zeroization)
 */
public void clearKey()
{
  if (key != null)
  {
    Arrays.fill(key, (byte)0);
    Arrays.fill(buffer, (byte)0);
  }
}

代码示例来源:origin: com.madgag.spongycastle/prov

protected byte[] engineGenerateSecret()
  throws IllegalStateException
{
  byte[] rv = Arrays.clone(shared);
  Arrays.fill(shared, (byte)0);
  return rv;
}

代码示例来源:origin: com.madgag.spongycastle/prov

public static ECField convertField(FiniteField field)
{
  if (ECAlgorithms.isFpField(field))
  {
    return new ECFieldFp(field.getCharacteristic());
  }
  else //if (ECAlgorithms.isF2mField(curveField))
  {
    Polynomial poly = ((PolynomialExtensionField)field).getMinimalPolynomial();
    int[] exponents = poly.getExponentsPresent();
    int[] ks = Arrays.reverse(Arrays.copyOfRange(exponents, 1, exponents.length - 1));
    return new ECFieldF2m(poly.getDegree(), ks);
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

protected byte[] truncate(byte[] bs)
  {
    if (bs.length <= macLength)
    {
      return bs;
    }

    return Arrays.copyOf(bs, macLength);
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
 * Return the current state of the initialisation vector.
 *
 * @return current IV
 */
public byte[] getCurrentIV()
{
  return Arrays.clone(cfbV);
}

代码示例来源:origin: ethereum/ethereumj

this.V = Arrays.copyOfRange(in, inOff, inOff + encLength);

代码示例来源:origin: com.madgag.spongycastle/core

public int hashCode()
  {
    return Arrays.hashCode(exponents);
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
 * For details see http://www.w3.org/TR/xmlenc-core/#sec-CMSKeyChecksum
 *
 * @param key key to be validated.
 * @param checksum the checksum.
 * @return true if okay, false otherwise.
 */
private boolean checkCMSKeyChecksum(
  byte[] key,
  byte[] checksum)
{
  return Arrays.constantTimeAreEqual(calculateCMSKeyChecksum(key), checksum);
}

代码示例来源:origin: com.madgag.spongycastle/core

public void clear()
{
  if (this.masterSecret != null)
  {
    Arrays.fill(this.masterSecret, (byte)0);
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

public BigInteger[] getKnowledgeProofForX2()
{
  return Arrays.copyOf(knowledgeProofForX2, knowledgeProofForX2.length);
}

代码示例来源:origin: com.madgag.spongycastle/core

public PopLinkWitnessV2(AlgorithmIdentifier keyGenAlgorithm, AlgorithmIdentifier macAlgorithm, byte[] witness)
{
  this.keyGenAlgorithm = keyGenAlgorithm;
  this.macAlgorithm = macAlgorithm;
  this.witness = Arrays.clone(witness);
}

代码示例来源:origin: ethereum/ethereumj

/**
 * Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTH
 */
public static byte[] encodeLength(int length, int offset) {
  if (length < SIZE_THRESHOLD) {
    byte firstByte = (byte) (length + offset);
    return new byte[]{firstByte};
  } else if (length < MAX_ITEM_LENGTH) {
    byte[] binaryLength;
    if (length > 0xFF)
      binaryLength = intToBytesNoLeadZeroes(length);
    else
      binaryLength = new byte[]{(byte) length};
    byte firstByte = (byte) (binaryLength.length + offset + SIZE_THRESHOLD - 1);
    return concatenate(new byte[]{firstByte}, binaryLength);
  } else {
    throw new RuntimeException("Input too long");
  }
}

相关文章