org.spongycastle.crypto.Digest Java Examples

The following examples show how to use org.spongycastle.crypto.Digest. 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: Cryptograph.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
private static byte[] getMultiHmac(byte[] secret, byte[] data, int bytes, Digest algorithm) {
    byte[] nuData = data;
    byte[] output = new byte[bytes];
    int size = 0;
    while (size < bytes) {
        nuData = getHmac(secret, nuData, algorithm);
        byte[] preOutput = getHmac(secret, combine(nuData, data), algorithm);
        System.arraycopy(preOutput, 0, output, size, Math.min(bytes - size, preOutput.length));
        size += preOutput.length;
    }
    return output;
}
 
Example #2
Source File: Cryptograph.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private static byte[] getMultiHmac(byte[] secret, byte[] data, int bytes, Digest algorithm) {
    byte[] nuData = data;
    byte[] output = new byte[bytes];
    int size = 0;
    while (size < bytes) {
        nuData = getHmac(secret, nuData, algorithm);
        byte[] preOutput = getHmac(secret, combine(nuData, data), algorithm);
        System.arraycopy(preOutput, 0, output, size, Math.min(bytes - size, preOutput.length));
        size += preOutput.length;
    }
    return output;
}
 
Example #3
Source File: Cryptograph.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private static byte[] getHmac(byte[] secret, byte[] data, Digest algorithm) {
    HMac hmac = new HMac(algorithm);
    hmac.init(new KeyParameter(secret));
    byte[] result = new byte[hmac.getMacSize()];
    hmac.update(data, 0, data.length);
    hmac.doFinal(result, 0);
    return result;
}
 
Example #4
Source File: HashUtil.java    From nuls with MIT License 5 votes vote down vote up
/**
 * @param data - message to hash
 * @return - reipmd160 hash of the message
 */
public static byte[] ripemd160(byte[] data) {
    Digest digest = new RIPEMD160Digest();
    if (data != null) {
        byte[] resBuf = new byte[digest.getDigestSize()];
        digest.update(data, 0, data.length);
        digest.doFinal(resBuf, 0);
        return resBuf;
    }
    throw new NullPointerException("Can't hash a NULL value");
}
 
Example #5
Source File: KeccakHash.java    From nuls with MIT License 5 votes vote down vote up
public static byte[] keccakBytes(byte[] bytes, int bitLength) {
    Digest digest = new KeccakDigest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return rsData;
}
 
Example #6
Source File: KeccakHash.java    From nuls with MIT License 5 votes vote down vote up
public static String keccak(byte[] bytes, int bitLength) {
    Digest digest = new KeccakDigest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return Hex.encode(rsData);
}
 
Example #7
Source File: Sha3Hash.java    From nuls with MIT License 5 votes vote down vote up
public static byte[] sha3bytes(byte[] bytes, int bitLength) {
    Digest digest = new SHA3Digest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return rsData;
}
 
Example #8
Source File: Sha3Hash.java    From nuls with MIT License 5 votes vote down vote up
public static String sha3(byte[] bytes, int bitLength) {
    Digest digest = new SHA3Digest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return Hex.encode(rsData);
}
 
Example #9
Source File: HashUtil.java    From asf-sdk with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param data - message to hash
 *
 * @return - reipmd160 hash of the message
 */
public static byte[] ripemd160(byte[] data) {
  Digest digest = new RIPEMD160Digest();
  if (data != null) {
    byte[] resBuf = new byte[digest.getDigestSize()];
    digest.update(data, 0, data.length);
    digest.doFinal(resBuf, 0);
    return resBuf;
  }
  throw new NullPointerException("Can't hash a NULL value");
}
 
Example #10
Source File: Cryptograph.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
private static byte[] getHmac(byte[] secret, byte[] data, Digest algorithm) {
    HMac hmac = new HMac(algorithm);
    hmac.init(new KeyParameter(secret));
    byte[] result = new byte[hmac.getMacSize()];
    hmac.update(data, 0, data.length);
    hmac.doFinal(result, 0);
    return result;
}
 
Example #11
Source File: HashUtil.java    From wkcwallet-java with Apache License 2.0 5 votes vote down vote up
/**
 * @param data - message to hash
 * @return - reipmd160 hash of the message
 */
public static byte[] ripemd160(byte[] data) {
    Digest digest = new RIPEMD160Digest();
    if (data != null) {
        byte[] resBuf = new byte[digest.getDigestSize()];
        digest.update(data, 0, data.length);
        digest.doFinal(resBuf, 0);
        return resBuf;
    }
    throw new NullPointerException("Can't hash a NULL value");
}
 
Example #12
Source File: MyHMacDSAKCalculator.java    From token-core-android with Apache License 2.0 4 votes vote down vote up
/**
 * Base constructor.
 *
 * @param digest digest to build the HMAC on.
 */
public MyHMacDSAKCalculator(Digest digest) {
  this.hMac = new HMac(digest);
  this.V = new byte[hMac.getMacSize()];
  this.K = new byte[hMac.getMacSize()];
}
 
Example #13
Source File: MGF1BytesGeneratorExt.java    From wkcwallet-java with Apache License 2.0 4 votes vote down vote up
public Digest getDigest() {
    return this.digest;
}
 
Example #14
Source File: MGF1BytesGeneratorExt.java    From wkcwallet-java with Apache License 2.0 4 votes vote down vote up
public MGF1BytesGeneratorExt(Digest digest, int counterStart) {
    this.digest = digest;
    this.hLen = digest.getDigestSize();
    this.counterStart = counterStart;
}
 
Example #15
Source File: ConcatKDFBytesGenerator.java    From wkcwallet-java with Apache License 2.0 4 votes vote down vote up
/**
 * return the underlying digest.
 */
public Digest getDigest()
{
    return digest;
}
 
Example #16
Source File: ConcatKDFBytesGenerator.java    From wkcwallet-java with Apache License 2.0 4 votes vote down vote up
public ConcatKDFBytesGenerator(Digest digest) {
    this(1, digest);
}
 
Example #17
Source File: ConcatKDFBytesGenerator.java    From wkcwallet-java with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a KDF Parameters generator.
 * <p>
 * 
 * @param counterStart
 *            value of counter.
 * @param digest
 *            the digest to be used as the source of derived keys.
 */
protected ConcatKDFBytesGenerator(int counterStart, Digest digest)
{
    this.counterStart = counterStart;
    this.digest = digest;
}