org.bouncycastle.crypto.engines.ChaChaEngine Java Examples
The following examples show how to use
org.bouncycastle.crypto.engines.ChaChaEngine.
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: Chacha20Crypt.java From shadowsocks-java with MIT License | 5 votes |
@Override protected StreamCipher getCipher(boolean isEncrypted) throws InvalidAlgorithmParameterException { if (_name.equals(CIPHER_CHACHA20)) { return new ChaChaEngine(); } else if (_name.equals(CIPHER_CHACHA20_IETF)) { return new ChaCha7539Engine(); } return null; }
Example #2
Source File: Chacha20Crypt.java From shadowsocks-android-java with Apache License 2.0 | 5 votes |
@Override protected StreamCipher getCipher(boolean isEncrypted) throws InvalidAlgorithmParameterException { if (_name.equals(CIPHER_CHACHA20)) { return new ChaChaEngine(); } else if (_name.equals(CIPHER_CHACHA20_IETF)) { return new ChaCha7539Engine(); } return null; }
Example #3
Source File: ChachaDecoder.java From HAP-Java with MIT License | 5 votes |
private KeyParameter initRecordMAC(ChaChaEngine cipher) { byte[] firstBlock = new byte[64]; cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0); // NOTE: The BC implementation puts 'r' after 'k' System.arraycopy(firstBlock, 0, firstBlock, 32, 16); KeyParameter macKey = new KeyParameter(firstBlock, 16, 32); Poly1305KeyGenerator.clamp(macKey.getKey()); return macKey; }
Example #4
Source File: ChachaEncoder.java From HAP-Java with MIT License | 5 votes |
private KeyParameter initRecordMAC(ChaChaEngine cipher) { byte[] firstBlock = new byte[64]; cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0); // NOTE: The BC implementation puts 'r' after 'k' System.arraycopy(firstBlock, 0, firstBlock, 32, 16); KeyParameter macKey = new KeyParameter(firstBlock, 16, 32); Poly1305KeyGenerator.clamp(macKey.getKey()); return macKey; }
Example #5
Source File: ChaCha20Encryptor.java From archistar-smc with GNU Lesser General Public License v2.1 | 5 votes |
@Override public byte[] encrypt(byte[] data, byte[] randomKeyBytes) throws IOException, InvalidKeyException, InvalidAlgorithmParameterException, InvalidCipherTextException { ChaChaEngine cipher = new ChaChaEngine(); cipher.init(true, new ParametersWithIV(new KeyParameter(randomKeyBytes), randomIvBytes)); byte[] result = new byte[data.length]; cipher.processBytes(data, 0, data.length, result, 0); return result; }
Example #6
Source File: ChaCha20Encryptor.java From archistar-smc with GNU Lesser General Public License v2.1 | 5 votes |
@Override public byte[] decrypt(byte[] data, byte[] randomKeyBytes) throws InvalidKeyException, InvalidAlgorithmParameterException, IOException, IllegalStateException, InvalidCipherTextException { ChaChaEngine cipher = new ChaChaEngine(); cipher.init(false, new ParametersWithIV(new KeyParameter(randomKeyBytes), randomIvBytes)); byte[] result = new byte[data.length]; cipher.processBytes(data, 0, data.length, result, 0); return result; }
Example #7
Source File: ChaCha20Encryptor.java From archistar-smc with GNU Lesser General Public License v2.1 | 5 votes |
/** * Special method to decrypt partial data * * @param data to decrypt * @param randomKeyBytes key to use * @param startingByte the starting position within the (complete) data * @return decrypted data */ public byte[] decrypt(byte[] data, byte[] randomKeyBytes, long startingByte) { ChaChaEngine cipher = new ChaChaEngine(); cipher.init(false, new ParametersWithIV(new KeyParameter(randomKeyBytes), randomIvBytes)); cipher.skip(startingByte); byte[] result = new byte[data.length]; cipher.processBytes(data, 0, data.length, result, 0); return result; }
Example #8
Source File: ChachaDecoder.java From HAP-Java with MIT License | 2 votes |
public ChachaDecoder(byte[] key, byte[] nonce) throws IOException { this.decryptCipher = new ChaChaEngine(20); this.decryptCipher.init(false, new ParametersWithIV(new KeyParameter(key), nonce)); }
Example #9
Source File: ChachaEncoder.java From HAP-Java with MIT License | 2 votes |
public ChachaEncoder(byte[] key, byte[] nonce) throws IOException { this.encryptCipher = new ChaChaEngine(20); this.encryptCipher.init(true, new ParametersWithIV(new KeyParameter(key), nonce)); }