1package org.bouncycastle.jcajce.provider.digest; 2 3import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; 4import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 5import org.bouncycastle.crypto.CipherKeyGenerator; 6import org.bouncycastle.crypto.digests.SHA256Digest; 7import org.bouncycastle.crypto.macs.HMac; 8import org.bouncycastle.jcajce.provider.config.ConfigurableProvider; 9import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator; 10import org.bouncycastle.jce.provider.JCEMac; 11 12public class SHA256 13{ 14 static public class Digest 15 extends BCMessageDigest 16 implements Cloneable 17 { 18 public Digest() 19 { 20 super(new SHA256Digest()); 21 } 22 23 public Object clone() 24 throws CloneNotSupportedException 25 { 26 Digest d = (Digest)super.clone(); 27 d.digest = new SHA256Digest((SHA256Digest)digest); 28 29 return d; 30 } 31 } 32 33 public static class HashMac 34 extends JCEMac 35 { 36 public HashMac() 37 { 38 super(new HMac(new SHA256Digest())); 39 } 40 } 41 42 /** 43 * HMACSHA256 44 */ 45 public static class KeyGenerator 46 extends BaseKeyGenerator 47 { 48 public KeyGenerator() 49 { 50 super("HMACSHA256", 256, new CipherKeyGenerator()); 51 } 52 } 53 54 public static class Mappings 55 extends DigestAlgorithmProvider 56 { 57 private static final String PREFIX = SHA256.class.getName(); 58 59 public Mappings() 60 { 61 } 62 63 public void configure(ConfigurableProvider provider) 64 { 65 provider.addAlgorithm("MessageDigest.SHA-256", PREFIX + "$Digest"); 66 provider.addAlgorithm("Alg.Alias.MessageDigest.SHA256", "SHA-256"); 67 provider.addAlgorithm("Alg.Alias.MessageDigest." + NISTObjectIdentifiers.id_sha256, "SHA-256"); 68 69 addHMACAlgorithm(provider, "SHA256", PREFIX + "$HashMac", PREFIX + "$KeyGenerator"); 70 addHMACAlias(provider, "SHA256", PKCSObjectIdentifiers.id_hmacWithSHA256); 71 } 72 } 73} 74