protected AlgorithmParameterSpec generateParameterSpec(ASN1ObjectIdentifier macOID, SecretKey encKey) throws CMSException { try { if (macOID.equals(PKCSObjectIdentifiers.RC2_CBC)) { byte[] iv = new byte[8]; random.nextBytes(iv); return new RC2ParameterSpec(encKey.getEncoded().length * 8, iv); } AlgorithmParameterGenerator pGen = helper.createAlgorithmParameterGenerator(macOID); AlgorithmParameters p = pGen.generateParameters(); return p.getParameterSpec(IvParameterSpec.class); } catch (GeneralSecurityException e) { return null; } }
protected AlgorithmParameterSpec localEngineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == RC2ParameterSpec.class) { if (parameterVersion != -1) { if (parameterVersion < 256) { return new RC2ParameterSpec(ekb[parameterVersion], iv); } else { return new RC2ParameterSpec(parameterVersion, iv); } } } if (paramSpec == IvParameterSpec.class) { return new IvParameterSpec(iv); } throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object."); }
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof RC2ParameterSpec)) { throw new InvalidParameterSpecException ("Inappropriate parameter specification"); } RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec; // check effective key size (a value of 0 means it is unspecified) effectiveKeySize = rps.getEffectiveKeyBits(); if (effectiveKeySize != 0) { if (effectiveKeySize < 1 || effectiveKeySize > 1024) { throw new InvalidParameterSpecException("RC2 effective key " + "size must be between 1 and 1024 bits"); } if (effectiveKeySize < 256) { version = EKB_TABLE[effectiveKeySize]; } else { version = effectiveKeySize; } } this.iv = rps.getIV(); }
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { if (params != null && params.getAlgorithm().equals("RC2")) { try { RC2ParameterSpec rc2Params = params.getParameterSpec(RC2ParameterSpec.class); engineInit(opmode, key, rc2Params, random); } catch (InvalidParameterSpecException ipse) { throw new InvalidAlgorithmParameterException ("Wrong parameter type: RC2 expected"); } } else { embeddedCipher.initEffectiveKeyBits(0); core.init(opmode, key, params, random); } }
/** * getEffectiveKeyBits() method testing. Tests that returned value is * equal to the value specified in the constructor. */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getEffectiveKeyBits", args = {} ) public void testGetEffectiveKeyBits() { int effectiveKeyBits = 10; byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8}; RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv); assertTrue("The returned effectiveKeyBits value is not equal to the " + "value specified in the constructor.", effectiveKeyBits == ps.getEffectiveKeyBits()); }
/** * hashCode() method testing. Tests that for equal objects hash codes * are equal. */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "hashCode", args = {} ) public void testHashCode() { int effectiveKeyBits = 0; byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv); RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv); assertTrue("Equal objects should have the same hash codes.", ps1.hashCode() == ps2.hashCode()); }
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { if (params != null && params.getAlgorithm().equals("RC2")) { try { RC2ParameterSpec rc2Params = (RC2ParameterSpec) params.getParameterSpec(RC2ParameterSpec.class); engineInit(opmode, key, rc2Params, random); } catch (InvalidParameterSpecException ipse) { throw new InvalidAlgorithmParameterException ("Wrong parameter type: RC2 expected"); } } else { embeddedCipher.initEffectiveKeyBits(0); core.init(opmode, key, params, random); } }