1 package org.bouncycastle.operator; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6 import org.bouncycastle.asn1.ASN1Integer; 7 import org.bouncycastle.asn1.ASN1ObjectIdentifier; 8 import org.bouncycastle.asn1.DERNull; 9 // Android-removed: Unsupported algorithms 10 // import org.bouncycastle.asn1.bc.BCObjectIdentifiers; 11 // import org.bouncycastle.asn1.bsi.BSIObjectIdentifiers; 12 // import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; 13 // import org.bouncycastle.asn1.eac.EACObjectIdentifiers; 14 // import org.bouncycastle.asn1.gm.GMObjectIdentifiers; 15 // import org.bouncycastle.asn1.edec.EdECObjectIdentifiers; 16 import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; 17 import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; 18 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 19 import org.bouncycastle.asn1.pkcs.RSASSAPSSparams; 20 // import org.bouncycastle.asn1.rosstandart.RosstandartObjectIdentifiers; 21 // import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers; 22 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 23 import org.bouncycastle.asn1.x9.X9ObjectIdentifiers; 24 25 public class DefaultDigestAlgorithmIdentifierFinder 26 implements DigestAlgorithmIdentifierFinder 27 { 28 private static Map digestOids = new HashMap(); 29 private static Map digestNameToOids = new HashMap(); 30 31 static 32 { 33 // 34 // digests 35 // 36 // BEGIN Android-removed: Unsupported algorithms 37 // digestOids.put(OIWObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); 38 // digestOids.put(OIWObjectIdentifiers.md4WithRSA, PKCSObjectIdentifiers.md4); 39 // digestOids.put(OIWObjectIdentifiers.dsaWithSHA1, OIWObjectIdentifiers.idSHA1); 40 // END Android-removed: Unsupported algorithms digestOids.put(OIWObjectIdentifiers.sha1WithRSA, OIWObjectIdentifiers.idSHA1)41 digestOids.put(OIWObjectIdentifiers.sha1WithRSA, OIWObjectIdentifiers.idSHA1); 42 digestOids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, NISTObjectIdentifiers.id_sha224)43 digestOids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, NISTObjectIdentifiers.id_sha224); digestOids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, NISTObjectIdentifiers.id_sha256)44 digestOids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, NISTObjectIdentifiers.id_sha256); digestOids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, NISTObjectIdentifiers.id_sha384)45 digestOids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, NISTObjectIdentifiers.id_sha384); digestOids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, NISTObjectIdentifiers.id_sha512)46 digestOids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, NISTObjectIdentifiers.id_sha512); 47 // BEGIN Android-removed: Unsupported algorithms 48 // digestOids.put(PKCSObjectIdentifiers.md2WithRSAEncryption, PKCSObjectIdentifiers.md2); 49 // digestOids.put(PKCSObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); 50 // END Android-removed: Unsupported algorithms digestOids.put(PKCSObjectIdentifiers.md5WithRSAEncryption, PKCSObjectIdentifiers.md5)51 digestOids.put(PKCSObjectIdentifiers.md5WithRSAEncryption, PKCSObjectIdentifiers.md5); digestOids.put(PKCSObjectIdentifiers.sha1WithRSAEncryption, OIWObjectIdentifiers.idSHA1)52 digestOids.put(PKCSObjectIdentifiers.sha1WithRSAEncryption, OIWObjectIdentifiers.idSHA1); 53 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, OIWObjectIdentifiers.idSHA1)54 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, OIWObjectIdentifiers.idSHA1); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, NISTObjectIdentifiers.id_sha224)55 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, NISTObjectIdentifiers.id_sha224); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, NISTObjectIdentifiers.id_sha256)56 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, NISTObjectIdentifiers.id_sha256); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, NISTObjectIdentifiers.id_sha384)57 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, NISTObjectIdentifiers.id_sha384); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, NISTObjectIdentifiers.id_sha512)58 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, NISTObjectIdentifiers.id_sha512); digestOids.put(X9ObjectIdentifiers.id_dsa_with_sha1, OIWObjectIdentifiers.idSHA1)59 digestOids.put(X9ObjectIdentifiers.id_dsa_with_sha1, OIWObjectIdentifiers.idSHA1); 60 61 // BEGIN Android-removed: Unsupported algorithms 62 /* 63 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA1, OIWObjectIdentifiers.idSHA1); 64 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA224, NISTObjectIdentifiers.id_sha224); 65 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA256, NISTObjectIdentifiers.id_sha256); 66 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA384, NISTObjectIdentifiers.id_sha384); 67 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA512, NISTObjectIdentifiers.id_sha512); 68 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_RIPEMD160, TeleTrusTObjectIdentifiers.ripemd160); 69 70 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_1, OIWObjectIdentifiers.idSHA1); 71 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_224, NISTObjectIdentifiers.id_sha224); 72 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_256, NISTObjectIdentifiers.id_sha256); 73 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_384, NISTObjectIdentifiers.id_sha384); 74 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_512, NISTObjectIdentifiers.id_sha512); 75 */ 76 // END Android-removed: Unsupported algorithms 77 digestOids.put(NISTObjectIdentifiers.dsa_with_sha224, NISTObjectIdentifiers.id_sha224)78 digestOids.put(NISTObjectIdentifiers.dsa_with_sha224, NISTObjectIdentifiers.id_sha224); digestOids.put(NISTObjectIdentifiers.dsa_with_sha256, NISTObjectIdentifiers.id_sha256)79 digestOids.put(NISTObjectIdentifiers.dsa_with_sha256, NISTObjectIdentifiers.id_sha256); digestOids.put(NISTObjectIdentifiers.dsa_with_sha384, NISTObjectIdentifiers.id_sha384)80 digestOids.put(NISTObjectIdentifiers.dsa_with_sha384, NISTObjectIdentifiers.id_sha384); digestOids.put(NISTObjectIdentifiers.dsa_with_sha512, NISTObjectIdentifiers.id_sha512)81 digestOids.put(NISTObjectIdentifiers.dsa_with_sha512, NISTObjectIdentifiers.id_sha512); 82 83 // BEGIN Android-removed: Unsupported algorithms 84 /* 85 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); 86 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); 87 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); 88 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); 89 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); 90 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); 91 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); 92 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); 93 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); 94 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); 95 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); 96 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); 97 98 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128, TeleTrusTObjectIdentifiers.ripemd128); 99 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160, TeleTrusTObjectIdentifiers.ripemd160); 100 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256, TeleTrusTObjectIdentifiers.ripemd256); 101 102 digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, CryptoProObjectIdentifiers.gostR3411); 103 digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001, CryptoProObjectIdentifiers.gostR3411); 104 digestOids.put(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256); 105 digestOids.put(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); 106 107 digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA3_512, NISTObjectIdentifiers.id_sha3_512); 108 digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA512, NISTObjectIdentifiers.id_sha512); 109 110 digestOids.put(GMObjectIdentifiers.sm2sign_with_rmd160, TeleTrusTObjectIdentifiers.ripemd160); 111 digestOids.put(GMObjectIdentifiers.sm2sign_with_sha1, OIWObjectIdentifiers.idSHA1); 112 digestOids.put(GMObjectIdentifiers.sm2sign_with_sha224, NISTObjectIdentifiers.id_sha224); 113 digestOids.put(GMObjectIdentifiers.sm2sign_with_sha256, NISTObjectIdentifiers.id_sha256); 114 digestOids.put(GMObjectIdentifiers.sm2sign_with_sha384, NISTObjectIdentifiers.id_sha384); 115 digestOids.put(GMObjectIdentifiers.sm2sign_with_sha512, NISTObjectIdentifiers.id_sha512); 116 digestOids.put(GMObjectIdentifiers.sm2sign_with_sm3, GMObjectIdentifiers.sm3); 117 */ 118 // END Android-removed: Unsupported algorithms 119 120 digestNameToOids.put("SHA-1", OIWObjectIdentifiers.idSHA1); 121 digestNameToOids.put("SHA-224", NISTObjectIdentifiers.id_sha224); 122 digestNameToOids.put("SHA-256", NISTObjectIdentifiers.id_sha256); 123 digestNameToOids.put("SHA-384", NISTObjectIdentifiers.id_sha384); 124 digestNameToOids.put("SHA-512", NISTObjectIdentifiers.id_sha512); 125 // BEGIN Android-removed: Unsupported algorithms 126 /* 127 digestNameToOids.put("SHA-512-224", NISTObjectIdentifiers.id_sha512_224); 128 digestNameToOids.put("SHA-512-256", NISTObjectIdentifiers.id_sha512_256); 129 130 digestNameToOids.put("SHA1", OIWObjectIdentifiers.idSHA1); 131 digestNameToOids.put("SHA224", NISTObjectIdentifiers.id_sha224); 132 digestNameToOids.put("SHA256", NISTObjectIdentifiers.id_sha256); 133 digestNameToOids.put("SHA384", NISTObjectIdentifiers.id_sha384); 134 digestNameToOids.put("SHA512", NISTObjectIdentifiers.id_sha512); 135 digestNameToOids.put("SHA512-224", NISTObjectIdentifiers.id_sha512_224); 136 digestNameToOids.put("SHA512-256", NISTObjectIdentifiers.id_sha512_256); 137 138 digestNameToOids.put("SHA3-224", NISTObjectIdentifiers.id_sha3_224); 139 digestNameToOids.put("SHA3-256", NISTObjectIdentifiers.id_sha3_256); 140 digestNameToOids.put("SHA3-384", NISTObjectIdentifiers.id_sha3_384); 141 digestNameToOids.put("SHA3-512", NISTObjectIdentifiers.id_sha3_512); 142 143 digestNameToOids.put("SHAKE-128", NISTObjectIdentifiers.id_shake128); 144 digestNameToOids.put("SHAKE-256", NISTObjectIdentifiers.id_shake256); 145 146 digestNameToOids.put("GOST3411", CryptoProObjectIdentifiers.gostR3411); 147 digestNameToOids.put("GOST3411-2012-256", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256); 148 digestNameToOids.put("GOST3411-2012-512", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); 149 150 digestNameToOids.put("MD2", PKCSObjectIdentifiers.md2); 151 digestNameToOids.put("MD4", PKCSObjectIdentifiers.md4); 152 */ 153 // END Android-removed: Unsupported algorithms 154 digestNameToOids.put("MD5", PKCSObjectIdentifiers.md5); 155 156 // BEGIN Android-removed: Unsupported algorithms 157 /* 158 digestNameToOids.put("RIPEMD128", TeleTrusTObjectIdentifiers.ripemd128); 159 digestNameToOids.put("RIPEMD160", TeleTrusTObjectIdentifiers.ripemd160); 160 digestNameToOids.put("RIPEMD256", TeleTrusTObjectIdentifiers.ripemd256); 161 162 digestNameToOids.put("SM3", GMObjectIdentifiers.sm3); 163 */ 164 // END Android-removed: Unsupported algorithms 165 } 166 find(AlgorithmIdentifier sigAlgId)167 public AlgorithmIdentifier find(AlgorithmIdentifier sigAlgId) 168 { 169 AlgorithmIdentifier digAlgId; 170 171 if (sigAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) 172 { 173 digAlgId = RSASSAPSSparams.getInstance(sigAlgId.getParameters()).getHashAlgorithm(); 174 } 175 // BEGIN Android-removed: Unsupported algorithms 176 /* 177 else if (sigAlgId.getAlgorithm().equals(EdECObjectIdentifiers.id_Ed25519)) 178 { 179 digAlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha512); 180 } 181 else if (sigAlgId.getAlgorithm().equals(EdECObjectIdentifiers.id_Ed448)) 182 { 183 digAlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_shake256_len, new ASN1Integer(512)); 184 } 185 */ 186 // END Android-removed: Unsupported algorithms 187 else 188 { 189 digAlgId = new AlgorithmIdentifier((ASN1ObjectIdentifier)digestOids.get(sigAlgId.getAlgorithm()), DERNull.INSTANCE); 190 } 191 192 return digAlgId; 193 } 194 find(String digAlgName)195 public AlgorithmIdentifier find(String digAlgName) 196 { 197 return new AlgorithmIdentifier((ASN1ObjectIdentifier)digestNameToOids.get(digAlgName), DERNull.INSTANCE); 198 } 199 }