Home | History | Annotate | Download | only in symmetric
      1 package org.bouncycastle.jcajce.provider.symmetric;
      2 
      3 import org.bouncycastle.asn1.misc.MiscObjectIdentifiers;
      4 import org.bouncycastle.crypto.CipherKeyGenerator;
      5 import org.bouncycastle.crypto.engines.BlowfishEngine;
      6 // Android-removed: Unsupported algorithms
      7 // import org.bouncycastle.crypto.macs.CMac;
      8 import org.bouncycastle.crypto.modes.CBCBlockCipher;
      9 import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
     10 import org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher;
     11 import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
     12 // Android-removed: Unsupported algorithms
     13 // import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
     14 import org.bouncycastle.jcajce.provider.symmetric.util.IvAlgorithmParameters;
     15 import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
     16 
     17 public final class Blowfish
     18 {
     19     private Blowfish()
     20     {
     21     }
     22 
     23     public static class ECB
     24         extends BaseBlockCipher
     25     {
     26         public ECB()
     27         {
     28             super(new BlowfishEngine());
     29         }
     30     }
     31 
     32     public static class CBC
     33         extends BaseBlockCipher
     34     {
     35         public CBC()
     36         {
     37             super(new CBCBlockCipher(new BlowfishEngine()), 64);
     38         }
     39     }
     40 
     41     // BEGIN Android-removed: Unsupported algorithms
     42     /*
     43     public static class CMAC
     44         extends BaseMac
     45     {
     46         public CMAC()
     47         {
     48             super(new CMac(new BlowfishEngine()));
     49         }
     50     }
     51     */
     52     // END Android-removed: Unsupported algorithms
     53 
     54     public static class KeyGen
     55         extends BaseKeyGenerator
     56     {
     57         public KeyGen()
     58         {
     59             super("Blowfish", 128, new CipherKeyGenerator());
     60         }
     61     }
     62 
     63     public static class AlgParams
     64         extends IvAlgorithmParameters
     65     {
     66         protected String engineToString()
     67         {
     68             return "Blowfish IV";
     69         }
     70     }
     71 
     72     public static class Mappings
     73         extends AlgorithmProvider
     74     {
     75         private static final String PREFIX = Blowfish.class.getName();
     76 
     77         public Mappings()
     78         {
     79         }
     80 
     81         public void configure(ConfigurableProvider provider)
     82         {
     83             // Android-removed: Unsupported algorithms
     84             // provider.addAlgorithm("Mac.BLOWFISHCMAC", PREFIX + "$CMAC");
     85             provider.addAlgorithm("Cipher.BLOWFISH", PREFIX + "$ECB");
     86             // Android-removed: Unsupported algorithms
     87             // provider.addAlgorithm("Cipher", MiscObjectIdentifiers.cryptlib_algorithm_blowfish_CBC, PREFIX + "$CBC");
     88             provider.addAlgorithm("KeyGenerator.BLOWFISH", PREFIX + "$KeyGen");
     89             provider.addAlgorithm("Alg.Alias.KeyGenerator", MiscObjectIdentifiers.cryptlib_algorithm_blowfish_CBC, "BLOWFISH");
     90             provider.addAlgorithm("AlgorithmParameters.BLOWFISH", PREFIX + "$AlgParams");
     91             provider.addAlgorithm("Alg.Alias.AlgorithmParameters", MiscObjectIdentifiers.cryptlib_algorithm_blowfish_CBC, "BLOWFISH");
     92 
     93         }
     94     }
     95 }
     96