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 // Android-removed: Unsupported algorithms 9 // import org.bouncycastle.asn1.bc.BCObjectIdentifiers; 10 // import org.bouncycastle.asn1.bsi.BSIObjectIdentifiers; 11 // import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; 12 import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; 13 import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; 14 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 15 import org.bouncycastle.asn1.pkcs.RSASSAPSSparams; 16 import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers; 17 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 18 import org.bouncycastle.asn1.x9.X9ObjectIdentifiers; 19 20 public class DefaultDigestAlgorithmIdentifierFinder 21 implements DigestAlgorithmIdentifierFinder 22 { 23 private static Map digestOids = new HashMap(); 24 private static Map digestNameToOids = new HashMap(); 25 26 static 27 { 28 // 29 // digests 30 // 31 // BEGIN Android-removed: Unsupported algorithms 32 // digestOids.put(OIWObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); 33 // digestOids.put(OIWObjectIdentifiers.md4WithRSA, PKCSObjectIdentifiers.md4); 34 // END Android-removed: Unsupported algorithms 35 digestOids.put(OIWObjectIdentifiers.sha1WithRSA, OIWObjectIdentifiers.idSHA1); 36 37 digestOids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, NISTObjectIdentifiers.id_sha224); 38 digestOids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, NISTObjectIdentifiers.id_sha256); 39 digestOids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, NISTObjectIdentifiers.id_sha384); 40 digestOids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, NISTObjectIdentifiers.id_sha512); 41 // BEGIN Android-removed: Unsupported algorithms 42 // digestOids.put(PKCSObjectIdentifiers.md2WithRSAEncryption, PKCSObjectIdentifiers.md2); 43 // digestOids.put(PKCSObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); 44 // END Android-removed: Unsupported algorithms 45 digestOids.put(PKCSObjectIdentifiers.md5WithRSAEncryption, PKCSObjectIdentifiers.md5); 46 digestOids.put(PKCSObjectIdentifiers.sha1WithRSAEncryption, OIWObjectIdentifiers.idSHA1); 47 48 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, OIWObjectIdentifiers.idSHA1); 49 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, NISTObjectIdentifiers.id_sha224); 50 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, NISTObjectIdentifiers.id_sha256); 51 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, NISTObjectIdentifiers.id_sha384); 52 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, NISTObjectIdentifiers.id_sha512); 53 digestOids.put(X9ObjectIdentifiers.id_dsa_with_sha1, OIWObjectIdentifiers.idSHA1); 54 55 // BEGIN Android-removed: Unsupported algorithms 56 // digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA1, OIWObjectIdentifiers.idSHA1); 57 // digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA224, NISTObjectIdentifiers.id_sha224); 58 // digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA256, NISTObjectIdentifiers.id_sha256); 59 // digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA384, NISTObjectIdentifiers.id_sha384); 60 // digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA512, NISTObjectIdentifiers.id_sha512); 61 // END Android-removed: Unsupported algorithms 62 63 digestOids.put(NISTObjectIdentifiers.dsa_with_sha224, NISTObjectIdentifiers.id_sha224); 64 digestOids.put(NISTObjectIdentifiers.dsa_with_sha256, NISTObjectIdentifiers.id_sha256); 65 digestOids.put(NISTObjectIdentifiers.dsa_with_sha384, NISTObjectIdentifiers.id_sha384); 66 digestOids.put(NISTObjectIdentifiers.dsa_with_sha512, NISTObjectIdentifiers.id_sha512); 67 68 // BEGIN Android-removed: Unsupported algorithms 69 /* 70 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); 71 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); 72 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); 73 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); 74 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); 75 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); 76 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); 77 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); 78 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); 79 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); 80 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); 81 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); 82 83 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128, TeleTrusTObjectIdentifiers.ripemd128); 84 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160, TeleTrusTObjectIdentifiers.ripemd160); 85 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256, TeleTrusTObjectIdentifiers.ripemd256); 86 87 digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, CryptoProObjectIdentifiers.gostR3411); 88 digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001, CryptoProObjectIdentifiers.gostR3411); 89 90 digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA3_512, NISTObjectIdentifiers.id_sha3_512); 91 digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA512, NISTObjectIdentifiers.id_sha512); 92 */ 93 // END Android-removed: Unsupported algorithms 94 95 96 digestNameToOids.put("SHA-1", OIWObjectIdentifiers.idSHA1); 97 digestNameToOids.put("SHA-224", NISTObjectIdentifiers.id_sha224); 98 digestNameToOids.put("SHA-256", NISTObjectIdentifiers.id_sha256); 99 digestNameToOids.put("SHA-384", NISTObjectIdentifiers.id_sha384); 100 digestNameToOids.put("SHA-512", NISTObjectIdentifiers.id_sha512); 101 // BEGIN Android-removed: Unsupported algorithms 102 /* 103 digestNameToOids.put("SHA-512-224", NISTObjectIdentifiers.id_sha512_224); 104 digestNameToOids.put("SHA-512-256", NISTObjectIdentifiers.id_sha512_256); 105 106 digestNameToOids.put("SHA1", OIWObjectIdentifiers.idSHA1); 107 digestNameToOids.put("SHA224", NISTObjectIdentifiers.id_sha224); 108 digestNameToOids.put("SHA256", NISTObjectIdentifiers.id_sha256); 109 digestNameToOids.put("SHA384", NISTObjectIdentifiers.id_sha384); 110 digestNameToOids.put("SHA512", NISTObjectIdentifiers.id_sha512); 111 digestNameToOids.put("SHA512-224", NISTObjectIdentifiers.id_sha512_224); 112 digestNameToOids.put("SHA512-256", NISTObjectIdentifiers.id_sha512_256); 113 114 digestNameToOids.put("SHA3-224", NISTObjectIdentifiers.id_sha3_224); 115 digestNameToOids.put("SHA3-256", NISTObjectIdentifiers.id_sha3_256); 116 digestNameToOids.put("SHA3-384", NISTObjectIdentifiers.id_sha3_384); 117 digestNameToOids.put("SHA3-512", NISTObjectIdentifiers.id_sha3_512); 118 119 digestNameToOids.put("SHAKE-128", NISTObjectIdentifiers.id_shake128); 120 digestNameToOids.put("SHAKE-256", NISTObjectIdentifiers.id_shake256); 121 122 digestNameToOids.put("GOST3411", CryptoProObjectIdentifiers.gostR3411); 123 124 digestNameToOids.put("MD2", PKCSObjectIdentifiers.md2); 125 digestNameToOids.put("MD4", PKCSObjectIdentifiers.md4); 126 */ 127 // END Android-removed: Unsupported algorithms 128 digestNameToOids.put("MD5", PKCSObjectIdentifiers.md5); 129 130 // BEGIN Android-removed: Unsupported algorithms 131 // digestNameToOids.put("RIPEMD128", TeleTrusTObjectIdentifiers.ripemd128); 132 // digestNameToOids.put("RIPEMD160", TeleTrusTObjectIdentifiers.ripemd160); 133 // digestNameToOids.put("RIPEMD256", TeleTrusTObjectIdentifiers.ripemd256); 134 // END Android-removed: Unsupported algorithms 135 } 136 137 public AlgorithmIdentifier find(AlgorithmIdentifier sigAlgId) 138 { 139 AlgorithmIdentifier digAlgId; 140 141 if (sigAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) 142 { 143 digAlgId = RSASSAPSSparams.getInstance(sigAlgId.getParameters()).getHashAlgorithm(); 144 } 145 else 146 { 147 digAlgId = new AlgorithmIdentifier((ASN1ObjectIdentifier)digestOids.get(sigAlgId.getAlgorithm()), DERNull.INSTANCE); 148 } 149 150 return digAlgId; 151 } 152 153 public AlgorithmIdentifier find(String digAlgName) 154 { 155 return new AlgorithmIdentifier((ASN1ObjectIdentifier)digestNameToOids.get(digAlgName), DERNull.INSTANCE); 156 } 157 }