Here are the examples of the java api class com.google.bitcoin.bouncycastle.crypto.params.KeyParameter taken from open source projects.
1. TlsUtils#hmac_hash()
Project: bitcoin-android
File: TlsUtils.java
File: TlsUtils.java
private static void hmac_hash(Digest digest, byte[] secret, byte[] seed, byte[] out) { HMac mac = new HMac(digest); KeyParameter param = new KeyParameter(secret); byte[] a = seed; int size = digest.getDigestSize(); int iterations = (out.length + size - 1) / size; byte[] buf = new byte[mac.getMacSize()]; byte[] buf2 = new byte[mac.getMacSize()]; for (int i = 0; i < iterations; i++) { mac.init(param); mac.update(a, 0, a.length); mac.doFinal(buf, 0); a = buf; mac.init(param); mac.update(a, 0, a.length); mac.update(seed, 0, seed.length); mac.doFinal(buf2, 0); System.arraycopy(buf2, 0, out, (size * i), Math.min(size, out.length - (size * i))); } }
2. XTEAEngine#init()
Project: bitcoin-android
File: XTEAEngine.java
File: XTEAEngine.java
/** * initialise * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof KeyParameter)) { throw new IllegalArgumentException("invalid parameter passed to TEA init - " + params.getClass().getName()); } _forEncryption = forEncryption; _initialised = true; KeyParameter p = (KeyParameter) params; setKey(p.getKey()); }
3. TEAEngine#init()
Project: bitcoin-android
File: TEAEngine.java
File: TEAEngine.java
/** * initialise * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof KeyParameter)) { throw new IllegalArgumentException("invalid parameter passed to TEA init - " + params.getClass().getName()); } _forEncryption = forEncryption; _initialised = true; KeyParameter p = (KeyParameter) params; setKey(p.getKey()); }
4. RC6Engine#init()
Project: bitcoin-android
File: RC6Engine.java
File: RC6Engine.java
/** * initialise a RC5-32 cipher. * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof KeyParameter)) { throw new IllegalArgumentException("invalid parameter passed to RC6 init - " + params.getClass().getName()); } KeyParameter p = (KeyParameter) params; this.forEncryption = forEncryption; setKey(p.getKey()); }
5. NoekeonEngine#init()
Project: bitcoin-android
File: NoekeonEngine.java
File: NoekeonEngine.java
/** * initialise * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof KeyParameter)) { throw new IllegalArgumentException("invalid parameter passed to Noekeon init - " + params.getClass().getName()); } _forEncryption = forEncryption; _initialised = true; KeyParameter p = (KeyParameter) params; setKey(p.getKey()); }
6. ISAACEngine#init()
Project: bitcoin-android
File: ISAACEngine.java
File: ISAACEngine.java
/** * initialise an ISAAC cipher. * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof KeyParameter)) { throw new IllegalArgumentException("invalid parameter passed to ISAAC init - " + params.getClass().getName()); } /* * ISAAC encryption and decryption is completely * symmetrical, so the 'forEncryption' is * irrelevant. */ KeyParameter p = (KeyParameter) params; setKey(p.getKey()); return; }
7. ISO9797Alg3Mac#init()
Project: bitcoin-android
File: ISO9797Alg3Mac.java
File: ISO9797Alg3Mac.java
public void init(CipherParameters params) { reset(); if (!(params instanceof KeyParameter)) { throw new IllegalArgumentException("params must be an instance of KeyParameter"); } // KeyParameter must contain a double or triple length DES key, // however the underlying cipher is a single DES. The middle and // right key are used only in the final step. KeyParameter kp = (KeyParameter) params; KeyParameter key1; byte[] keyvalue = kp.getKey(); if (keyvalue.length == 16) { // Double length DES key key1 = new KeyParameter(keyvalue, 0, 8); this.lastKey2 = new KeyParameter(keyvalue, 8, 8); this.lastKey3 = key1; } else if (keyvalue.length == 24) { // Triple length DES key key1 = new KeyParameter(keyvalue, 0, 8); this.lastKey2 = new KeyParameter(keyvalue, 8, 8); this.lastKey3 = new KeyParameter(keyvalue, 16, 8); } else { throw new IllegalArgumentException("Key must be either 112 or 168 bit long"); } cipher.init(true, key1); }
8. TlsBlockCipherCipherSuite#initCipher()
Project: bitcoin-android
File: TlsBlockCipherCipherSuite.java
File: TlsBlockCipherCipherSuite.java
private void initCipher(boolean forEncryption, BlockCipher cipher, byte[] key_block, int key_size, int key_offset, int iv_offset) { KeyParameter key_parameter = new KeyParameter(key_block, key_offset, key_size); ParametersWithIV parameters_with_iv = new ParametersWithIV(key_parameter, key_block, iv_offset, cipher.getBlockSize()); cipher.init(forEncryption, parameters_with_iv); }
9. VMPCMac#init()
Project: bitcoin-android
File: VMPCMac.java
File: VMPCMac.java
public void init(CipherParameters params) throws IllegalArgumentException { if (!(params instanceof ParametersWithIV)) { throw new IllegalArgumentException("VMPC-MAC Init parameters must include an IV"); } ParametersWithIV ivParams = (ParametersWithIV) params; KeyParameter key = (KeyParameter) ivParams.getParameters(); if (!(ivParams.getParameters() instanceof KeyParameter)) { throw new IllegalArgumentException("VMPC-MAC Init parameters must include a key"); } this.workingIV = ivParams.getIV(); if (workingIV == null || workingIV.length < 1 || workingIV.length > 768) { throw new IllegalArgumentException("VMPC-MAC requires 1 to 768 bytes of IV"); } this.workingKey = key.getKey(); reset(); }
10. VMPCEngine#init()
Project: bitcoin-android
File: VMPCEngine.java
File: VMPCEngine.java
/** * initialise a VMPC cipher. * * @param forEncryption * whether or not we are for encryption. * @param params * the parameters required to set up the cipher. * @exception IllegalArgumentException * if the params argument is inappropriate. */ public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof ParametersWithIV)) { throw new IllegalArgumentException("VMPC init parameters must include an IV"); } ParametersWithIV ivParams = (ParametersWithIV) params; KeyParameter key = (KeyParameter) ivParams.getParameters(); if (!(ivParams.getParameters() instanceof KeyParameter)) { throw new IllegalArgumentException("VMPC init parameters must include a key"); } this.workingIV = ivParams.getIV(); if (workingIV == null || workingIV.length < 1 || workingIV.length > 768) { throw new IllegalArgumentException("VMPC requires 1 to 768 bytes of IV"); } this.workingKey = key.getKey(); initKey(this.workingKey, this.workingIV); }
11. Salsa20Engine#init()
Project: bitcoin-android
File: Salsa20Engine.java
File: Salsa20Engine.java
/** * initialise a Salsa20 cipher. * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof ParametersWithIV)) { throw new IllegalArgumentException("Salsa20 Init parameters must include an IV"); } ParametersWithIV ivParams = (ParametersWithIV) params; byte[] iv = ivParams.getIV(); if (iv == null || iv.length != 8) { throw new IllegalArgumentException("Salsa20 requires exactly 8 bytes of IV"); } if (!(ivParams.getParameters() instanceof KeyParameter)) { throw new IllegalArgumentException("Salsa20 Init parameters must include a key"); } KeyParameter key = (KeyParameter) ivParams.getParameters(); workingKey = key.getKey(); workingIV = iv; setKey(workingKey, workingIV); }
12. IESEngine#encryptBlock()
Project: bitcoin-android
File: IESEngine.java
File: IESEngine.java
private byte[] encryptBlock(byte[] in, int inOff, int inLen, byte[] z) throws InvalidCipherTextException { byte[] C = null; KeyParameter macKey = null; KDFParameters kParam = new KDFParameters(z, param.getDerivationV()); int c_text_length = 0; int macKeySize = param.getMacKeySize(); if (// stream mode cipher == null) { byte[] buf = generateKdfBytes(kParam, inLen + (macKeySize / 8)); C = new byte[inLen + mac.getMacSize()]; c_text_length = inLen; for (int i = 0; i != inLen; i++) { C[i] = (byte) (in[inOff + i] ^ buf[i]); } macKey = new KeyParameter(buf, inLen, (macKeySize / 8)); } else { int cipherKeySize = ((IESWithCipherParameters) param).getCipherKeySize(); byte[] buf = generateKdfBytes(kParam, (cipherKeySize / 8) + (macKeySize / 8)); cipher.init(true, new KeyParameter(buf, 0, (cipherKeySize / 8))); c_text_length = cipher.getOutputSize(inLen); byte[] tmp = new byte[c_text_length]; int len = cipher.processBytes(in, inOff, inLen, tmp, 0); len += cipher.doFinal(tmp, len); C = new byte[len + mac.getMacSize()]; c_text_length = len; System.arraycopy(tmp, 0, C, 0, len); macKey = new KeyParameter(buf, (cipherKeySize / 8), (macKeySize / 8)); } byte[] macIV = param.getEncodingV(); mac.init(macKey); mac.update(C, 0, c_text_length); mac.update(macIV, 0, macIV.length); // // return the message and it's MAC // mac.doFinal(C, c_text_length); return C; }
13. IESEngine#decryptBlock()
Project: bitcoin-android
File: IESEngine.java
File: IESEngine.java
private byte[] decryptBlock(byte[] in_enc, int inOff, int inLen, byte[] z) throws InvalidCipherTextException { byte[] M = null; KeyParameter macKey = null; KDFParameters kParam = new KDFParameters(z, param.getDerivationV()); int macKeySize = param.getMacKeySize(); kdf.init(kParam); inLen -= mac.getMacSize(); if (// stream mode cipher == null) { byte[] buf = generateKdfBytes(kParam, inLen + (macKeySize / 8)); M = new byte[inLen]; for (int i = 0; i != inLen; i++) { M[i] = (byte) (in_enc[inOff + i] ^ buf[i]); } macKey = new KeyParameter(buf, inLen, (macKeySize / 8)); } else { int cipherKeySize = ((IESWithCipherParameters) param).getCipherKeySize(); byte[] buf = generateKdfBytes(kParam, (cipherKeySize / 8) + (macKeySize / 8)); cipher.init(false, new KeyParameter(buf, 0, (cipherKeySize / 8))); byte[] tmp = new byte[cipher.getOutputSize(inLen)]; int len = cipher.processBytes(in_enc, inOff, inLen, tmp, 0); len += cipher.doFinal(tmp, len); M = new byte[len]; System.arraycopy(tmp, 0, M, 0, len); macKey = new KeyParameter(buf, (cipherKeySize / 8), (macKeySize / 8)); } byte[] macIV = param.getEncodingV(); mac.init(macKey); mac.update(in_enc, inOff, inLen); mac.update(macIV, 0, macIV.length); mac.doFinal(macBuf, 0); inOff += inLen; for (int t = 0; t < macBuf.length; t++) { if (macBuf[t] != in_enc[inOff + t]) { throw (new InvalidCipherTextException("Mac codes failed to equal.")); } } return M; }
14. Grainv1Engine#init()
Project: bitcoin-android
File: Grainv1Engine.java
File: Grainv1Engine.java
/** * Initialize a Grain v1 cipher. * * @param forEncryption Whether or not we are for encryption. * @param params The parameters required to set up the cipher. * @throws IllegalArgumentException If the params argument is inappropriate. */ public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException { /** * Grain encryption and decryption is completely symmetrical, so the * 'forEncryption' is irrelevant. */ if (!(params instanceof ParametersWithIV)) { throw new IllegalArgumentException("Grain v1 Init parameters must include an IV"); } ParametersWithIV ivParams = (ParametersWithIV) params; byte[] iv = ivParams.getIV(); if (iv == null || iv.length != 8) { throw new IllegalArgumentException("Grain v1 requires exactly 8 bytes of IV"); } if (!(ivParams.getParameters() instanceof KeyParameter)) { throw new IllegalArgumentException("Grain v1 Init parameters must include a key"); } KeyParameter key = (KeyParameter) ivParams.getParameters(); /** * Initialize variables. */ workingIV = new byte[key.getKey().length]; workingKey = new byte[key.getKey().length]; lfsr = new int[STATE_SIZE]; nfsr = new int[STATE_SIZE]; out = new byte[2]; System.arraycopy(iv, 0, workingIV, 0, iv.length); System.arraycopy(key.getKey(), 0, workingKey, 0, key.getKey().length); setKey(workingKey, workingIV); initGrain(); }
15. Grain128Engine#init()
Project: bitcoin-android
File: Grain128Engine.java
File: Grain128Engine.java
/** * Initialize a Grain-128 cipher. * * @param forEncryption Whether or not we are for encryption. * @param params The parameters required to set up the cipher. * @throws IllegalArgumentException If the params argument is inappropriate. */ public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException { /** * Grain encryption and decryption is completely symmetrical, so the * 'forEncryption' is irrelevant. */ if (!(params instanceof ParametersWithIV)) { throw new IllegalArgumentException("Grain-128 Init parameters must include an IV"); } ParametersWithIV ivParams = (ParametersWithIV) params; byte[] iv = ivParams.getIV(); if (iv == null || iv.length != 12) { throw new IllegalArgumentException("Grain-128 requires exactly 12 bytes of IV"); } if (!(ivParams.getParameters() instanceof KeyParameter)) { throw new IllegalArgumentException("Grain-128 Init parameters must include a key"); } KeyParameter key = (KeyParameter) ivParams.getParameters(); /** * Initialize variables. */ workingIV = new byte[key.getKey().length]; workingKey = new byte[key.getKey().length]; lfsr = new int[STATE_SIZE]; nfsr = new int[STATE_SIZE]; out = new byte[4]; System.arraycopy(iv, 0, workingIV, 0, iv.length); System.arraycopy(key.getKey(), 0, workingKey, 0, key.getKey().length); setKey(workingKey, workingIV); initGrain(); }