Tabnine Logo
org.spongycastle.crypto.digests
Code IndexAdd Tabnine to your IDE (free)

How to use org.spongycastle.crypto.digests

Best Java code snippets using org.spongycastle.crypto.digests (Showing top 20 results out of 315)

origin: ethereum/ethereumj

private void doSum(KeccakDigest mac, byte[] out) {
  // doFinal without resetting the MAC by using clone of digest state
  new KeccakDigest(mac).doFinal(out, 0);
}
origin: ethereum/ethereumj

KeccakDigest mac1 = new KeccakDigest(MAC_SIZE);
mac1.update(xor(secrets.mac, responderNonce), 0, secrets.mac.length);
byte[] buf = new byte[32];
new KeccakDigest(mac1).doFinal(buf, 0);
mac1.update(initiatePacket, 0, initiatePacket.length);
new KeccakDigest(mac1).doFinal(buf, 0);
KeccakDigest mac2 = new KeccakDigest(MAC_SIZE);
mac2.update(xor(secrets.mac, initiatorNonce), 0, secrets.mac.length);
new KeccakDigest(mac2).doFinal(buf, 0);
mac2.update(responsePacket, 0, responsePacket.length);
new KeccakDigest(mac2).doFinal(buf, 0);
if (isInitiator) {
  secrets.egressMac = mac1;
origin: ethereum/ethereumj

/**
 * @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");
}
origin: ethereum/ethereumj

private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
  AESEngine aesFastEngine = new AESEngine();
  EthereumIESEngine iesEngine = new EthereumIESEngine(
      new ECDHBasicAgreement(),
      new ConcatKDFBytesGenerator(new SHA256Digest()),
      new HMac(new SHA256Digest()),
      new SHA256Digest(),
      new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
  byte[]         d = new byte[] {};
  byte[]         e = new byte[] {};
  IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
  ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
  iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
  return iesEngine;
}
origin: com.madgag/sc-light-jdk15on

CombinedHash(TlsClientContext context)
{
  this.context = context;
  this.md5 = new MD5Digest();
  this.sha1 = new SHA1Digest();
}
origin: ethereum/ethereumj

/**
 *  Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
 *
 *  DL_KeyAgreementAlgorithm:        DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
 *  DL_KeyDerivationAlgorithm:       DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
 *  DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
 *  DL_PrivateKey:                   DL_Key<ECPPoint>
 *  DL_PrivateKey_EC<class ECP>
 *
 *  Used for Whisper V3
 */
public static byte[] decryptSimple(BigInteger privKey, byte[] cipher) throws IOException, InvalidCipherTextException {
  EthereumIESEngine iesEngine = new EthereumIESEngine(
      new ECDHBasicAgreement(),
      new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
      new HMac(new SHA1Digest()),
      new SHA1Digest(),
      null);
  IESParameters p = new IESParameters(null, null, KEY_SIZE);
  ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);
  iesEngine.setHashMacKey(false);
  iesEngine.init(new ECPrivateKeyParameters(privKey, CURVE), parametersWithIV,
      new ECIESPublicKeyParser(ECKey.CURVE));
  return iesEngine.processBlock(cipher, 0, cipher.length);
}
origin: ethereum/ethereumj

private byte[] updateMac(KeccakDigest mac, byte[] seed, int offset, byte[] out, int outOffset, boolean egress) throws IOException {
  byte[] aesBlock = new byte[mac.getDigestSize()];
  doSum(mac, aesBlock);
  makeMacCipher().processBlock(aesBlock, 0, aesBlock, 0);
  // Note that although the mac digest size is 32 bytes, we only use 16 bytes in the computation
  int length = 16;
  for (int i = 0; i < length; i++) {
    aesBlock[i] ^= seed[i + offset];
  }
  mac.update(aesBlock, 0, length);
  byte[] result = new byte[mac.getDigestSize()];
  doSum(mac, result);
  if (egress) {
    System.arraycopy(result, 0, out, outOffset, length);
  } else {
    for (int i = 0; i < length; i++) {
      if (out[i + outOffset] != result[i]) {
        throw new IOException("MAC mismatch");
      }
    }
  }
  return result;
}
origin: ethereum/ethereumj

assertArrayEquals(decode("2ea74ec5dae199227dff1af715362700e989d889d7a493cb0639691efb8e5f98"), handshakerB.getSecrets().mac);
byte[] fooHash = new byte[32];
handshakerB.getSecrets().ingressMac.update("foo".getBytes(), 0, "foo".getBytes().length);
handshakerB.getSecrets().ingressMac.doFinal(fooHash, 0);
assertArrayEquals(decode("0c7ec6340062cc46f5e9f1e3cf86f8c8c403c5a0964f5df0ebd34a75ddc86db5"), fooHash);
origin: com.madgag.spongycastle/core

public int doFinal(byte[] out, int outOff)
{
  absorbBits(0x02, 2);
  
  return super.doFinal(out,  outOff);
}
origin: com.madgag.spongycastle/core

public void reset(Memoable other)
{
  SM3Digest d = (SM3Digest)other;
  super.copyIn(d);
  copyIn(d);
}
origin: com.madgag.spongycastle/core

  public byte[] getEncodedState()
  {
    byte[] encoded = new byte[getEncodedStateSize()];
    super.populateState(encoded);
    return encoded;
  }
}
origin: ethereum/ethereumj

public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] IV, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
  AESEngine aesFastEngine = new AESEngine();
  EthereumIESEngine iesEngine = new EthereumIESEngine(
      new ECDHBasicAgreement(),
      new ConcatKDFBytesGenerator(new SHA256Digest()),
      new HMac(new SHA256Digest()),
      new SHA256Digest(),
      new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
  byte[]         d = new byte[] {};
  byte[]         e = new byte[] {};
  IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
  ParametersWithIV parametersWithIV =
      new ParametersWithIV(p, IV);
  iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);
  return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
origin: ethereum/ethereumj

EthereumIESEngine iesEngine = new EthereumIESEngine(
    new ECDHBasicAgreement(),
    new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
    new HMac(new SHA1Digest()),
    new SHA1Digest(),
    null);
origin: ethereum/ethereumj

enc.processBytes(ptype, 0, ptype.length, buff, 0);
out.write(buff, 0, ptype.length);
egressMac.update(buff, 0, ptype.length);
while (true) {
  int n = frame.payload.read(buff);
  if (n <= 0) break;
  enc.processBytes(buff, 0, n, buff, 0);
  egressMac.update(buff, 0, n);
  out.write(buff, 0, n);
if (padding < 16) {
  enc.processBytes(pad, 0, padding, buff, 0);
  egressMac.update(buff, 0, padding);
  out.write(buff, 0, padding);
byte[] macBuffer = new byte[egressMac.getDigestSize()];
origin: ethereum/ethereumj

@Test
public void testKDF() {
  ConcatKDFBytesGenerator kdf = new ConcatKDFBytesGenerator(new SHA256Digest());
  kdf.init(new KDFParameters("Hello".getBytes(), new byte[0]));
  byte[] bytes = new byte[2];
  kdf.generateBytes(bytes, 0, bytes.length);
  assertArrayEquals(new byte[]{-66, -89}, bytes);
}
origin: ethereum/ethereumj

ingressMac.update(buffer, 0, frameSize);
dec.processBytes(buffer, 0, frameSize, buffer, 0);
int pos = 0;
InputStream payload = new ByteArrayInputStream(buffer, pos, totalBodySize - pos);
int size = totalBodySize - pos;
byte[] macBuffer = new byte[ingressMac.getDigestSize()];
origin: ethereum/ethereumj

  throw new MissingPrivateKeyException();
if (privKey instanceof BCECPrivateKey) {
  ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
  ECPrivateKeyParameters privKeyParams = new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
  signer.init(true, privKeyParams);
origin: ethereum/ethereumj

private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
  AESEngine aesFastEngine = new AESEngine();
  EthereumIESEngine iesEngine = new EthereumIESEngine(
      new ECDHBasicAgreement(),
      new ConcatKDFBytesGenerator(new SHA256Digest()),
      new HMac(new SHA256Digest()),
      new SHA256Digest(),
      new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
  byte[]         d = new byte[] {};
  byte[]         e = new byte[] {};
  IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
  ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
  iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, curve), new ECPublicKeyParameters(pub, curve), parametersWithIV);
  return iesEngine;
}
origin: ethereum/ethereumj

new KDF2BytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
new KDF2BytesGenerator (new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
origin: ethereum/ethereumj

new KDF2BytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
new KDF2BytesGenerator (new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
org.spongycastle.crypto.digests

Most used classes

  • SHA256Digest
    FIPS 180-2 implementation of SHA-256. block word digest SHA-1 512 32 160 SHA-256 512
  • RIPEMD160Digest
    implementation of RIPEMD see, http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
  • SHA512Digest
    FIPS 180-2 implementation of SHA-512. block word digest SHA-1 512 32 160 SHA-256 512
  • SHA1Digest
    implementation of SHA-1 as outlined in "Handbook of Applied Cryptography", pages 346 - 349. It is in
  • MD5Digest
    implementation of MD5 as outlined in "Handbook of Applied Cryptography", pages 346 - 347.
  • SHA384Digest,
  • KeccakDigest,
  • MD2Digest,
  • RIPEMD128Digest,
  • SHA3Digest,
  • GOST3411Digest,
  • MD4Digest,
  • RIPEMD256Digest,
  • NullDigest,
  • TigerDigest,
  • WhirlpoolDigest,
  • RIPEMD320Digest,
  • GOST3411_2012_256Digest,
  • GOST3411_2012_512Digest
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now