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 import org.bouncycastle.asn1.bc.BCObjectIdentifiers; 10 import org.bouncycastle.asn1.bsi.BSIObjectIdentifiers; 11 import org.bouncycastle.asn1.cms.CMSObjectIdentifiers; 12 import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; 13 import org.bouncycastle.asn1.eac.EACObjectIdentifiers; 14 import org.bouncycastle.asn1.edec.EdECObjectIdentifiers; 15 import org.bouncycastle.asn1.gm.GMObjectIdentifiers; 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 private static Map digestOidToAlgIds = new HashMap(); 31 32 static 33 { 34 // 35 // digests 36 // digestOids.put(OIWObjectIdentifiers.dsaWithSHA1, OIWObjectIdentifiers.idSHA1)37 digestOids.put(OIWObjectIdentifiers.dsaWithSHA1, OIWObjectIdentifiers.idSHA1); digestOids.put(OIWObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4)38 digestOids.put(OIWObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); digestOids.put(OIWObjectIdentifiers.md4WithRSA, PKCSObjectIdentifiers.md4)39 digestOids.put(OIWObjectIdentifiers.md4WithRSA, PKCSObjectIdentifiers.md4); digestOids.put(OIWObjectIdentifiers.sha1WithRSA, OIWObjectIdentifiers.idSHA1)40 digestOids.put(OIWObjectIdentifiers.sha1WithRSA, OIWObjectIdentifiers.idSHA1); 41 digestOids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, NISTObjectIdentifiers.id_sha224)42 digestOids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, NISTObjectIdentifiers.id_sha224); digestOids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, NISTObjectIdentifiers.id_sha256)43 digestOids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, NISTObjectIdentifiers.id_sha256); digestOids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, NISTObjectIdentifiers.id_sha384)44 digestOids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, NISTObjectIdentifiers.id_sha384); digestOids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, NISTObjectIdentifiers.id_sha512)45 digestOids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, NISTObjectIdentifiers.id_sha512); digestOids.put(PKCSObjectIdentifiers.sha512_224WithRSAEncryption, NISTObjectIdentifiers.id_sha512_224)46 digestOids.put(PKCSObjectIdentifiers.sha512_224WithRSAEncryption, NISTObjectIdentifiers.id_sha512_224); digestOids.put(PKCSObjectIdentifiers.sha512_256WithRSAEncryption, NISTObjectIdentifiers.id_sha512_256)47 digestOids.put(PKCSObjectIdentifiers.sha512_256WithRSAEncryption, NISTObjectIdentifiers.id_sha512_256); digestOids.put(PKCSObjectIdentifiers.md2WithRSAEncryption, PKCSObjectIdentifiers.md2)48 digestOids.put(PKCSObjectIdentifiers.md2WithRSAEncryption, PKCSObjectIdentifiers.md2); digestOids.put(PKCSObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4)49 digestOids.put(PKCSObjectIdentifiers.md4WithRSAEncryption, PKCSObjectIdentifiers.md4); digestOids.put(PKCSObjectIdentifiers.md5WithRSAEncryption, PKCSObjectIdentifiers.md5)50 digestOids.put(PKCSObjectIdentifiers.md5WithRSAEncryption, PKCSObjectIdentifiers.md5); digestOids.put(PKCSObjectIdentifiers.sha1WithRSAEncryption, OIWObjectIdentifiers.idSHA1)51 digestOids.put(PKCSObjectIdentifiers.sha1WithRSAEncryption, OIWObjectIdentifiers.idSHA1); 52 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, OIWObjectIdentifiers.idSHA1)53 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, OIWObjectIdentifiers.idSHA1); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, NISTObjectIdentifiers.id_sha224)54 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, NISTObjectIdentifiers.id_sha224); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, NISTObjectIdentifiers.id_sha256)55 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, NISTObjectIdentifiers.id_sha256); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, NISTObjectIdentifiers.id_sha384)56 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, NISTObjectIdentifiers.id_sha384); digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, NISTObjectIdentifiers.id_sha512)57 digestOids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, NISTObjectIdentifiers.id_sha512); digestOids.put(X9ObjectIdentifiers.id_dsa_with_sha1, OIWObjectIdentifiers.idSHA1)58 digestOids.put(X9ObjectIdentifiers.id_dsa_with_sha1, OIWObjectIdentifiers.idSHA1); 59 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA1, OIWObjectIdentifiers.idSHA1)60 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA1, OIWObjectIdentifiers.idSHA1); digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA224, NISTObjectIdentifiers.id_sha224)61 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA224, NISTObjectIdentifiers.id_sha224); digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA256, NISTObjectIdentifiers.id_sha256)62 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA256, NISTObjectIdentifiers.id_sha256); digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA384, NISTObjectIdentifiers.id_sha384)63 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA384, NISTObjectIdentifiers.id_sha384); digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA512, NISTObjectIdentifiers.id_sha512)64 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_SHA512, NISTObjectIdentifiers.id_sha512); digestOids.put(BSIObjectIdentifiers.ecdsa_plain_RIPEMD160, TeleTrusTObjectIdentifiers.ripemd160)65 digestOids.put(BSIObjectIdentifiers.ecdsa_plain_RIPEMD160, TeleTrusTObjectIdentifiers.ripemd160); 66 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_1, OIWObjectIdentifiers.idSHA1)67 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_1, OIWObjectIdentifiers.idSHA1); digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_224, NISTObjectIdentifiers.id_sha224)68 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_224, NISTObjectIdentifiers.id_sha224); digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_256, NISTObjectIdentifiers.id_sha256)69 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_256, NISTObjectIdentifiers.id_sha256); digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_384, NISTObjectIdentifiers.id_sha384)70 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_384, NISTObjectIdentifiers.id_sha384); digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_512, NISTObjectIdentifiers.id_sha512)71 digestOids.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_512, NISTObjectIdentifiers.id_sha512); 72 digestOids.put(NISTObjectIdentifiers.dsa_with_sha224, NISTObjectIdentifiers.id_sha224)73 digestOids.put(NISTObjectIdentifiers.dsa_with_sha224, NISTObjectIdentifiers.id_sha224); digestOids.put(NISTObjectIdentifiers.dsa_with_sha256, NISTObjectIdentifiers.id_sha256)74 digestOids.put(NISTObjectIdentifiers.dsa_with_sha256, NISTObjectIdentifiers.id_sha256); digestOids.put(NISTObjectIdentifiers.dsa_with_sha384, NISTObjectIdentifiers.id_sha384)75 digestOids.put(NISTObjectIdentifiers.dsa_with_sha384, NISTObjectIdentifiers.id_sha384); digestOids.put(NISTObjectIdentifiers.dsa_with_sha512, NISTObjectIdentifiers.id_sha512)76 digestOids.put(NISTObjectIdentifiers.dsa_with_sha512, NISTObjectIdentifiers.id_sha512); 77 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224, NISTObjectIdentifiers.id_sha3_224)78 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256, NISTObjectIdentifiers.id_sha3_256)79 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384, NISTObjectIdentifiers.id_sha3_384)80 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512, NISTObjectIdentifiers.id_sha3_512)81 digestOids.put(NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224)82 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256)83 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384)84 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512)85 digestOids.put(NISTObjectIdentifiers.id_dsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224)86 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_224, NISTObjectIdentifiers.id_sha3_224); digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256)87 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_256, NISTObjectIdentifiers.id_sha3_256); digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384)88 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_384, NISTObjectIdentifiers.id_sha3_384); digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512)89 digestOids.put(NISTObjectIdentifiers.id_ecdsa_with_sha3_512, NISTObjectIdentifiers.id_sha3_512); 90 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128, TeleTrusTObjectIdentifiers.ripemd128)91 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128, TeleTrusTObjectIdentifiers.ripemd128); digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160, TeleTrusTObjectIdentifiers.ripemd160)92 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160, TeleTrusTObjectIdentifiers.ripemd160); digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256, TeleTrusTObjectIdentifiers.ripemd256)93 digestOids.put(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256, TeleTrusTObjectIdentifiers.ripemd256); 94 digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, CryptoProObjectIdentifiers.gostR3411)95 digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, CryptoProObjectIdentifiers.gostR3411); digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001, CryptoProObjectIdentifiers.gostR3411)96 digestOids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001, CryptoProObjectIdentifiers.gostR3411); digestOids.put(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256)97 digestOids.put(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256); digestOids.put(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512)98 digestOids.put(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); 99 digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA3_512, NISTObjectIdentifiers.id_sha3_512)100 digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA3_512, NISTObjectIdentifiers.id_sha3_512); digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA512, NISTObjectIdentifiers.id_sha512)101 digestOids.put(BCObjectIdentifiers.sphincs256_with_SHA512, NISTObjectIdentifiers.id_sha512); 102 103 // digestOids.put(GMObjectIdentifiers.sm2sign_with_rmd160, TeleTrusTObjectIdentifiers.ripemd160); 104 // digestOids.put(GMObjectIdentifiers.sm2sign_with_sha1, OIWObjectIdentifiers.idSHA1); 105 // digestOids.put(GMObjectIdentifiers.sm2sign_with_sha224, NISTObjectIdentifiers.id_sha224); digestOids.put(GMObjectIdentifiers.sm2sign_with_sha256, NISTObjectIdentifiers.id_sha256)106 digestOids.put(GMObjectIdentifiers.sm2sign_with_sha256, NISTObjectIdentifiers.id_sha256); 107 // digestOids.put(GMObjectIdentifiers.sm2sign_with_sha384, NISTObjectIdentifiers.id_sha384); 108 // digestOids.put(GMObjectIdentifiers.sm2sign_with_sha512, NISTObjectIdentifiers.id_sha512); digestOids.put(GMObjectIdentifiers.sm2sign_with_sm3, GMObjectIdentifiers.sm3)109 digestOids.put(GMObjectIdentifiers.sm2sign_with_sm3, GMObjectIdentifiers.sm3); 110 digestOids.put(CMSObjectIdentifiers.id_RSASSA_PSS_SHAKE128, NISTObjectIdentifiers.id_shake128)111 digestOids.put(CMSObjectIdentifiers.id_RSASSA_PSS_SHAKE128, NISTObjectIdentifiers.id_shake128); digestOids.put(CMSObjectIdentifiers.id_RSASSA_PSS_SHAKE256, NISTObjectIdentifiers.id_shake256)112 digestOids.put(CMSObjectIdentifiers.id_RSASSA_PSS_SHAKE256, NISTObjectIdentifiers.id_shake256); digestOids.put(CMSObjectIdentifiers.id_ecdsa_with_shake128, NISTObjectIdentifiers.id_shake128)113 digestOids.put(CMSObjectIdentifiers.id_ecdsa_with_shake128, NISTObjectIdentifiers.id_shake128); digestOids.put(CMSObjectIdentifiers.id_ecdsa_with_shake256, NISTObjectIdentifiers.id_shake256)114 digestOids.put(CMSObjectIdentifiers.id_ecdsa_with_shake256, NISTObjectIdentifiers.id_shake256); 115 116 digestNameToOids.put("SHA-1", OIWObjectIdentifiers.idSHA1); 117 digestNameToOids.put("SHA-224", NISTObjectIdentifiers.id_sha224); 118 digestNameToOids.put("SHA-256", NISTObjectIdentifiers.id_sha256); 119 digestNameToOids.put("SHA-384", NISTObjectIdentifiers.id_sha384); 120 digestNameToOids.put("SHA-512", NISTObjectIdentifiers.id_sha512); 121 digestNameToOids.put("SHA-512-224", NISTObjectIdentifiers.id_sha512_224); 122 digestNameToOids.put("SHA-512-256", NISTObjectIdentifiers.id_sha512_256); 123 124 digestNameToOids.put("SHA1", OIWObjectIdentifiers.idSHA1); 125 digestNameToOids.put("SHA224", NISTObjectIdentifiers.id_sha224); 126 digestNameToOids.put("SHA256", NISTObjectIdentifiers.id_sha256); 127 digestNameToOids.put("SHA384", NISTObjectIdentifiers.id_sha384); 128 digestNameToOids.put("SHA512", NISTObjectIdentifiers.id_sha512); 129 digestNameToOids.put("SHA512-224", NISTObjectIdentifiers.id_sha512_224); 130 digestNameToOids.put("SHA512-256", NISTObjectIdentifiers.id_sha512_256); 131 132 digestNameToOids.put("SHA3-224", NISTObjectIdentifiers.id_sha3_224); 133 digestNameToOids.put("SHA3-256", NISTObjectIdentifiers.id_sha3_256); 134 digestNameToOids.put("SHA3-384", NISTObjectIdentifiers.id_sha3_384); 135 digestNameToOids.put("SHA3-512", NISTObjectIdentifiers.id_sha3_512); 136 137 digestNameToOids.put("SHAKE128", NISTObjectIdentifiers.id_shake128); 138 digestNameToOids.put("SHAKE256", NISTObjectIdentifiers.id_shake256); 139 digestNameToOids.put("SHAKE-128", NISTObjectIdentifiers.id_shake128); 140 digestNameToOids.put("SHAKE-256", NISTObjectIdentifiers.id_shake256); 141 142 digestNameToOids.put("GOST3411", CryptoProObjectIdentifiers.gostR3411); 143 digestNameToOids.put("GOST3411-2012-256", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256); 144 digestNameToOids.put("GOST3411-2012-512", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); 145 146 digestNameToOids.put("MD2", PKCSObjectIdentifiers.md2); 147 digestNameToOids.put("MD4", PKCSObjectIdentifiers.md4); 148 digestNameToOids.put("MD5", PKCSObjectIdentifiers.md5); 149 150 digestNameToOids.put("RIPEMD128", TeleTrusTObjectIdentifiers.ripemd128); 151 digestNameToOids.put("RIPEMD160", TeleTrusTObjectIdentifiers.ripemd160); 152 digestNameToOids.put("RIPEMD256", TeleTrusTObjectIdentifiers.ripemd256); 153 154 digestNameToOids.put("SM3", GMObjectIdentifiers.sm3); 155 156 // IETF RFC 3370 addDigestAlgId(OIWObjectIdentifiers.idSHA1, true)157 addDigestAlgId(OIWObjectIdentifiers.idSHA1, true); 158 // IETF RFC 5754 addDigestAlgId(NISTObjectIdentifiers.id_sha224, false)159 addDigestAlgId(NISTObjectIdentifiers.id_sha224, false); addDigestAlgId(NISTObjectIdentifiers.id_sha256, false)160 addDigestAlgId(NISTObjectIdentifiers.id_sha256, false); addDigestAlgId(NISTObjectIdentifiers.id_sha384, false)161 addDigestAlgId(NISTObjectIdentifiers.id_sha384, false); addDigestAlgId(NISTObjectIdentifiers.id_sha512, false)162 addDigestAlgId(NISTObjectIdentifiers.id_sha512, false); addDigestAlgId(NISTObjectIdentifiers.id_sha512_224, false)163 addDigestAlgId(NISTObjectIdentifiers.id_sha512_224, false); addDigestAlgId(NISTObjectIdentifiers.id_sha512_256, false)164 addDigestAlgId(NISTObjectIdentifiers.id_sha512_256, false); 165 166 // NIST CSOR addDigestAlgId(NISTObjectIdentifiers.id_sha3_224, false)167 addDigestAlgId(NISTObjectIdentifiers.id_sha3_224, false); addDigestAlgId(NISTObjectIdentifiers.id_sha3_256, false)168 addDigestAlgId(NISTObjectIdentifiers.id_sha3_256, false); addDigestAlgId(NISTObjectIdentifiers.id_sha3_384, false)169 addDigestAlgId(NISTObjectIdentifiers.id_sha3_384, false); addDigestAlgId(NISTObjectIdentifiers.id_sha3_512, false)170 addDigestAlgId(NISTObjectIdentifiers.id_sha3_512, false); 171 172 // RFC 8702 addDigestAlgId(NISTObjectIdentifiers.id_shake128, false)173 addDigestAlgId(NISTObjectIdentifiers.id_shake128, false); addDigestAlgId(NISTObjectIdentifiers.id_shake256, false)174 addDigestAlgId(NISTObjectIdentifiers.id_shake256, false); 175 176 // RFC 4357 addDigestAlgId(CryptoProObjectIdentifiers.gostR3411, true)177 addDigestAlgId(CryptoProObjectIdentifiers.gostR3411, true); 178 179 // draft-deremin-rfc4491 addDigestAlgId(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256, false)180 addDigestAlgId(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256, false); addDigestAlgId(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512, false)181 addDigestAlgId(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512, false); 182 183 // IETF RFC 1319 addDigestAlgId(PKCSObjectIdentifiers.md2, true)184 addDigestAlgId(PKCSObjectIdentifiers.md2, true); 185 // IETF RFC 1320 addDigestAlgId(PKCSObjectIdentifiers.md4, true)186 addDigestAlgId(PKCSObjectIdentifiers.md4, true); 187 // IETF RFC 1321 addDigestAlgId(PKCSObjectIdentifiers.md5, true)188 addDigestAlgId(PKCSObjectIdentifiers.md5, true); 189 190 // found no standard which specified the handle of AlgorithmIdentifier.parameters, 191 // so let it as before. addDigestAlgId(TeleTrusTObjectIdentifiers.ripemd128, true)192 addDigestAlgId(TeleTrusTObjectIdentifiers.ripemd128, true); addDigestAlgId(TeleTrusTObjectIdentifiers.ripemd160, true)193 addDigestAlgId(TeleTrusTObjectIdentifiers.ripemd160, true); addDigestAlgId(TeleTrusTObjectIdentifiers.ripemd256, true)194 addDigestAlgId(TeleTrusTObjectIdentifiers.ripemd256, true); 195 } 196 addDigestAlgId(ASN1ObjectIdentifier oid, boolean withNullParams)197 private static void addDigestAlgId(ASN1ObjectIdentifier oid, boolean withNullParams) 198 { 199 AlgorithmIdentifier algId; 200 if (withNullParams) 201 { 202 algId = new AlgorithmIdentifier(oid, DERNull.INSTANCE); 203 } 204 else 205 { 206 algId = new AlgorithmIdentifier(oid); 207 } 208 digestOidToAlgIds.put(oid, algId); 209 } 210 find(AlgorithmIdentifier sigAlgId)211 public AlgorithmIdentifier find(AlgorithmIdentifier sigAlgId) 212 { 213 ASN1ObjectIdentifier sigAlgOid = sigAlgId.getAlgorithm(); 214 215 if (sigAlgOid.equals(EdECObjectIdentifiers.id_Ed448)) 216 { 217 return new AlgorithmIdentifier(NISTObjectIdentifiers.id_shake256_len, new ASN1Integer(512)); 218 } 219 220 ASN1ObjectIdentifier digAlgOid; 221 if (sigAlgOid.equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) 222 { 223 digAlgOid = RSASSAPSSparams.getInstance(sigAlgId.getParameters()).getHashAlgorithm().getAlgorithm(); 224 } 225 else if (sigAlgOid.equals(EdECObjectIdentifiers.id_Ed25519)) 226 { 227 digAlgOid = NISTObjectIdentifiers.id_sha512; 228 } 229 else 230 { 231 digAlgOid = (ASN1ObjectIdentifier)digestOids.get(sigAlgId.getAlgorithm()); 232 } 233 234 return find(digAlgOid); 235 } 236 find(ASN1ObjectIdentifier digAlgOid)237 public AlgorithmIdentifier find(ASN1ObjectIdentifier digAlgOid) 238 { 239 if (digAlgOid == null) 240 { 241 throw new NullPointerException("digest OID is null"); 242 } 243 244 AlgorithmIdentifier digAlgId = (AlgorithmIdentifier)digestOidToAlgIds.get(digAlgOid); 245 if (digAlgId == null) 246 { 247 return new AlgorithmIdentifier(digAlgOid); 248 } 249 else 250 { 251 return digAlgId; 252 } 253 } 254 find(String digAlgName)255 public AlgorithmIdentifier find(String digAlgName) 256 { 257 ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)digestNameToOids.get(digAlgName); 258 if (oid != null) 259 { 260 return find(oid); 261 } 262 try 263 { 264 return find(new ASN1ObjectIdentifier(digAlgName)); 265 } 266 catch (IllegalArgumentException e) 267 { 268 // ignore - tried it but it didn't work... 269 } 270 271 return null; 272 } 273 }