use of org.spongycastle.crypto.digests.SHA1Digest in project universa by UniversaBlockchain.
the class OAEPEncodingTest method maskGeneratorFunction1.
/**
* Tests the private implementation of maskGeneratorFunction1 using reference vectors
* from RSA OAEP spec.
*
* @throws Exception
*/
@Test
public void maskGeneratorFunction1() throws Exception {
OAEPEncoding oaepEncoder = new OAEPEncoding(RSAEngineFactory.make(), new SHA1Digest());
byte[] dbMask_test = MGF(oaepEncoder, oaepSpec.seed, 107);
assertArrayEquals(dbMask_test, oaepSpec.dbMask);
byte[] maskedDB_test = new byte[oaepSpec.DB.length];
for (int i = 0; i < oaepSpec.DB.length; i++) {
maskedDB_test[i] = (byte) (oaepSpec.DB[i] ^ oaepSpec.dbMask[i]);
}
assertArrayEquals(maskedDB_test, oaepSpec.maskedDB);
byte[] seedMask_test = MGF(oaepEncoder, oaepSpec.maskedDB, 20);
assertArrayEquals(seedMask_test, oaepSpec.seedMask);
byte[] maskedSeed_test = new byte[oaepSpec.seed.length];
for (int i = 0; i < oaepSpec.seed.length; i++) {
maskedSeed_test[i] = (byte) (oaepSpec.seed[i] ^ oaepSpec.seedMask[i]);
}
assertArrayEquals(maskedSeed_test, oaepSpec.maskedSeed);
ByteArrayOutputStream emStream = new ByteArrayOutputStream();
emStream.write(oaepSpec.maskedSeed);
emStream.write(oaepSpec.maskedDB);
byte[] em_test = emStream.toByteArray();
assertArrayEquals(em_test, oaepSpec.EM);
}
use of org.spongycastle.crypto.digests.SHA1Digest in project balzac by balzac-lang.
the class BitcoinUtils method sha1.
public static Hash sha1(byte[] bytes) {
SHA1Digest digest = new SHA1Digest();
digest.update(bytes, 0, bytes.length);
byte[] sha1Hash = new byte[20];
digest.doFinal(sha1Hash, 0);
return new Hash(sha1Hash);
}
use of org.spongycastle.crypto.digests.SHA1Digest in project rskj by rsksmart.
the class ECIESCoder method decryptSimple.
/**
* 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);
}
use of org.spongycastle.crypto.digests.SHA1Digest in project rskj by rsksmart.
the class ECIESCoder method encryptSimple.
/**
* 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[] encryptSimple(ECPoint pub, byte[] plaintext) 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);
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
SecureRandom random = new SecureRandom();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random);
eGen.init(gParam);
EphemeralKeyPairGenerator ephemeralKeyPairGenerator = new EphemeralKeyPairGenerator(/*testGen*/
eGen, new ECIESPublicKeyEncoder());
iesEngine.init(new ECPublicKeyParameters(pub, CURVE), parametersWithIV, ephemeralKeyPairGenerator);
return iesEngine.processBlock(plaintext, 0, plaintext.length);
}
Aggregations