Home | History | Annotate | Download | only in digest
      1 package org.bouncycastle.jcajce.provider.digest;
      2 
      3 import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
      4 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
      5 import org.bouncycastle.crypto.CipherKeyGenerator;
      6 import org.bouncycastle.crypto.digests.SHA256Digest;
      7 import org.bouncycastle.crypto.macs.HMac;
      8 import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
      9 import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
     10 import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
     11 import org.bouncycastle.jcajce.provider.symmetric.util.PBESecretKeyFactory;
     12 
     13 public class SHA256
     14 {
     15     private SHA256()
     16     {
     17 
     18     }
     19 
     20     static public class Digest
     21         extends BCMessageDigest
     22         implements Cloneable
     23     {
     24         public Digest()
     25         {
     26             super(new SHA256Digest());
     27         }
     28 
     29         public Object clone()
     30             throws CloneNotSupportedException
     31         {
     32             Digest d = (Digest)super.clone();
     33             d.digest = new SHA256Digest((SHA256Digest)digest);
     34 
     35             return d;
     36         }
     37     }
     38 
     39     public static class HashMac
     40         extends BaseMac
     41     {
     42         public HashMac()
     43         {
     44             super(new HMac(new SHA256Digest()));
     45         }
     46     }
     47 
     48     // BEGIN Android-removed: Unsupported algorithms
     49     /*
     50     /**
     51      * PBEWithHmacSHA
     52      *
     53     public static class PBEWithMacKeyFactory
     54         extends PBESecretKeyFactory
     55     {
     56         public PBEWithMacKeyFactory()
     57         {
     58             super("PBEwithHmacSHA256", null, false, PKCS12, SHA256, 256, 0);
     59         }
     60     }
     61     */
     62     // END Android-removed: Unsupported algorithms
     63 
     64     /**
     65      * HMACSHA256
     66      */
     67     public static class KeyGenerator
     68         extends BaseKeyGenerator
     69     {
     70         public KeyGenerator()
     71         {
     72             super("HMACSHA256", 256, new CipherKeyGenerator());
     73         }
     74     }
     75 
     76     public static class Mappings
     77         extends DigestAlgorithmProvider
     78     {
     79         private static final String PREFIX = SHA256.class.getName();
     80 
     81         public Mappings()
     82         {
     83         }
     84 
     85         public void configure(ConfigurableProvider provider)
     86         {
     87             provider.addAlgorithm("MessageDigest.SHA-256", PREFIX + "$Digest");
     88             provider.addAlgorithm("Alg.Alias.MessageDigest.SHA256", "SHA-256");
     89             provider.addAlgorithm("Alg.Alias.MessageDigest." + NISTObjectIdentifiers.id_sha256, "SHA-256");
     90 
     91             // BEGIN Android-removed: Unsupported algorithms
     92             // provider.addAlgorithm("SecretKeyFactory.PBEWITHHMACSHA256", PREFIX + "$PBEWithMacKeyFactory");
     93             // provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHHMACSHA-256", "PBEWITHHMACSHA256");
     94             // provider.addAlgorithm("Alg.Alias.SecretKeyFactory." + NISTObjectIdentifiers.id_sha256, "PBEWITHHMACSHA256");
     95             // END Android-removed: Unsupported algorithms
     96 
     97             provider.addAlgorithm("Mac.PBEWITHHMACSHA256", PREFIX + "$HashMac");
     98 
     99             addHMACAlgorithm(provider, "SHA256", PREFIX + "$HashMac",  PREFIX + "$KeyGenerator");
    100             addHMACAlias(provider, "SHA256", PKCSObjectIdentifiers.id_hmacWithSHA256);
    101             addHMACAlias(provider, "SHA256", NISTObjectIdentifiers.id_sha256);
    102         }
    103     }
    104 }
    105