1 package org.bouncycastle.operator; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6 import org.bouncycastle.asn1.ASN1ObjectIdentifier; 7 import org.bouncycastle.asn1.DERNull; 8 // BEGIN android-removed 9 // import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; 10 // END android-removed 11 import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; 12 import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; 13 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 14 import org.bouncycastle.asn1.pkcs.RSASSAPSSparams; 15 import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers; 16 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 17 import org.bouncycastle.asn1.x9.X9ObjectIdentifiers; 18 19 public class DefaultDigestAlgorithmIdentifierFinder 20 implements DigestAlgorithmIdentifierFinder 21 { 22 private static Map digestOids = new HashMap(); 23 private static Map digestNameToOids = new HashMap(); 24 25 static 26 { 27 // 28 // digests 29 // 30 // BEGIN android-removed 31 // digestOids.put(OIWObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); 32 // digestOids.put(OIWObjectIdentifiers.md4WithRSA, PKCSObjectIdentifiers.md4); 33 // END android-removed digestOids.put(OIWObjectIdentifiers.sha1WithRSA, OIWObjectIdentifiers.idSHA1)34 digestOids.put(OIWObjectIdentifiers.sha1WithRSA, OIWObjectIdentifiers.idSHA1); 35 digestOids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, NISTObjectIdentifiers.id_sha224)36 digestOids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, NISTObjectIdentifiers.id_sha224); digestOids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, NISTObjectIdentifiers.id_sha256)37 digestOids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, NISTObjectIdentifiers.id_sha256); digestOids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, NISTObjectIdentifiers.id_sha384)38 digestOids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, NISTObjectIdentifiers.id_sha384); digestOids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, NISTObjectIdentifiers.id_sha512)39 digestOids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, NISTObjectIdentifiers.id_sha512); 40 // BEGIN android-removed 41 // digestOids.put(PKCSObjectIdentifiers.md2WithRSAEncryption, PKCSObjectIdentifiers.md2); 42 // digestOids.put(PKCSObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); 43 // END android-removed digestOids.put(PKCSObjectIdentifiers.md5WithRSAEncryption, PKCSObjectIdentifiers.md5)44 digestOids.put(PKCSObjectIdentifiers.md5WithRSAEncryption, PKCSObjectIdentifiers.md5); digestOids.put(PKCSObjectIdentifiers.sha1WithRSAEncryption, OIWObjectIdentifiers.idSHA1)45 digestOids.put(PKCSObjectIdentifiers.sha1WithRSAEncryption, OIWObjectIdentifiers.idSHA1); 46 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, OIWObjectIdentifiers.idSHA1)47 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, OIWObjectIdentifiers.idSHA1); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, NISTObjectIdentifiers.id_sha224)48 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, NISTObjectIdentifiers.id_sha224); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, NISTObjectIdentifiers.id_sha256)49 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, NISTObjectIdentifiers.id_sha256); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, NISTObjectIdentifiers.id_sha384)50 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, NISTObjectIdentifiers.id_sha384); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, NISTObjectIdentifiers.id_sha512)51 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, NISTObjectIdentifiers.id_sha512); digestOids.put(X9ObjectIdentifiers.id_dsa_with_sha1, OIWObjectIdentifiers.idSHA1)52 digestOids.put(X9ObjectIdentifiers.id_dsa_with_sha1, OIWObjectIdentifiers.idSHA1); 53 digestOids.put(NISTObjectIdentifiers.dsa_with_sha224, NISTObjectIdentifiers.id_sha224)54 digestOids.put(NISTObjectIdentifiers.dsa_with_sha224, NISTObjectIdentifiers.id_sha224); digestOids.put(NISTObjectIdentifiers.dsa_with_sha256, NISTObjectIdentifiers.id_sha256)55 digestOids.put(NISTObjectIdentifiers.dsa_with_sha256, NISTObjectIdentifiers.id_sha256); digestOids.put(NISTObjectIdentifiers.dsa_with_sha384, NISTObjectIdentifiers.id_sha384)56 digestOids.put(NISTObjectIdentifiers.dsa_with_sha384, NISTObjectIdentifiers.id_sha384); digestOids.put(NISTObjectIdentifiers.dsa_with_sha512, NISTObjectIdentifiers.id_sha512)57 digestOids.put(NISTObjectIdentifiers.dsa_with_sha512, NISTObjectIdentifiers.id_sha512); 58 59 // BEGIN android-removed 60 // digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128, TeleTrusTObjectIdentifiers.ripemd128); 61 // digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160, TeleTrusTObjectIdentifiers.ripemd160); 62 // digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256, TeleTrusTObjectIdentifiers.ripemd256); 63 // 64 // digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, CryptoProObjectIdentifiers.gostR3411); 65 // digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001, CryptoProObjectIdentifiers.gostR3411); 66 // END android-removed 67 68 digestNameToOids.put("SHA-1", OIWObjectIdentifiers.idSHA1); 69 digestNameToOids.put("SHA-224", NISTObjectIdentifiers.id_sha224); 70 digestNameToOids.put("SHA-256", NISTObjectIdentifiers.id_sha256); 71 digestNameToOids.put("SHA-384", NISTObjectIdentifiers.id_sha384); 72 digestNameToOids.put("SHA-512", NISTObjectIdentifiers.id_sha512); 73 74 // BEGIN android-removed 75 // digestNameToOids.put("SHA1", OIWObjectIdentifiers.idSHA1); 76 // digestNameToOids.put("SHA224", NISTObjectIdentifiers.id_sha224); 77 // digestNameToOids.put("SHA256", NISTObjectIdentifiers.id_sha256); 78 // digestNameToOids.put("SHA384", NISTObjectIdentifiers.id_sha384); 79 // digestNameToOids.put("SHA512", NISTObjectIdentifiers.id_sha512); 80 81 // digestNameToOids.put("SHA3-224", NISTObjectIdentifiers.id_sha3_224); 82 // digestNameToOids.put("SHA3-256", NISTObjectIdentifiers.id_sha3_256); 83 // digestNameToOids.put("SHA3-384", NISTObjectIdentifiers.id_sha3_384); 84 // digestNameToOids.put("SHA3-512", NISTObjectIdentifiers.id_sha3_512); 85 // 86 // digestNameToOids.put("SHAKE-128", NISTObjectIdentifiers.id_shake128); 87 // digestNameToOids.put("SHAKE-256", NISTObjectIdentifiers.id_shake256); 88 // 89 // digestNameToOids.put("GOST3411", CryptoProObjectIdentifiers.gostR3411); 90 // 91 // digestNameToOids.put("MD2", PKCSObjectIdentifiers.md2); 92 // digestNameToOids.put("MD4", PKCSObjectIdentifiers.md4); 93 // END android-removed 94 digestNameToOids.put("MD5", PKCSObjectIdentifiers.md5); 95 96 // BEGIN android-removed 97 // digestNameToOids.put("RIPEMD128", TeleTrusTObjectIdentifiers.ripemd128); 98 // digestNameToOids.put("RIPEMD160", TeleTrusTObjectIdentifiers.ripemd160); 99 // digestNameToOids.put("RIPEMD256", TeleTrusTObjectIdentifiers.ripemd256); 100 // END android-removed 101 } 102 find(AlgorithmIdentifier sigAlgId)103 public AlgorithmIdentifier find(AlgorithmIdentifier sigAlgId) 104 { 105 AlgorithmIdentifier digAlgId; 106 107 if (sigAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) 108 { 109 digAlgId = RSASSAPSSparams.getInstance(sigAlgId.getParameters()).getHashAlgorithm(); 110 } 111 else 112 { 113 digAlgId = new AlgorithmIdentifier((ASN1ObjectIdentifier)digestOids.get(sigAlgId.getAlgorithm()), DERNull.INSTANCE); 114 } 115 116 return digAlgId; 117 } 118 find(String digAlgName)119 public AlgorithmIdentifier find(String digAlgName) 120 { 121 return new AlgorithmIdentifier((ASN1ObjectIdentifier)digestNameToOids.get(digAlgName), DERNull.INSTANCE); 122 } 123 } 124