1package org.bouncycastle.jcajce.provider.symmetric; 2 3import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 4import org.bouncycastle.crypto.CipherKeyGenerator; 5import org.bouncycastle.crypto.engines.RC4Engine; 6import org.bouncycastle.jcajce.provider.config.ConfigurableProvider; 7import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator; 8import org.bouncycastle.jcajce.provider.symmetric.util.BaseStreamCipher; 9import org.bouncycastle.jcajce.provider.symmetric.util.PBESecretKeyFactory; 10import org.bouncycastle.jcajce.provider.util.AlgorithmProvider; 11 12public final class ARC4 13{ 14 private ARC4() 15 { 16 } 17 18 public static class Base 19 extends BaseStreamCipher 20 { 21 public Base() 22 { 23 super(new RC4Engine(), 0); 24 } 25 } 26 27 public static class KeyGen 28 extends BaseKeyGenerator 29 { 30 public KeyGen() 31 { 32 // BEGIN android-changed 33 super("ARC4", 128, new CipherKeyGenerator()); 34 // END android-changed 35 } 36 } 37 38 /** 39 * PBEWithSHAAnd128BitRC4 40 */ 41 static public class PBEWithSHAAnd128BitKeyFactory 42 extends PBESecretKeyFactory 43 { 44 public PBEWithSHAAnd128BitKeyFactory() 45 { 46 super("PBEWithSHAAnd128BitRC4", PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC4, true, PKCS12, SHA1, 128, 0); 47 } 48 } 49 50 /** 51 * PBEWithSHAAnd40BitRC4 52 */ 53 static public class PBEWithSHAAnd40BitKeyFactory 54 extends PBESecretKeyFactory 55 { 56 public PBEWithSHAAnd40BitKeyFactory() 57 { 58 super("PBEWithSHAAnd128BitRC4", PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC4, true, PKCS12, SHA1, 40, 0); 59 } 60 } 61 62 63 /** 64 * PBEWithSHAAnd128BitRC4 65 */ 66 static public class PBEWithSHAAnd128Bit 67 extends BaseStreamCipher 68 { 69 public PBEWithSHAAnd128Bit() 70 { 71 super(new RC4Engine(), 0); 72 } 73 } 74 75 /** 76 * PBEWithSHAAnd40BitRC4 77 */ 78 static public class PBEWithSHAAnd40Bit 79 extends BaseStreamCipher 80 { 81 public PBEWithSHAAnd40Bit() 82 { 83 super(new RC4Engine(), 0); 84 } 85 } 86 87 public static class Mappings 88 extends AlgorithmProvider 89 { 90 private static final String PREFIX = ARC4.class.getName(); 91 92 public Mappings() 93 { 94 } 95 96 public void configure(ConfigurableProvider provider) 97 { 98 provider.addAlgorithm("Cipher.ARC4", PREFIX + "$Base"); 99 provider.addAlgorithm("Alg.Alias.Cipher." + PKCSObjectIdentifiers.rc4, "ARC4"); 100 provider.addAlgorithm("Alg.Alias.Cipher.ARCFOUR", "ARC4"); 101 provider.addAlgorithm("Alg.Alias.Cipher.RC4", "ARC4"); 102 provider.addAlgorithm("KeyGenerator.ARC4", PREFIX + "$KeyGen"); 103 provider.addAlgorithm("Alg.Alias.KeyGenerator.RC4", "ARC4"); 104 provider.addAlgorithm("Alg.Alias.KeyGenerator.1.2.840.113549.3.4", "ARC4"); 105 provider.addAlgorithm("SecretKeyFactory.PBEWITHSHAAND128BITRC4", PREFIX + "$PBEWithSHAAnd128BitKeyFactory"); 106 provider.addAlgorithm("SecretKeyFactory.PBEWITHSHAAND40BITRC4", PREFIX + "$PBEWithSHAAnd40BitKeyFactory"); 107 108 provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC4, "PKCS12PBE"); 109 provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC4, "PKCS12PBE"); 110 provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND40BITRC4", "PKCS12PBE"); 111 provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITRC4", "PKCS12PBE"); 112 provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC4", "PKCS12PBE"); 113 provider.addAlgorithm("Cipher.PBEWITHSHAAND128BITRC4", PREFIX + "$PBEWithSHAAnd128Bit"); 114 provider.addAlgorithm("Cipher.PBEWITHSHAAND40BITRC4", PREFIX + "$PBEWithSHAAnd40Bit"); 115 116 provider.addAlgorithm("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC4, "PBEWITHSHAAND128BITRC4"); 117 provider.addAlgorithm("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC4, "PBEWITHSHAAND40BITRC4"); 118 119 provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND128BITRC4", "PBEWITHSHAAND128BITRC4"); 120 provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND40BITRC4", "PBEWITHSHAAND40BITRC4"); 121 122 provider.addAlgorithm("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC4, "PBEWITHSHAAND128BITRC4"); 123 provider.addAlgorithm("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC4, "PBEWITHSHAAND40BITRC4"); 124 } 125 } 126} 127