Search in sources :

Example 1 with ConcatKDFBytesGenerator

use of org.ethereum.ConcatKDFBytesGenerator in project rskj by rsksmart.

the class ECIESTest method testKDF.

@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);
}
Also used : ConcatKDFBytesGenerator(org.ethereum.ConcatKDFBytesGenerator) SHA256Digest(org.spongycastle.crypto.digests.SHA256Digest) Test(org.junit.Test)

Example 2 with ConcatKDFBytesGenerator

use of org.ethereum.ConcatKDFBytesGenerator in project rskj by rsksmart.

the class ECIESCoder method decrypt.

public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] iv, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
    AESFastEngine aesFastEngine = new AESFastEngine();
    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);
}
Also used : HMac(org.spongycastle.crypto.macs.HMac) SICBlockCipher(org.spongycastle.crypto.modes.SICBlockCipher) AESFastEngine(org.spongycastle.crypto.engines.AESFastEngine) ECDHBasicAgreement(org.spongycastle.crypto.agreement.ECDHBasicAgreement) ConcatKDFBytesGenerator(org.ethereum.ConcatKDFBytesGenerator) SHA256Digest(org.spongycastle.crypto.digests.SHA256Digest) BufferedBlockCipher(org.spongycastle.crypto.BufferedBlockCipher)

Example 3 with ConcatKDFBytesGenerator

use of org.ethereum.ConcatKDFBytesGenerator in project rskj by rsksmart.

the class ECIESCoder method makeIESEngine.

private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] iv) {
    AESFastEngine aesFastEngine = new AESFastEngine();
    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;
}
Also used : HMac(org.spongycastle.crypto.macs.HMac) SICBlockCipher(org.spongycastle.crypto.modes.SICBlockCipher) AESFastEngine(org.spongycastle.crypto.engines.AESFastEngine) ECDHBasicAgreement(org.spongycastle.crypto.agreement.ECDHBasicAgreement) ConcatKDFBytesGenerator(org.ethereum.ConcatKDFBytesGenerator) SHA256Digest(org.spongycastle.crypto.digests.SHA256Digest) BufferedBlockCipher(org.spongycastle.crypto.BufferedBlockCipher)

Example 4 with ConcatKDFBytesGenerator

use of org.ethereum.ConcatKDFBytesGenerator in project rskj by rsksmart.

the class ECIESTest method makeIESEngine.

private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
    AESFastEngine aesFastEngine = new AESFastEngine();
    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;
}
Also used : HMac(org.spongycastle.crypto.macs.HMac) SICBlockCipher(org.spongycastle.crypto.modes.SICBlockCipher) AESFastEngine(org.spongycastle.crypto.engines.AESFastEngine) ECDHBasicAgreement(org.spongycastle.crypto.agreement.ECDHBasicAgreement) ConcatKDFBytesGenerator(org.ethereum.ConcatKDFBytesGenerator) SHA256Digest(org.spongycastle.crypto.digests.SHA256Digest)

Aggregations

ConcatKDFBytesGenerator (org.ethereum.ConcatKDFBytesGenerator)4 SHA256Digest (org.spongycastle.crypto.digests.SHA256Digest)4 ECDHBasicAgreement (org.spongycastle.crypto.agreement.ECDHBasicAgreement)3 AESFastEngine (org.spongycastle.crypto.engines.AESFastEngine)3 HMac (org.spongycastle.crypto.macs.HMac)3 SICBlockCipher (org.spongycastle.crypto.modes.SICBlockCipher)3 BufferedBlockCipher (org.spongycastle.crypto.BufferedBlockCipher)2 Test (org.junit.Test)1