java.security.DigestException Java Examples

The following examples show how to use java.security.DigestException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApkVerityBuilder.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the fsverity root hash for integrity measurement.  This needs to be consistent to
 * what kernel returns.
 */
static byte[] generateFsverityRootHash(RandomAccessFile apk, ByteBuffer apkDigest,
        SignatureInfo signatureInfo)
        throws NoSuchAlgorithmException, DigestException, IOException {
    ByteBuffer verityBlock = ByteBuffer.allocate(CHUNK_SIZE_BYTES)
            .order(ByteOrder.LITTLE_ENDIAN);
    ByteBuffer header = slice(verityBlock, 0, FSVERITY_HEADER_SIZE_BYTES);
    ByteBuffer extensions = slice(verityBlock, FSVERITY_HEADER_SIZE_BYTES,
            CHUNK_SIZE_BYTES - FSVERITY_HEADER_SIZE_BYTES);

    calculateFsveritySignatureInternal(apk, signatureInfo, null, null, header, extensions);

    MessageDigest md = MessageDigest.getInstance(JCA_DIGEST_ALGORITHM);
    md.update(header);
    md.update(extensions);
    md.update(apkDigest);
    return md.digest();
}
 
Example #2
Source File: EthHash.java    From besu with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates a dataset item and writes it to a given buffer.
 *
 * @param buffer Buffer to store dataset item in
 * @param cache EthHash Cache
 * @param index Index of the dataset item to calculate
 */
public static void calcDatasetItem(final byte[] buffer, final int[] cache, final int index) {
  final int rows = cache.length / HASH_WORDS;
  final int[] mixInts = new int[HASH_BYTES / 4];
  final int offset = index % rows * HASH_WORDS;
  mixInts[0] = cache[offset] ^ index;
  System.arraycopy(cache, offset + 1, mixInts, 1, HASH_WORDS - 1);
  intToByte(buffer, mixInts);
  final MessageDigest keccak512 = KECCAK_512.get();
  keccak512.update(buffer);
  try {
    keccak512.digest(buffer, 0, HASH_BYTES);
    ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().get(mixInts);
    for (int i = 0; i < DATASET_PARENTS; ++i) {
      fnvHash(
          mixInts,
          cache,
          Integer.remainderUnsigned(fnv(index ^ i, mixInts[i % 16]), rows) * HASH_WORDS);
    }
    intToByte(buffer, mixInts);
    keccak512.update(buffer);
    keccak512.digest(buffer, 0, HASH_BYTES);
  } catch (final DigestException ex) {
    throw new IllegalStateException(ex);
  }
}
 
Example #3
Source File: crc32.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 */
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
    byte[] result = new byte[CRC32_LENGTH];
    result = int2quad(seed);
    if (len < CRC32_LENGTH) {
        throw new DigestException("partial digests not returned");
    }
    if (buf.length - offset < CRC32_LENGTH) {
        throw new DigestException("insufficient space in the output " +
                                  "buffer to store the digest");
    }
    System.arraycopy(result, 0, buf, offset, CRC32_LENGTH);
    //processBuffer(buffer, 0, bufferIndex, result, 0);
    /*if (len < CRC32_LENGTH) {
      throw new DigestException("partial digests not returned");
      }
      if (buf.length - offset < CRC32_LENGTH) {
      throw new DigestException("insufficient space in the output " +
      "buffer to store the digest");
      }
      System.arraycopy(result, 0, buf, offset, CRC32_LENGTH);      */
    init();
    return CRC32_LENGTH;
}
 
Example #4
Source File: crc32.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 */
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
    byte[] result = new byte[CRC32_LENGTH];
    result = int2quad(seed);
    if (len < CRC32_LENGTH) {
        throw new DigestException("partial digests not returned");
    }
    if (buf.length - offset < CRC32_LENGTH) {
        throw new DigestException("insufficient space in the output " +
                                  "buffer to store the digest");
    }
    System.arraycopy(result, 0, buf, offset, CRC32_LENGTH);
    //processBuffer(buffer, 0, bufferIndex, result, 0);
    /*if (len < CRC32_LENGTH) {
      throw new DigestException("partial digests not returned");
      }
      if (buf.length - offset < CRC32_LENGTH) {
      throw new DigestException("insufficient space in the output " +
      "buffer to store the digest");
      }
      System.arraycopy(result, 0, buf, offset, CRC32_LENGTH);      */
    init();
    return CRC32_LENGTH;
}
 
Example #5
Source File: SHA1Utils.java    From AlipayWechatPlatform with GNU General Public License v3.0 6 votes vote down vote up
public static String SHA1(String decrypt) throws DigestException {
    //获取信息摘要 - 参数字典排序后字符串
    try {
        //指定sha1算法
        MessageDigest digest = MessageDigest
                .getInstance("SHA-1");
        digest.update(decrypt.getBytes());
        byte messageDigest[] = digest.digest();
        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        // 字节数组转换为 十六进制 数
        for (byte aMessageDigest : messageDigest) {
            String shaHex = Integer.toHexString(aMessageDigest & 0xFF);
            if (shaHex.length() < 2) {
                hexString.append(0);
            }
            hexString.append(shaHex);
        }
        return hexString.toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new DigestException("签名错误!");
    }
}
 
Example #6
Source File: DigestBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected final int engineDigest(byte[] out, int ofs, int len)
        throws DigestException {
    if (len < digestLength) {
        throw new DigestException("Length must be at least "
            + digestLength + " for " + algorithm + "digests");
    }
    if ((ofs < 0) || (len < 0) || (ofs > out.length - len)) {
        throw new DigestException("Buffer too short to store digest");
    }
    if (bytesProcessed < 0) {
        engineReset();
    }
    implDigest(out, ofs);
    bytesProcessed = -1;
    return digestLength;
}
 
Example #7
Source File: VerityUtils.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a pair of {@code SharedMemory} and {@code Integer}. The {@code SharedMemory} contains
 * Merkle tree and fsverity headers for the given apk, in the form that can immediately be used
 * for fsverity setup. The data is aligned to the beginning of {@code SharedMemory}, and has
 * length equals to the returned {@code Integer}.
 */
private static Pair<SharedMemory, Integer> generateApkVerityIntoSharedMemory(
        String apkPath, byte[] expectedRootHash)
        throws IOException, SecurityException, DigestException, NoSuchAlgorithmException,
               SignatureNotFoundException {
    TrackedShmBufferFactory shmBufferFactory = new TrackedShmBufferFactory();
    byte[] generatedRootHash = ApkSignatureVerifier.generateApkVerity(apkPath,
            shmBufferFactory);
    // We only generate Merkle tree once here, so it's important to make sure the root hash
    // matches the signed one in the apk.
    if (!Arrays.equals(expectedRootHash, generatedRootHash)) {
        throw new SecurityException("Locally generated verity root hash does not match");
    }

    int contentSize = shmBufferFactory.getBufferLimit();
    SharedMemory shm = shmBufferFactory.releaseSharedMemory();
    if (shm == null) {
        throw new IllegalStateException("Failed to generate verity tree into shared memory");
    }
    if (!shm.setProtect(PROT_READ)) {
        throw new SecurityException("Failed to set up shared memory correctly");
    }
    return Pair.create(shm, contentSize);
}
 
Example #8
Source File: ByteBufferDataSource.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void feedIntoDataDigester(DataDigester md, long offset, int size)
        throws IOException, DigestException {
    // There's no way to tell MessageDigest to read data from ByteBuffer from a position
    // other than the buffer's current position. We thus need to change the buffer's
    // position to match the requested offset.
    //
    // In the future, it may be necessary to compute digests of multiple regions in
    // parallel. Given that digest computation is a slow operation, we enable multiple
    // such requests to be fulfilled by this instance. This is achieved by serially
    // creating a new ByteBuffer corresponding to the requested data range and then,
    // potentially concurrently, feeding these buffers into MessageDigest instances.
    ByteBuffer region;
    synchronized (mBuf) {
        mBuf.position(0);
        mBuf.limit((int) offset + size);
        mBuf.position((int) offset);
        region = mBuf.slice();
    }

    md.consume(region);
}
 
Example #9
Source File: crc32.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 */
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
    byte[] result = new byte[CRC32_LENGTH];
    result = int2quad(seed);
    if (len < CRC32_LENGTH) {
        throw new DigestException("partial digests not returned");
    }
    if (buf.length - offset < CRC32_LENGTH) {
        throw new DigestException("insufficient space in the output " +
                                  "buffer to store the digest");
    }
    System.arraycopy(result, 0, buf, offset, CRC32_LENGTH);
    //processBuffer(buffer, 0, bufferIndex, result, 0);
    /*if (len < CRC32_LENGTH) {
      throw new DigestException("partial digests not returned");
      }
      if (buf.length - offset < CRC32_LENGTH) {
      throw new DigestException("insufficient space in the output " +
      "buffer to store the digest");
      }
      System.arraycopy(result, 0, buf, offset, CRC32_LENGTH);      */
    init();
    return CRC32_LENGTH;
}
 
Example #10
Source File: DigestBase.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected final int engineDigest(byte[] out, int ofs, int len)
        throws DigestException {
    if (len < digestLength) {
        throw new DigestException("Length must be at least "
            + digestLength + " for " + algorithm + "digests");
    }
    if ((ofs < 0) || (len < 0) || (ofs > out.length - len)) {
        throw new DigestException("Buffer too short to store digest");
    }
    if (bytesProcessed < 0) {
        engineReset();
    }
    implDigest(out, ofs);
    bytesProcessed = -1;
    return digestLength;
}
 
Example #11
Source File: ApkVerityBuilder.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Consumes and digests data up to BUFFER_SIZE (may continue from the previous remaining),
 * then writes the final digest to the output buffer.  Repeat until all data are consumed.
 * If the last consumption is not enough for BUFFER_SIZE, the state will stay and future
 * consumption will continuous from there.
 */
@Override
public void consume(ByteBuffer buffer) throws DigestException {
    int offset = buffer.position();
    int remaining = buffer.remaining();
    while (remaining > 0) {
        int allowance = (int) Math.min(remaining, BUFFER_SIZE - mBytesDigestedSinceReset);
        // Optimization: set the buffer limit to avoid allocating a new ByteBuffer object.
        buffer.limit(buffer.position() + allowance);
        mMd.update(buffer);
        offset += allowance;
        remaining -= allowance;
        mBytesDigestedSinceReset += allowance;

        if (mBytesDigestedSinceReset == BUFFER_SIZE) {
            mMd.digest(mDigestBuffer, 0, mDigestBuffer.length);
            mOutput.put(mDigestBuffer);
            // After digest, MessageDigest resets automatically, so no need to reset again.
            mMd.update(mSalt);
            mBytesDigestedSinceReset = 0;
        }
    }
}
 
Example #12
Source File: TestSameValue.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {

    for (int i = 0; i < data.length / 2; i++) {
        md.update(data, i * 2, 2);
    }
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
            "ERROR" + ": digest length differs!");
    }
    return output;
}
 
Example #13
Source File: FS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
public static byte[] deriveKey(byte[] password, byte[] salt, int numIterations, int keySize, int ivSize, ProgressReporter pr) throws EncryptionEngineException, DigestException
{
    HMACSHA1KDF kdf = new HMACSHA1KDF();
    kdf.setProgressReporter(pr);
    return kdf.deriveKey(
            password,
            salt,
            numIterations,
            keySize + ivSize
    );
}
 
Example #14
Source File: TestSameValue.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {

    for (int i = 0; i < data.length / 2; i++) {
        md.update(data, i * 2, 2);
    }
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
            "ERROR" + ": digest length differs!");
    }
    return output;
}
 
Example #15
Source File: TestSameValue.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {
    md.update(ByteBuffer.wrap(data));
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
              "ERROR" + ": digest length differs!");
    }
    return output;
}
 
Example #16
Source File: SHA1MACCalculator.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] calcChecksum(byte[] buf, int offset, int count)
{
    byte[] data;
    if(isChainedIVEnabled())
    {
        byte[] iv = getChainedIV();
        data = new byte[count + 8];
        System.arraycopy(buf, offset, data, 0, count);
        for(int i=0;i<8;i++)
            data[count + i] = iv[7-i];
    }
    else
        data = Arrays.copyOfRange(buf, offset, offset + count);
    try
    {
        byte[] mac = new byte[_hmac.getDigestLength()];
        _hmac.calcHMAC(data, 0, data.length, mac);
        byte[] cut = new byte[8];
        for(int i=0; i<mac.length - 1;i++)
            cut[i % cut.length] ^= mac[i];
        if(isChainedIVEnabled())
            setChainedIV(cut.clone());
        return cut;
    }
    catch (DigestException | EncryptionEngineException e)
    {
        throw new RuntimeException(e);
    }
    finally
    {
        Arrays.fill(data, (byte)0);
    }
}
 
Example #17
Source File: TestSameValue.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {
    md.update(data);
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
            "ERROR" + ": digest length differs!");
    }
    return output;
}
 
Example #18
Source File: FS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
public FS(Path rootPath, byte[] password, ContainerOpeningProgressReporter progressReporter) throws IOException, ApplicationException
{
    super(rootPath.getFileSystem());
    setOpeningProgressReporter(progressReporter);
    _config = readConfig(rootPath);
    _rootRealPath = rootPath;
    byte[] derivedKey = null;
    try
    {
        if(_progressReporter!=null)
        {
            _progressReporter.setCurrentEncryptionAlgName(_config.getDataCodecInfo().getName());
            _progressReporter.setCurrentKDFName("SHA1");
        }
        derivedKey = deriveKey(password);
        _encryptionKey = decryptVolumeKey(derivedKey);
        _rootPath = new RootPath();
    }
    catch (DigestException e)
    {
        throw new ApplicationException("Failed deriving the key", e);
    }
    finally
    {
        if(derivedKey!=null)
            Arrays.fill(derivedKey, (byte)0);
    }
}
 
Example #19
Source File: SecureRandomStrengthener.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void reseed(final SecureRandom secureRandom) {
  this.seedBuffer.clear();
  secureRandom.nextBytes(this.seedBuffer.array());

  for (final EntropySource source : this.entropySources) {
    final ByteBuffer entropy = source.provideEntropy();
    if (entropy == null) {
      continue;
    }

    final ByteBuffer wipeBuffer = entropy.duplicate();
    this.digest.update(entropy);
    wipe(wipeBuffer);
  }

  this.digest.update(mTimeEntropySource.provideEntropy());
  this.digest.update(this.seedBuffer);
  this.seedBuffer.clear();
  // remove data from seedBuffer so it won't be retrievable

  // reuse

  try {
    this.digest.digest(this.seedBuffer.array(), 0,
      this.seedBuffer.capacity());
  } catch (final DigestException e) {
    throw new IllegalStateException(
      "DigestException should not be thrown", e);
  }
  secureRandom.setSeed(this.seedBuffer.array());

  wipe(this.seedBuffer);
}
 
Example #20
Source File: TestSameValue.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {
    md.update(ByteBuffer.wrap(data));
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
                "ERROR" + ": digest length differs!");
    }
    return output;
}
 
Example #21
Source File: DigestBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final byte[] engineDigest() {
    byte[] b = new byte[digestLength];
    try {
        engineDigest(b, 0, b.length);
    } catch (DigestException e) {
        throw (ProviderException)
            new ProviderException("Internal error").initCause(e);
    }
    return b;
}
 
Example #22
Source File: AF.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
private void diffuse(byte[] src, int srcOffset, byte[] dst, int dstOffset, int len) throws DigestException
{
	int ds = _hash.getDigestLength();
	int blocks = len/ds;
	int padding = len % ds;
	
	for(int i=0;i<blocks; i++)		
		hashBuf(src, srcOffset + ds*i, dst, dstOffset + ds*i, ds, i);
	if(padding > 0)
		hashBuf(src, srcOffset + ds*blocks, dst, dstOffset + ds*blocks, padding, blocks);		
}
 
Example #23
Source File: Shabal256.java    From burstkit4j with Apache License 2.0 5 votes vote down vote up
@Override
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
    if (len < 32)
        throw new DigestException("partial digests not returned");
    if (buf.length - offset < 32)
        throw new DigestException("insufficient space in the output buffer to store the digest");

    shabalDigest(buf, offset);

    return 32;
}
 
Example #24
Source File: ApkSigningBlockUtils.java    From Xpatch with Apache License 2.0 5 votes vote down vote up
static void computeOneMbChunkContentDigests(
        RunnablesExecutor executor,
        Set<ContentDigestAlgorithm> digestAlgorithms,
        DataSource[] contents,
        Map<ContentDigestAlgorithm, byte[]> outputContentDigests)
        throws NoSuchAlgorithmException, DigestException {
    long chunkCountLong = 0;
    for (DataSource input : contents) {
        chunkCountLong +=
                getChunkCount(input.size(), CONTENT_DIGESTED_CHUNK_MAX_SIZE_BYTES);
    }
    if (chunkCountLong > Integer.MAX_VALUE) {
        throw new DigestException("Input too long: " + chunkCountLong + " chunks");
    }
    int chunkCount = (int) chunkCountLong;

    List<ChunkDigests> chunkDigestsList = new ArrayList<>(digestAlgorithms.size());
    for (ContentDigestAlgorithm algorithms : digestAlgorithms) {
        chunkDigestsList.add(new ChunkDigests(algorithms, chunkCount));
    }

    ChunkSupplier chunkSupplier = new ChunkSupplier(contents);
    executor.execute(() -> new ChunkDigester(chunkSupplier, chunkDigestsList));

    // Compute and write out final digest for each algorithm.
    for (ChunkDigests chunkDigests : chunkDigestsList) {
        MessageDigest messageDigest = chunkDigests.createMessageDigest();
        outputContentDigests.put(
                chunkDigests.algorithm,
                messageDigest.digest(chunkDigests.concatOfDigestsOfChunks));
    }
}
 
Example #25
Source File: ApkSigningBlockUtils.java    From Xpatch with Apache License 2.0 5 votes vote down vote up
public static Map<ContentDigestAlgorithm, byte[]> computeContentDigests(
            RunnablesExecutor executor,
            Set<ContentDigestAlgorithm> digestAlgorithms,
            DataSource beforeCentralDir,
            DataSource centralDir,
            DataSource eocd) throws IOException, NoSuchAlgorithmException, DigestException {
        Map<ContentDigestAlgorithm, byte[]> contentDigests = new HashMap<>();
        // 不使用stream,以兼容android6以及一下
//        Set<ContentDigestAlgorithm> oneMbChunkBasedAlgorithm = digestAlgorithms.stream()
//                .filter(a -> a == ContentDigestAlgorithm.CHUNKED_SHA256 ||
//                             a == ContentDigestAlgorithm.CHUNKED_SHA512)
//                .collect(Collectors.toSet());

        Set<ContentDigestAlgorithm> oneMbChunkBasedAlgorithm = new HashSet<>();
        if (digestAlgorithms != null && digestAlgorithms.size() > 0) {
            for (ContentDigestAlgorithm a : digestAlgorithms) {
                if (a == ContentDigestAlgorithm.CHUNKED_SHA256 ||
                        a == ContentDigestAlgorithm.CHUNKED_SHA512) {
                    oneMbChunkBasedAlgorithm.add(a);
                }
            }
        }

        computeOneMbChunkContentDigests(
                executor,
                oneMbChunkBasedAlgorithm,
                new DataSource[] { beforeCentralDir, centralDir, eocd },
                contentDigests);

        if (digestAlgorithms.contains(ContentDigestAlgorithm.VERITY_CHUNKED_SHA256)) {
            computeApkVerityDigest(beforeCentralDir, centralDir, eocd, contentDigests);
        }
        return contentDigests;
    }
 
Example #26
Source File: MySQLPasswordEncrypter.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public static byte[] scrambleCachingSha2(byte[] password, byte[] seed) throws DigestException {
    MessageDigest md;
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException ex) {
        throw new DigestException(ex);
    }

    byte[] dig1 = new byte[CACHING_SHA2_DIGEST_LENGTH];
    byte[] dig2 = new byte[CACHING_SHA2_DIGEST_LENGTH];
    byte[] scramble1 = new byte[CACHING_SHA2_DIGEST_LENGTH];

    // SHA2(src) => digest_stage1
    md.update(password, 0, password.length);
    md.digest(dig1, 0, CACHING_SHA2_DIGEST_LENGTH);
    md.reset();

    // SHA2(digest_stage1) => digest_stage2
    md.update(dig1, 0, dig1.length);
    md.digest(dig2, 0, CACHING_SHA2_DIGEST_LENGTH);
    md.reset();

    // SHA2(digest_stage2, m_rnd) => scramble_stage1
    md.update(dig2, 0, dig1.length);
    md.update(seed, 0, seed.length);
    md.digest(scramble1, 0, CACHING_SHA2_DIGEST_LENGTH);

    // XOR(digest_stage1, scramble_stage1) => scramble
    byte[] mysqlScrambleBuff = new byte[CACHING_SHA2_DIGEST_LENGTH];
    xorString(dig1, mysqlScrambleBuff, scramble1, CACHING_SHA2_DIGEST_LENGTH);

    return mysqlScrambleBuff;
}
 
Example #27
Source File: DirectAcyclicGraphSeed.java    From besu with Apache License 2.0 5 votes vote down vote up
public static byte[] dagSeed(final long block) {
  final byte[] seed = new byte[32];
  if (Long.compareUnsigned(block, EPOCH_LENGTH) >= 0) {
    final MessageDigest keccak256 = KECCAK_256.get();
    for (int i = 0; i < Long.divideUnsigned(block, EPOCH_LENGTH); ++i) {
      keccak256.update(seed);
      try {
        keccak256.digest(seed, 0, seed.length);
      } catch (final DigestException ex) {
        throw new IllegalStateException(ex);
      }
    }
  }
  return seed;
}
 
Example #28
Source File: TestSameValue.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {
    md.update(ByteBuffer.wrap(data));
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
              "ERROR" + ": digest length differs!");
    }
    return output;
}
 
Example #29
Source File: TestSameValue.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {

    for (int i = 0; i < data.length / 2; i++) {
        md.update(data, i * 2, 2);
    }
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
            "ERROR" + ": digest length differs!");
    }
    return output;
}
 
Example #30
Source File: TestSameValue.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] updateDigest(byte[] data, MessageDigest md)
        throws DigestException {
    md.update(data);
    byte[] output = new byte[md.getDigestLength()];
    int len = md.digest(output, 0, output.length);
    if (len != output.length) {
        throw new RuntimeException(
            "ERROR" + ": digest length differs!");
    }
    return output;
}