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