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