Home | History | Annotate | Download | only in patches
      1 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/ASN1Null.java bcprov-jdk15on-147/org/bouncycastle/asn1/ASN1Null.java
      2 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/ASN1Null.java	2012-03-22 15:11:48.000000000 +0000
      3 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/ASN1Null.java	2012-09-19 21:17:12.000000000 +0000
      4 @@ -8,9 +8,11 @@
      5  public abstract class ASN1Null
      6      extends ASN1Primitive
      7  {
      8 -    public ASN1Null()
      9 +    // BEGIN android-changed
     10 +    /*package*/ ASN1Null()
     11      {
     12      }
     13 +    // END android-changed
     14  
     15      public static ASN1Null getInstance(Object o)
     16      {
     17 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERBoolean.java bcprov-jdk15on-147/org/bouncycastle/asn1/DERBoolean.java
     18 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERBoolean.java	2012-03-22 15:11:48.000000000 +0000
     19 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/DERBoolean.java	2012-09-19 21:17:12.000000000 +0000
     20 @@ -10,7 +10,9 @@
     21      private static final byte[] TRUE_VALUE = new byte[] { (byte)0xff };
     22      private static final byte[] FALSE_VALUE = new byte[] { 0 };
     23  
     24 -    private byte[]         value;
     25 +    // BEGIN android-changed
     26 +    final private byte[]         value;
     27 +    // END android-changed
     28  
     29      public static final ASN1Boolean FALSE = new ASN1Boolean(false);
     30      public static final ASN1Boolean TRUE  = new ASN1Boolean(true);
     31 @@ -46,6 +48,17 @@
     32          return (value ? TRUE : FALSE);
     33      }
     34  
     35 +    // BEGIN android-added
     36 +    /**
     37 +     * return a DERBoolean from the passed in array.
     38 +     */
     39 +    public static DERBoolean getInstance(
     40 +        byte[] octets)
     41 +    {
     42 +        return (octets[0] != 0) ? TRUE : FALSE;
     43 +    }
     44 +
     45 +    // END android-added
     46      /**
     47       * return a Boolean from a tagged object.
     48       *
     49 @@ -71,7 +84,9 @@
     50          }
     51      }
     52      
     53 -    DERBoolean(
     54 +    // BEGIN android-changed
     55 +    protected DERBoolean(
     56 +    // END android-changed
     57          byte[]       value)
     58      {
     59          if (value.length != 1)
     60 @@ -93,8 +108,10 @@
     61          }
     62      }
     63  
     64 -    public DERBoolean(
     65 +    // BEGIN android-changed
     66 +    protected DERBoolean(
     67          boolean     value)
     68 +    // END android-changed
     69      {
     70          this.value = (value) ? TRUE_VALUE : FALSE_VALUE;
     71      }
     72 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERNull.java bcprov-jdk15on-147/org/bouncycastle/asn1/DERNull.java
     73 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERNull.java	2012-03-22 15:11:48.000000000 +0000
     74 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/DERNull.java	2012-09-19 21:17:12.000000000 +0000
     75 @@ -12,7 +12,9 @@
     76  
     77      private static final byte[]  zeroBytes = new byte[0];
     78  
     79 -    public DERNull()
     80 +    // BEGIN android-changed
     81 +    protected DERNull()
     82 +    // END android-changed
     83      {
     84      }
     85  
     86 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERObjectIdentifier.java bcprov-jdk15on-147/org/bouncycastle/asn1/DERObjectIdentifier.java
     87 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERObjectIdentifier.java	2012-03-22 15:11:48.000000000 +0000
     88 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/DERObjectIdentifier.java	2012-09-19 21:17:12.000000000 +0000
     89 @@ -117,7 +117,13 @@
     90              }
     91          }
     92  
     93 -        this.identifier = objId.toString();
     94 +        // BEGIN android-changed
     95 +        /*
     96 +         * Intern the identifier so there aren't hundreds of duplicates
     97 +         * (in practice).
     98 +         */
     99 +        this.identifier = objId.toString().intern();
    100 +        // END android-changed
    101      }
    102  
    103      public DERObjectIdentifier(
    104 @@ -128,7 +134,13 @@
    105              throw new IllegalArgumentException("string " + identifier + " not an OID");
    106          }
    107  
    108 -        this.identifier = identifier;
    109 +        // BEGIN android-changed
    110 +        /*
    111 +         * Intern the identifier so there aren't hundreds of duplicates
    112 +         * (in practice).
    113 +         */
    114 +        this.identifier = identifier.intern();
    115 +        // END android-changed
    116      }
    117  
    118      public String getId()
    119 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERPrintableString.java bcprov-jdk15on-147/org/bouncycastle/asn1/DERPrintableString.java
    120 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/DERPrintableString.java	2012-03-22 15:11:48.000000000 +0000
    121 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/DERPrintableString.java	2012-09-19 21:17:12.000000000 +0000
    122 @@ -12,7 +12,9 @@
    123      extends ASN1Primitive
    124      implements ASN1String
    125  {
    126 -    private byte[]  string;
    127 +    // BEGIN android-changed
    128 +    private final byte[]  string;
    129 +    // END android-changed
    130  
    131      /**
    132       * return a printable string from the passed in object.
    133 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/cms/ContentInfo.java bcprov-jdk15on-147/org/bouncycastle/asn1/cms/ContentInfo.java
    134 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/cms/ContentInfo.java	2012-03-22 15:11:48.000000000 +0000
    135 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/cms/ContentInfo.java	2012-09-19 21:17:12.000000000 +0000
    136 @@ -12,7 +12,9 @@
    137  
    138  public class ContentInfo
    139      extends ASN1Object
    140 -    implements CMSObjectIdentifiers
    141 +    // BEGIN android-removed
    142 +    // implements CMSObjectIdentifiers
    143 +    // END android-removed
    144  {
    145      private ASN1ObjectIdentifier contentType;
    146      private ASN1Encodable        content;
    147 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/EncryptedPrivateKeyInfo.java bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/EncryptedPrivateKeyInfo.java
    148 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/EncryptedPrivateKeyInfo.java	2012-03-22 15:11:48.000000000 +0000
    149 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/EncryptedPrivateKeyInfo.java	2012-09-19 21:17:12.000000000 +0000
    150 @@ -37,10 +37,13 @@
    151      public static EncryptedPrivateKeyInfo getInstance(
    152          Object  obj)
    153      {
    154 -        if (obj instanceof EncryptedData)
    155 +        // BEGIN android-changed
    156 +        //     fix copy and paste error in instanceof call
    157 +        if (obj instanceof EncryptedPrivateKeyInfo)
    158          {
    159              return (EncryptedPrivateKeyInfo)obj;
    160          }
    161 +        // END android-changed
    162          else if (obj != null)
    163          { 
    164              return new EncryptedPrivateKeyInfo(ASN1Sequence.getInstance(obj));
    165 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java
    166 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java	2012-03-22 15:11:48.000000000 +0000
    167 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java	2012-09-19 21:17:12.000000000 +0000
    168 @@ -10,8 +10,10 @@
    169      //
    170      static final ASN1ObjectIdentifier    pkcs_1                    = new ASN1ObjectIdentifier("1.2.840.113549.1.1");
    171      static final ASN1ObjectIdentifier    rsaEncryption             = pkcs_1.branch("1");
    172 -    static final ASN1ObjectIdentifier    md2WithRSAEncryption      = pkcs_1.branch("2");
    173 -    static final ASN1ObjectIdentifier    md4WithRSAEncryption      = pkcs_1.branch("3");
    174 +    // BEGIN android-removed
    175 +    // static final ASN1ObjectIdentifier    md2WithRSAEncryption      = pkcs_1.branch("2");
    176 +    // static final ASN1ObjectIdentifier    md4WithRSAEncryption      = pkcs_1.branch("3");
    177 +    // END android-removed
    178      static final ASN1ObjectIdentifier    md5WithRSAEncryption      = pkcs_1.branch("4");
    179      static final ASN1ObjectIdentifier    sha1WithRSAEncryption     = pkcs_1.branch("5");
    180      static final ASN1ObjectIdentifier    srsaOAEPEncryptionSET     = pkcs_1.branch("6");
    181 @@ -22,7 +24,9 @@
    182      static final ASN1ObjectIdentifier    sha256WithRSAEncryption   = pkcs_1.branch("11");
    183      static final ASN1ObjectIdentifier    sha384WithRSAEncryption   = pkcs_1.branch("12");
    184      static final ASN1ObjectIdentifier    sha512WithRSAEncryption   = pkcs_1.branch("13");
    185 -    static final ASN1ObjectIdentifier    sha224WithRSAEncryption   = pkcs_1.branch("14");
    186 +    // BEGIN android-removed
    187 +    // static final ASN1ObjectIdentifier    sha224WithRSAEncryption   = pkcs_1.branch("14");
    188 +    // END android-removed
    189  
    190      //
    191      // pkcs-3 OBJECT IDENTIFIER ::= {
    192 @@ -65,13 +69,17 @@
    193      // md2 OBJECT IDENTIFIER ::=
    194      //      {iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) 2}
    195      //
    196 -    static final ASN1ObjectIdentifier    md2                    = digestAlgorithm.branch("2");
    197 +    // BEGIN android-removed
    198 +    // static final ASN1ObjectIdentifier    md2                    = digestAlgorithm.branch("2");
    199 +    // END android-removed
    200  
    201      //
    202      // md4 OBJECT IDENTIFIER ::=
    203      //      {iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) 4}
    204      //
    205 -    static final ASN1ObjectIdentifier    md4 = digestAlgorithm.branch("4");
    206 +    // BEGIN android-removed
    207 +    // static final ASN1ObjectIdentifier    md4 = digestAlgorithm.branch("4");
    208 +    // END android-removed
    209  
    210      //
    211      // md5 OBJECT IDENTIFIER ::=
    212 @@ -80,7 +88,9 @@
    213      static final ASN1ObjectIdentifier    md5                     = digestAlgorithm.branch("5");
    214  
    215      static final ASN1ObjectIdentifier    id_hmacWithSHA1         = digestAlgorithm.branch("7");
    216 -    static final ASN1ObjectIdentifier    id_hmacWithSHA224       = digestAlgorithm.branch("8");
    217 +    // BEGIN android-removed
    218 +    // static final ASN1ObjectIdentifier    id_hmacWithSHA224       = digestAlgorithm.branch("8");
    219 +    // END android-removed
    220      static final ASN1ObjectIdentifier    id_hmacWithSHA256       = digestAlgorithm.branch("9");
    221      static final ASN1ObjectIdentifier    id_hmacWithSHA384       = digestAlgorithm.branch("10");
    222      static final ASN1ObjectIdentifier    id_hmacWithSHA512       = digestAlgorithm.branch("11");
    223 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java
    224 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java	2012-03-22 15:11:48.000000000 +0000
    225 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/RSAESOAEPparams.java	2012-09-19 21:17:12.000000000 +0000
    226 @@ -19,7 +19,9 @@
    227      private AlgorithmIdentifier maskGenAlgorithm;
    228      private AlgorithmIdentifier pSourceAlgorithm;
    229      
    230 -    public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, new DERNull());
    231 +    // BEGIN android-changed
    232 +    public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
    233 +    // END android-changed
    234      public final static AlgorithmIdentifier DEFAULT_MASK_GEN_FUNCTION = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, DEFAULT_HASH_ALGORITHM);
    235      public final static AlgorithmIdentifier DEFAULT_P_SOURCE_ALGORITHM = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(new byte[0]));
    236      
    237 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java
    238 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java	2012-03-22 15:11:48.000000000 +0000
    239 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/pkcs/RSASSAPSSparams.java	2012-09-19 21:17:12.000000000 +0000
    240 @@ -22,7 +22,9 @@
    241      private ASN1Integer          saltLength;
    242      private ASN1Integer          trailerField;
    243      
    244 -    public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, new DERNull());
    245 +    // BEGIN android-changed
    246 +    public final static AlgorithmIdentifier DEFAULT_HASH_ALGORITHM = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
    247 +    // END android-changed
    248      public final static AlgorithmIdentifier DEFAULT_MASK_GEN_FUNCTION = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, DEFAULT_HASH_ALGORITHM);
    249      public final static ASN1Integer          DEFAULT_SALT_LENGTH = new ASN1Integer(20);
    250      public final static ASN1Integer          DEFAULT_TRAILER_FIELD = new ASN1Integer(1);
    251 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/util/ASN1Dump.java bcprov-jdk15on-147/org/bouncycastle/asn1/util/ASN1Dump.java
    252 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/util/ASN1Dump.java	2012-03-22 15:11:48.000000000 +0000
    253 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/util/ASN1Dump.java	2012-09-19 21:17:12.000000000 +0000
    254 @@ -78,7 +78,9 @@
    255              {
    256                  Object  o = e.nextElement();
    257  
    258 -                if (o == null || o.equals(new DERNull()))
    259 +                // BEGIN android-changed
    260 +                if (o == null || o.equals(DERNull.INSTANCE))
    261 +                // END android-changed
    262                  {
    263                      buf.append(tab);
    264                      buf.append("NULL");
    265 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/AttCertIssuer.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/AttCertIssuer.java
    266 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/AttCertIssuer.java	2012-03-22 15:11:48.000000000 +0000
    267 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/AttCertIssuer.java	2012-09-19 21:17:12.000000000 +0000
    268 @@ -46,7 +46,7 @@
    269          ASN1TaggedObject obj,
    270          boolean          explicit)
    271      {
    272 -        return getInstance(obj.getObject()); // must be explictly tagged
    273 +        return getInstance(obj.getObject()); // must be explicitly tagged
    274      }
    275  
    276      /**
    277 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java
    278 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java	2012-03-22 15:11:48.000000000 +0000
    279 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java	2012-09-19 21:17:12.000000000 +0000
    280 @@ -14,7 +14,9 @@
    281  import org.bouncycastle.asn1.DERSequence;
    282  import org.bouncycastle.asn1.DERTaggedObject;
    283  import org.bouncycastle.crypto.Digest;
    284 -import org.bouncycastle.crypto.digests.SHA1Digest;
    285 +// BEGIN android-changed
    286 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
    287 +// END android-changed
    288  
    289  /**
    290   * The AuthorityKeyIdentifier object.
    291 @@ -101,7 +103,9 @@
    292      public AuthorityKeyIdentifier(
    293          SubjectPublicKeyInfo    spki)
    294      {
    295 -        Digest  digest = new SHA1Digest();
    296 +        // BEGIN android-changed
    297 +        Digest  digest = AndroidDigestFactory.getSHA1();
    298 +        // END android-changed
    299          byte[]  resBuf = new byte[digest.getDigestSize()];
    300  
    301          byte[] bytes = spki.getPublicKeyData().getBytes();
    302 @@ -119,7 +123,9 @@
    303          GeneralNames            name,
    304          BigInteger              serialNumber)
    305      {
    306 -        Digest  digest = new SHA1Digest();
    307 +        // BEGIN android-changed
    308 +        Digest  digest = AndroidDigestFactory.getSHA1();
    309 +        // END android-changed
    310          byte[]  resBuf = new byte[digest.getDigestSize()];
    311  
    312          byte[] bytes = spki.getPublicKeyData().getBytes();
    313 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/BasicConstraints.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/BasicConstraints.java
    314 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/BasicConstraints.java	2012-03-22 15:11:48.000000000 +0000
    315 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/BasicConstraints.java	2012-09-19 21:17:12.000000000 +0000
    316 @@ -14,7 +14,9 @@
    317  public class BasicConstraints
    318      extends ASN1Object
    319  {
    320 -    DERBoolean  cA = new DERBoolean(false);
    321 +    // BEGIN android-changed
    322 +    DERBoolean  cA = DERBoolean.FALSE;
    323 +    // END android-changed
    324      ASN1Integer  pathLenConstraint = null;
    325  
    326      public static BasicConstraints getInstance(
    327 @@ -81,7 +83,9 @@
    328      {
    329          if (cA)
    330          {
    331 -            this.cA = new DERBoolean(true);
    332 +            // BEGIN android-changed
    333 +            this.cA = DERBoolean.TRUE;
    334 +            // END android-changed
    335          }
    336          else
    337          {
    338 @@ -98,7 +102,9 @@
    339      public BasicConstraints(
    340          int     pathLenConstraint)
    341      {
    342 -        this.cA = new DERBoolean(true);
    343 +        // BEGIN android-changed
    344 +        this.cA = DERBoolean.TRUE;
    345 +        // END android-changed
    346          this.pathLenConstraint = new ASN1Integer(pathLenConstraint);
    347      }
    348  
    349 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/CRLReason.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/CRLReason.java
    350 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/CRLReason.java	2012-03-22 15:11:48.000000000 +0000
    351 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/CRLReason.java	2012-09-19 21:17:12.000000000 +0000
    352 @@ -138,7 +138,9 @@
    353  
    354      public static CRLReason lookup(int value)
    355      {
    356 -        Integer idx = new Integer(value);
    357 +        // BEGIN android-changed
    358 +        Integer idx = Integer.valueOf(value);
    359 +        // END android-changed
    360  
    361          if (!table.containsKey(idx))
    362          {
    363 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java
    364 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java	2012-03-22 15:11:48.000000000 +0000
    365 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/IssuingDistributionPoint.java	2012-09-19 21:17:12.000000000 +0000
    366 @@ -96,11 +96,15 @@
    367          }
    368          if (onlyContainsUserCerts)
    369          {
    370 -            vec.add(new DERTaggedObject(false, 1, new DERBoolean(true)));
    371 +            // BEGIN android-changed
    372 +            vec.add(new DERTaggedObject(false, 1, DERBoolean.TRUE));
    373 +            // END android-changed
    374          }
    375          if (onlyContainsCACerts)
    376          {
    377 -            vec.add(new DERTaggedObject(false, 2, new DERBoolean(true)));
    378 +            // BEGIN android-changed
    379 +            vec.add(new DERTaggedObject(false, 2, DERBoolean.TRUE));
    380 +            // END android-changed
    381          }
    382          if (onlySomeReasons != null)
    383          {
    384 @@ -108,11 +112,15 @@
    385          }
    386          if (indirectCRL)
    387          {
    388 -            vec.add(new DERTaggedObject(false, 4, new DERBoolean(true)));
    389 +            // BEGIN android-changed
    390 +            vec.add(new DERTaggedObject(false, 4, DERBoolean.TRUE));
    391 +            // END android-changed
    392          }
    393          if (onlyContainsAttributeCerts)
    394          {
    395 -            vec.add(new DERTaggedObject(false, 5, new DERBoolean(true)));
    396 +            // BEGIN android-changed
    397 +            vec.add(new DERTaggedObject(false, 5, DERBoolean.TRUE));
    398 +            // END android-changed
    399          }
    400  
    401          seq = new DERSequence(vec);
    402 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java
    403 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java	2012-03-22 15:11:48.000000000 +0000
    404 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java	2012-09-19 21:17:12.000000000 +0000
    405 @@ -6,7 +6,9 @@
    406  import org.bouncycastle.asn1.ASN1TaggedObject;
    407  import org.bouncycastle.asn1.DEROctetString;
    408  import org.bouncycastle.crypto.Digest;
    409 -import org.bouncycastle.crypto.digests.SHA1Digest;
    410 +// BEGIN android-changed
    411 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
    412 +// END android-changed
    413  
    414  /**
    415   * The SubjectKeyIdentifier object.
    416 @@ -119,7 +121,9 @@
    417  
    418      private static byte[] getDigest(SubjectPublicKeyInfo spki)
    419      {
    420 -        Digest digest = new SHA1Digest();
    421 +        // BEGIN android-changed
    422 +        Digest digest = AndroidDigestFactory.getSHA1();
    423 +        // END android-changed
    424          byte[]  resBuf = new byte[digest.getDigestSize()];
    425  
    426          byte[] bytes = spki.getPublicKeyData().getBytes();
    427 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/X509Extensions.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/X509Extensions.java
    428 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/X509Extensions.java	2012-03-22 15:11:48.000000000 +0000
    429 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/X509Extensions.java	2012-09-19 21:17:12.000000000 +0000
    430 @@ -408,7 +408,9 @@
    431  
    432              if (ext.isCritical())
    433              {
    434 -                v.add(new DERBoolean(true));
    435 +                // BEGIN android-changed
    436 +                v.add(DERBoolean.TRUE);
    437 +                // END android-changed
    438              }
    439  
    440              v.add(ext.getValue());
    441 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/X509Name.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/X509Name.java
    442 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/X509Name.java	2012-03-22 15:11:48.000000000 +0000
    443 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/X509Name.java	2012-09-19 21:17:12.000000000 +0000
    444 @@ -255,8 +255,10 @@
    445       */
    446      public static final Hashtable SymbolLookUp = DefaultLookUp;
    447  
    448 -    private static final Boolean TRUE = new Boolean(true); // for J2ME compatibility
    449 -    private static final Boolean FALSE = new Boolean(false);
    450 +    // BEGIN android-changed
    451 +    private static final Boolean TRUE = Boolean.TRUE;
    452 +    private static final Boolean FALSE = Boolean.FALSE;
    453 +    // END android-changed
    454  
    455      static
    456      {
    457 @@ -445,7 +447,9 @@
    458                             throw new IllegalArgumentException("cannot encode value");
    459                         }
    460                     }
    461 -                   added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
    462 +                   // BEGIN android-changed
    463 +                   added.addElement(Boolean.valueOf(i != 0));
    464 +                   // END android-changed
    465              }
    466          }
    467      }
    468 @@ -702,7 +706,9 @@
    469  
    470              if (index == -1)
    471              {
    472 -                throw new IllegalArgumentException("badly formated directory string");
    473 +                // BEGIN android-changed
    474 +                throw new IllegalArgumentException("badly formatted directory string");
    475 +                // END android-changed
    476              }
    477  
    478              String              name = token.substring(0, index);
    479 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/X509NameTokenizer.java bcprov-jdk15on-147/org/bouncycastle/asn1/x509/X509NameTokenizer.java
    480 --- bcprov-jdk15on-147.orig/org/bouncycastle/asn1/x509/X509NameTokenizer.java	2012-03-22 15:11:48.000000000 +0000
    481 +++ bcprov-jdk15on-147/org/bouncycastle/asn1/x509/X509NameTokenizer.java	2012-09-19 21:17:12.000000000 +0000
    482 @@ -58,6 +58,17 @@
    483                  }
    484                  else
    485                  {
    486 +                    // BEGIN android-added
    487 +                    // copied from a newer version of BouncyCastle
    488 +                    if (c == '#' && buf.charAt(buf.length() - 1) == '=')
    489 +                    {
    490 +                        buf.append('\\');
    491 +                    }
    492 +                    else if (c == '+' && seperator != '+')
    493 +                    {
    494 +                        buf.append('\\');
    495 +                    }
    496 +                    // END android-added
    497                      buf.append(c);
    498                  }
    499                  escaped = false;
    500 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/PBEParametersGenerator.java bcprov-jdk15on-147/org/bouncycastle/crypto/PBEParametersGenerator.java
    501 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/PBEParametersGenerator.java	2012-03-22 15:11:48.000000000 +0000
    502 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/PBEParametersGenerator.java	2012-09-19 21:17:12.000000000 +0000
    503 @@ -136,7 +136,8 @@
    504      public static byte[] PKCS12PasswordToBytes(
    505          char[]  password)
    506      {
    507 -        if (password.length > 0)
    508 +        // BEGIN android-changed
    509 +        if (password != null && password.length > 0)
    510          {
    511                                         // +1 for extra 2 pad bytes.
    512              byte[]  bytes = new byte[(password.length + 1) * 2];
    513 @@ -153,5 +154,6 @@
    514          {
    515              return new byte[0];
    516          }
    517 +        // END android-changed
    518      }
    519  }
    520 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactory.java bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactory.java
    521 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactory.java	1970-01-01 00:00:00.000000000 +0000
    522 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactory.java	2012-09-19 21:17:12.000000000 +0000
    523 @@ -0,0 +1,78 @@
    524 +/*
    525 + * Copyright (C) 2012 The Android Open Source Project
    526 + *
    527 + * Licensed under the Apache License, Version 2.0 (the "License");
    528 + * you may not use this file except in compliance with the License.
    529 + * You may obtain a copy of the License at
    530 + *
    531 + *      http://www.apache.org/licenses/LICENSE-2.0
    532 + *
    533 + * Unless required by applicable law or agreed to in writing, software
    534 + * distributed under the License is distributed on an "AS IS" BASIS,
    535 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    536 + * See the License for the specific language governing permissions and
    537 + * limitations under the License.
    538 + */
    539 +
    540 +package org.bouncycastle.crypto.digests;
    541 +
    542 +import org.bouncycastle.crypto.Digest;
    543 +
    544 +/**
    545 + * Level of indirection to let us select OpenSSLDigest implementations
    546 + * for libcore but fallback to BouncyCastle ones on the RI.
    547 + */
    548 +public final class AndroidDigestFactory {
    549 +    private static final String OpenSSLFactoryClassName
    550 +            = AndroidDigestFactory.class.getName() + "OpenSSL";
    551 +    private static final String BouncyCastleFactoryClassName
    552 +            = AndroidDigestFactory.class.getName() + "BouncyCastle";
    553 +
    554 +    private static final AndroidDigestFactoryInterface FACTORY;
    555 +    static {
    556 +        Class factoryImplementationClass;
    557 +        try {
    558 +            factoryImplementationClass = Class.forName(OpenSSLFactoryClassName);
    559 +        } catch (ClassNotFoundException e1) {
    560 +            try {
    561 +                factoryImplementationClass = Class.forName(BouncyCastleFactoryClassName);
    562 +            } catch (ClassNotFoundException e2) {
    563 +                throw new AssertionError("Failed to find AndroidDigestFactoryInterface "
    564 +                                         + "implementation. Looked for "
    565 +                                         + OpenSSLFactoryClassName + " and "
    566 +                                         + BouncyCastleFactoryClassName);
    567 +            }
    568 +        }
    569 +        if (!AndroidDigestFactoryInterface.class.isAssignableFrom(factoryImplementationClass)) {
    570 +            throw new AssertionError(factoryImplementationClass
    571 +                                     + "does not implement AndroidDigestFactoryInterface");
    572 +        }
    573 +        try {
    574 +            FACTORY = (AndroidDigestFactoryInterface) factoryImplementationClass.newInstance();
    575 +        } catch (InstantiationException e) {
    576 +            throw new AssertionError(e);
    577 +        } catch (IllegalAccessException e) {
    578 +            throw new AssertionError(e);
    579 +        }
    580 +    }
    581 +
    582 +    public static Digest getMD5() {
    583 +        return FACTORY.getMD5();
    584 +    }
    585 +
    586 +    public static Digest getSHA1() {
    587 +        return FACTORY.getSHA1();
    588 +    }
    589 +
    590 +    public static Digest getSHA256() {
    591 +        return FACTORY.getSHA256();
    592 +    }
    593 +
    594 +    public static Digest getSHA384() {
    595 +        return FACTORY.getSHA384();
    596 +    }
    597 +
    598 +    public static Digest getSHA512() {
    599 +        return FACTORY.getSHA512();
    600 +    }
    601 +}
    602 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactoryBouncyCastle.java bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactoryBouncyCastle.java
    603 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactoryBouncyCastle.java	1970-01-01 00:00:00.000000000 +0000
    604 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactoryBouncyCastle.java	2012-09-19 21:17:12.000000000 +0000
    605 @@ -0,0 +1,37 @@
    606 +/*
    607 + * Copyright (C) 2012 The Android Open Source Project
    608 + *
    609 + * Licensed under the Apache License, Version 2.0 (the "License");
    610 + * you may not use this file except in compliance with the License.
    611 + * You may obtain a copy of the License at
    612 + *
    613 + *      http://www.apache.org/licenses/LICENSE-2.0
    614 + *
    615 + * Unless required by applicable law or agreed to in writing, software
    616 + * distributed under the License is distributed on an "AS IS" BASIS,
    617 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    618 + * See the License for the specific language governing permissions and
    619 + * limitations under the License.
    620 + */
    621 +
    622 +package org.bouncycastle.crypto.digests;
    623 +
    624 +import org.bouncycastle.crypto.Digest;
    625 +
    626 +public class AndroidDigestFactoryBouncyCastle implements AndroidDigestFactoryInterface {
    627 +    public Digest getMD5() {
    628 +        return new MD5Digest();
    629 +    }
    630 +    public Digest getSHA1() {
    631 +        return new SHA1Digest();
    632 +    }
    633 +    public Digest getSHA256() {
    634 +        return new SHA256Digest();
    635 +    }
    636 +    public Digest getSHA384() {
    637 +        return new SHA384Digest();
    638 +    }
    639 +    public Digest getSHA512() {
    640 +        return new SHA512Digest();
    641 +    }
    642 +}
    643 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactoryInterface.java bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactoryInterface.java
    644 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactoryInterface.java	1970-01-01 00:00:00.000000000 +0000
    645 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactoryInterface.java	2012-09-19 21:17:12.000000000 +0000
    646 @@ -0,0 +1,27 @@
    647 +/*
    648 + * Copyright (C) 2012 The Android Open Source Project
    649 + *
    650 + * Licensed under the Apache License, Version 2.0 (the "License");
    651 + * you may not use this file except in compliance with the License.
    652 + * You may obtain a copy of the License at
    653 + *
    654 + *      http://www.apache.org/licenses/LICENSE-2.0
    655 + *
    656 + * Unless required by applicable law or agreed to in writing, software
    657 + * distributed under the License is distributed on an "AS IS" BASIS,
    658 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    659 + * See the License for the specific language governing permissions and
    660 + * limitations under the License.
    661 + */
    662 +
    663 +package org.bouncycastle.crypto.digests;
    664 +
    665 +import org.bouncycastle.crypto.Digest;
    666 +
    667 +interface AndroidDigestFactoryInterface {
    668 +    public Digest getMD5();
    669 +    public Digest getSHA1();
    670 +    public Digest getSHA256();
    671 +    public Digest getSHA384();
    672 +    public Digest getSHA512();
    673 +}
    674 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactoryOpenSSL.java bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactoryOpenSSL.java
    675 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/AndroidDigestFactoryOpenSSL.java	1970-01-01 00:00:00.000000000 +0000
    676 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/digests/AndroidDigestFactoryOpenSSL.java	2012-09-19 21:17:12.000000000 +0000
    677 @@ -0,0 +1,37 @@
    678 +/*
    679 + * Copyright (C) 2012 The Android Open Source Project
    680 + *
    681 + * Licensed under the Apache License, Version 2.0 (the "License");
    682 + * you may not use this file except in compliance with the License.
    683 + * You may obtain a copy of the License at
    684 + *
    685 + *      http://www.apache.org/licenses/LICENSE-2.0
    686 + *
    687 + * Unless required by applicable law or agreed to in writing, software
    688 + * distributed under the License is distributed on an "AS IS" BASIS,
    689 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    690 + * See the License for the specific language governing permissions and
    691 + * limitations under the License.
    692 + */
    693 +
    694 +package org.bouncycastle.crypto.digests;
    695 +
    696 +import org.bouncycastle.crypto.Digest;
    697 +
    698 +public class AndroidDigestFactoryOpenSSL implements AndroidDigestFactoryInterface {
    699 +    public Digest getMD5() {
    700 +        return new OpenSSLDigest.MD5();
    701 +    }
    702 +    public Digest getSHA1() {
    703 +        return new OpenSSLDigest.SHA1();
    704 +    }
    705 +    public Digest getSHA256() {
    706 +        return new OpenSSLDigest.SHA256();
    707 +    }
    708 +    public Digest getSHA384() {
    709 +        return new OpenSSLDigest.SHA384();
    710 +    }
    711 +    public Digest getSHA512() {
    712 +        return new OpenSSLDigest.SHA512();
    713 +    }
    714 +}
    715 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/OpenSSLDigest.java bcprov-jdk15on-147/org/bouncycastle/crypto/digests/OpenSSLDigest.java
    716 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/digests/OpenSSLDigest.java	1970-01-01 00:00:00.000000000 +0000
    717 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/digests/OpenSSLDigest.java	2012-09-19 21:17:12.000000000 +0000
    718 @@ -0,0 +1,159 @@
    719 +/*
    720 + * Copyright (C) 2008 The Android Open Source Project
    721 + *
    722 + * Licensed under the Apache License, Version 2.0 (the "License");
    723 + * you may not use this file except in compliance with the License.
    724 + * You may obtain a copy of the License at
    725 + *
    726 + *      http://www.apache.org/licenses/LICENSE-2.0
    727 + *
    728 + * Unless required by applicable law or agreed to in writing, software
    729 + * distributed under the License is distributed on an "AS IS" BASIS,
    730 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    731 + * See the License for the specific language governing permissions and
    732 + * limitations under the License.
    733 + */
    734 +
    735 +package org.bouncycastle.crypto.digests;
    736 +
    737 +import org.apache.harmony.xnet.provider.jsse.NativeCrypto;
    738 +import org.bouncycastle.crypto.ExtendedDigest;
    739 +
    740 +/**
    741 + * Implements the BouncyCastle Digest interface using OpenSSL's EVP API.
    742 + */
    743 +public class OpenSSLDigest implements ExtendedDigest {
    744 +
    745 +    /**
    746 +     * Holds the standard name of the hashing algorithm, e.g. "SHA-1";
    747 +     */
    748 +    private final String algorithm;
    749 +
    750 +    /**
    751 +     * Holds the EVP_MD for the hashing algorithm, e.g. EVP_get_digestbyname("sha1");
    752 +     */
    753 +    private final int evp_md;
    754 +
    755 +    /**
    756 +     * Holds the output size of the message digest.
    757 +     */
    758 +    private final int size;
    759 +
    760 +    /**
    761 +     * Holds the block size of the message digest.
    762 +     */
    763 +    private final int blockSize;
    764 +
    765 +    /**
    766 +     * Holds a pointer to the native message digest context. It is
    767 +     * lazily initialized to avoid having to reallocate on reset when
    768 +     * its unlikely to be reused.
    769 +     */
    770 +    private int ctx;
    771 +
    772 +    /**
    773 +     * Holds a dummy buffer for writing single bytes to the digest.
    774 +     */
    775 +    private final byte[] singleByte = new byte[1];
    776 +
    777 +    /**
    778 +     * Creates a new OpenSSLMessageDigest instance for the given algorithm
    779 +     * name.
    780 +     */
    781 +    private OpenSSLDigest(String algorithm, int evp_md, int size, int blockSize) {
    782 +        this.algorithm = algorithm;
    783 +        this.evp_md = evp_md;
    784 +        this.size = size;
    785 +        this.blockSize = blockSize;
    786 +    }
    787 +
    788 +    public String getAlgorithmName() {
    789 +        return algorithm;
    790 +    }
    791 +
    792 +    public int getDigestSize() {
    793 +        return size;
    794 +    }
    795 +
    796 +    public int getByteLength() {
    797 +        return blockSize;
    798 +    }
    799 +
    800 +    public void reset() {
    801 +        free();
    802 +    }
    803 +
    804 +    public void update(byte in) {
    805 +        singleByte[0] = in;
    806 +        update(singleByte, 0, 1);
    807 +    }
    808 +
    809 +    public void update(byte[] in, int inOff, int len) {
    810 +        NativeCrypto.EVP_DigestUpdate(getCtx(), in, inOff, len);
    811 +    }
    812 +
    813 +    public int doFinal(byte[] out, int outOff) {
    814 +        int i = NativeCrypto.EVP_DigestFinal(getCtx(), out, outOff);
    815 +        ctx = 0; // EVP_DigestFinal frees the context as a side effect
    816 +        reset();
    817 +        return i;
    818 +    }
    819 +
    820 +    private int getCtx() {
    821 +        if (ctx == 0) {
    822 +            ctx = NativeCrypto.EVP_DigestInit(evp_md);
    823 +        }
    824 +        return ctx;
    825 +    }
    826 +
    827 +    private void free() {
    828 +        if (ctx != 0) {
    829 +            NativeCrypto.EVP_MD_CTX_destroy(ctx);
    830 +            ctx = 0;
    831 +        }
    832 +    }
    833 +
    834 +    @Override
    835 +    protected void finalize() throws Throwable {
    836 +        try {
    837 +            free();
    838 +        } finally {
    839 +            super.finalize();
    840 +        }
    841 +    }
    842 +
    843 +    public static class MD5 extends OpenSSLDigest {
    844 +        private static final int EVP_MD = NativeCrypto.EVP_get_digestbyname("md5");
    845 +        private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
    846 +        private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
    847 +        public MD5() { super("MD5", EVP_MD, SIZE, BLOCK_SIZE); }
    848 +    }
    849 +
    850 +    public static class SHA1 extends OpenSSLDigest {
    851 +        private static final int EVP_MD = NativeCrypto.EVP_get_digestbyname("sha1");
    852 +        private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
    853 +        private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
    854 +        public SHA1() { super("SHA-1", EVP_MD, SIZE, BLOCK_SIZE); }
    855 +    }
    856 +
    857 +    public static class SHA256 extends OpenSSLDigest {
    858 +        private static final int EVP_MD = NativeCrypto.EVP_get_digestbyname("sha256");
    859 +        private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
    860 +        private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
    861 +        public SHA256() { super("SHA-256", EVP_MD, SIZE, BLOCK_SIZE); }
    862 +    }
    863 +
    864 +    public static class SHA384 extends OpenSSLDigest {
    865 +        private static final int EVP_MD = NativeCrypto.EVP_get_digestbyname("sha384");
    866 +        private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
    867 +        private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
    868 +        public SHA384() { super("SHA-384", EVP_MD, SIZE, BLOCK_SIZE); }
    869 +    }
    870 +
    871 +    public static class SHA512 extends OpenSSLDigest {
    872 +        private static final int EVP_MD = NativeCrypto.EVP_get_digestbyname("sha512");
    873 +        private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
    874 +        private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
    875 +        public SHA512() { super("SHA-512", EVP_MD, SIZE, BLOCK_SIZE); }
    876 +    }
    877 +}
    878 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/encodings/OAEPEncoding.java bcprov-jdk15on-147/org/bouncycastle/crypto/encodings/OAEPEncoding.java
    879 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/encodings/OAEPEncoding.java	2012-03-22 15:11:48.000000000 +0000
    880 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/encodings/OAEPEncoding.java	2012-09-19 21:17:12.000000000 +0000
    881 @@ -4,7 +4,9 @@
    882  import org.bouncycastle.crypto.CipherParameters;
    883  import org.bouncycastle.crypto.Digest;
    884  import org.bouncycastle.crypto.InvalidCipherTextException;
    885 -import org.bouncycastle.crypto.digests.SHA1Digest;
    886 +// BEGIN android-changed
    887 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
    888 +// END android-changed
    889  import org.bouncycastle.crypto.params.ParametersWithRandom;
    890  
    891  import java.security.SecureRandom;
    892 @@ -26,7 +28,9 @@
    893      public OAEPEncoding(
    894          AsymmetricBlockCipher   cipher)
    895      {
    896 -        this(cipher, new SHA1Digest(), null);
    897 +        // BEGIN android-changed
    898 +        this(cipher, AndroidDigestFactory.getSHA1(), null);
    899 +        // END android-changed
    900      }
    901      
    902      public OAEPEncoding(
    903 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/encodings/PKCS1Encoding.java bcprov-jdk15on-147/org/bouncycastle/crypto/encodings/PKCS1Encoding.java
    904 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/encodings/PKCS1Encoding.java	2012-03-22 15:11:48.000000000 +0000
    905 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/encodings/PKCS1Encoding.java	2012-09-19 21:17:12.000000000 +0000
    906 @@ -206,6 +206,12 @@
    907          {
    908              throw new InvalidCipherTextException("unknown block type");
    909          }
    910 +        // BEGIN android-added
    911 +        if ((type == 1 && forPrivateKey) || (type == 2 && !forPrivateKey))
    912 +        {
    913 +            throw new InvalidCipherTextException("invalid block type " + type);
    914 +        }
    915 +        // END android-added
    916  
    917          if (useStrictLength && block.length != engine.getOutputBlockSize())
    918          {
    919 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/engines/DESedeWrapEngine.java bcprov-jdk15on-147/org/bouncycastle/crypto/engines/DESedeWrapEngine.java
    920 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/engines/DESedeWrapEngine.java	2012-03-22 15:11:48.000000000 +0000
    921 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/engines/DESedeWrapEngine.java	2012-09-19 21:17:12.000000000 +0000
    922 @@ -6,7 +6,9 @@
    923  import org.bouncycastle.crypto.Digest;
    924  import org.bouncycastle.crypto.InvalidCipherTextException;
    925  import org.bouncycastle.crypto.Wrapper;
    926 -import org.bouncycastle.crypto.digests.SHA1Digest;
    927 +// BEGIN android-changed
    928 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
    929 +// END android-changed
    930  import org.bouncycastle.crypto.modes.CBCBlockCipher;
    931  import org.bouncycastle.crypto.params.KeyParameter;
    932  import org.bouncycastle.crypto.params.ParametersWithIV;
    933 @@ -52,7 +54,9 @@
    934      //
    935      // checksum digest
    936      //
    937 -    Digest  sha1 = new SHA1Digest();
    938 +    // BEGIN android-changed
    939 +    Digest  sha1 = AndroidDigestFactory.getSHA1();
    940 +    // END android-changed
    941      byte[]  digest = new byte[20];
    942  
    943     /**
    944 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/DHParametersHelper.java bcprov-jdk15on-147/org/bouncycastle/crypto/generators/DHParametersHelper.java
    945 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/DHParametersHelper.java	2012-03-22 15:11:48.000000000 +0000
    946 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/generators/DHParametersHelper.java	2012-09-19 21:17:12.000000000 +0000
    947 @@ -3,10 +3,17 @@
    948  import java.math.BigInteger;
    949  import java.security.SecureRandom;
    950  
    951 +// BEGIN android-added
    952 +import java.util.logging.Logger;
    953 +// END android-added
    954  import org.bouncycastle.util.BigIntegers;
    955  
    956  class DHParametersHelper
    957  {
    958 +    // BEGIN android-added
    959 +    private static final Logger logger = Logger.getLogger(DHParametersHelper.class.getName());
    960 +    // END android-added
    961 +
    962      private static final BigInteger ONE = BigInteger.valueOf(1);
    963      private static final BigInteger TWO = BigInteger.valueOf(2);
    964  
    965 @@ -17,11 +24,19 @@
    966       */
    967      static BigInteger[] generateSafePrimes(int size, int certainty, SecureRandom random)
    968      {
    969 +        // BEGIN android-added
    970 +        logger.info("Generating safe primes. This may take a long time.");
    971 +        long start = System.currentTimeMillis();
    972 +        int tries = 0;
    973 +        // END android-added
    974          BigInteger p, q;
    975          int qLength = size - 1;
    976  
    977          for (;;)
    978          {
    979 +            // BEGIN android-added
    980 +            tries++;
    981 +            // END android-added
    982              q = new BigInteger(qLength, 2, random);
    983  
    984              // p <- 2q + 1
    985 @@ -32,6 +47,11 @@
    986                  break;
    987              }
    988          }
    989 +        // BEGIN android-added
    990 +        long end = System.currentTimeMillis();
    991 +        long duration = end - start;
    992 +        logger.info("Generated safe primes: " + tries + " tries took " + duration + "ms");
    993 +        // END android-added
    994  
    995          return new BigInteger[] { p, q };
    996      }
    997 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/DSAParametersGenerator.java bcprov-jdk15on-147/org/bouncycastle/crypto/generators/DSAParametersGenerator.java
    998 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/DSAParametersGenerator.java	2012-03-22 15:11:48.000000000 +0000
    999 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/generators/DSAParametersGenerator.java	2012-09-19 21:17:12.000000000 +0000
   1000 @@ -1,8 +1,9 @@
   1001  package org.bouncycastle.crypto.generators;
   1002  
   1003  import org.bouncycastle.crypto.Digest;
   1004 -import org.bouncycastle.crypto.digests.SHA1Digest;
   1005 -import org.bouncycastle.crypto.digests.SHA256Digest;
   1006 +// BEGIN android-changed
   1007 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   1008 +// END android-changed
   1009  import org.bouncycastle.crypto.params.DSAParameters;
   1010  import org.bouncycastle.crypto.params.DSAValidationParameters;
   1011  import org.bouncycastle.util.Arrays;
   1012 @@ -75,7 +76,9 @@
   1013          byte[]          part1 = new byte[20];
   1014          byte[]          part2 = new byte[20];
   1015          byte[]          u = new byte[20];
   1016 -        SHA1Digest      sha1 = new SHA1Digest();
   1017 +        // BEGIN android-changed
   1018 +        Digest          sha1 = AndroidDigestFactory.getSHA1();
   1019 +        // END android-changed
   1020          int             n = (L - 1) / 160;
   1021          byte[]          w = new byte[L / 8];
   1022  
   1023 @@ -166,7 +169,9 @@
   1024      {
   1025  // A.1.1.2 Generation of the Probable Primes p and q Using an Approved Hash Function
   1026          // FIXME This should be configurable (digest size in bits must be >= N)
   1027 -        Digest d = new SHA256Digest();
   1028 +        // BEGIN android-changed
   1029 +        Digest d = AndroidDigestFactory.getSHA256();
   1030 +        // END android-changed
   1031          int outlen = d.getDigestSize() * 8;
   1032  
   1033  // 1. Check that the (L, N) pair is in the list of acceptable (L, N pairs) (see Section 4.2). If
   1034 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/OpenSSLPBEParametersGenerator.java bcprov-jdk15on-147/org/bouncycastle/crypto/generators/OpenSSLPBEParametersGenerator.java
   1035 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/OpenSSLPBEParametersGenerator.java	2012-03-22 15:11:48.000000000 +0000
   1036 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/generators/OpenSSLPBEParametersGenerator.java	2012-09-19 21:17:12.000000000 +0000
   1037 @@ -3,7 +3,9 @@
   1038  import org.bouncycastle.crypto.CipherParameters;
   1039  import org.bouncycastle.crypto.Digest;
   1040  import org.bouncycastle.crypto.PBEParametersGenerator;
   1041 -import org.bouncycastle.crypto.digests.MD5Digest;
   1042 +// BEGIN android-changed
   1043 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   1044 +// END android-changed
   1045  import org.bouncycastle.crypto.params.KeyParameter;
   1046  import org.bouncycastle.crypto.params.ParametersWithIV;
   1047  
   1048 @@ -17,7 +19,9 @@
   1049  public class OpenSSLPBEParametersGenerator
   1050      extends PBEParametersGenerator
   1051  {
   1052 -    private Digest  digest = new MD5Digest();
   1053 +    // BEGIN android-changed
   1054 +    private Digest  digest = AndroidDigestFactory.getMD5();
   1055 +    // END android-changed
   1056  
   1057      /**
   1058       * Construct a OpenSSL Parameters generator. 
   1059 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/PKCS5S2ParametersGenerator.java bcprov-jdk15on-147/org/bouncycastle/crypto/generators/PKCS5S2ParametersGenerator.java
   1060 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/generators/PKCS5S2ParametersGenerator.java	2012-03-22 15:11:48.000000000 +0000
   1061 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/generators/PKCS5S2ParametersGenerator.java	2012-09-19 21:17:12.000000000 +0000
   1062 @@ -4,7 +4,9 @@
   1063  import org.bouncycastle.crypto.Digest;
   1064  import org.bouncycastle.crypto.Mac;
   1065  import org.bouncycastle.crypto.PBEParametersGenerator;
   1066 -import org.bouncycastle.crypto.digests.SHA1Digest;
   1067 +// BEGIN android-changed
   1068 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   1069 +// END android-changed
   1070  import org.bouncycastle.crypto.macs.HMac;
   1071  import org.bouncycastle.crypto.params.KeyParameter;
   1072  import org.bouncycastle.crypto.params.ParametersWithIV;
   1073 @@ -27,7 +29,9 @@
   1074       */
   1075      public PKCS5S2ParametersGenerator()
   1076      {
   1077 -    	this(new SHA1Digest());
   1078 +        // BEGIN android-changed
   1079 +    	this(AndroidDigestFactory.getSHA1());
   1080 +        // END android-changed
   1081      }
   1082  
   1083      public PKCS5S2ParametersGenerator(Digest digest)
   1084 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/macs/HMac.java bcprov-jdk15on-147/org/bouncycastle/crypto/macs/HMac.java
   1085 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/macs/HMac.java	2012-03-22 15:11:48.000000000 +0000
   1086 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/macs/HMac.java	2012-09-19 21:17:12.000000000 +0000
   1087 @@ -32,23 +32,31 @@
   1088      {
   1089          blockLengths = new Hashtable();
   1090          
   1091 -        blockLengths.put("GOST3411", new Integer(32));
   1092 -        
   1093 -        blockLengths.put("MD2", new Integer(16));
   1094 -        blockLengths.put("MD4", new Integer(64));
   1095 -        blockLengths.put("MD5", new Integer(64));
   1096 -        
   1097 -        blockLengths.put("RIPEMD128", new Integer(64));
   1098 -        blockLengths.put("RIPEMD160", new Integer(64));
   1099 -        
   1100 -        blockLengths.put("SHA-1", new Integer(64));
   1101 -        blockLengths.put("SHA-224", new Integer(64));
   1102 -        blockLengths.put("SHA-256", new Integer(64));
   1103 -        blockLengths.put("SHA-384", new Integer(128));
   1104 -        blockLengths.put("SHA-512", new Integer(128));
   1105 -        
   1106 -        blockLengths.put("Tiger", new Integer(64));
   1107 -        blockLengths.put("Whirlpool", new Integer(64));
   1108 +        // BEGIN android-removed
   1109 +        // blockLengths.put("GOST3411", Integer.valueOf(32));
   1110 +        //
   1111 +        // blockLengths.put("MD2", Integer.valueOf(16));
   1112 +        // blockLengths.put("MD4", Integer.valueOf(64));
   1113 +        // END android-removed
   1114 +        blockLengths.put("MD5", Integer.valueOf(64));
   1115 +        
   1116 +        // BEGIN android-removed
   1117 +        // blockLengths.put("RIPEMD128", Integer.valueOf(64));
   1118 +        // blockLengths.put("RIPEMD160", Integer.valueOf(64));
   1119 +        // END android-removed
   1120 +        
   1121 +        blockLengths.put("SHA-1", Integer.valueOf(64));
   1122 +        // BEGIN android-removed
   1123 +        // blockLengths.put("SHA-224", Integer.valueOf(64));
   1124 +        // END android-removed
   1125 +        blockLengths.put("SHA-256", Integer.valueOf(64));
   1126 +        blockLengths.put("SHA-384", Integer.valueOf(128));
   1127 +        blockLengths.put("SHA-512", Integer.valueOf(128));
   1128 +        
   1129 +        // BEGIN android-removed
   1130 +        // blockLengths.put("Tiger", Integer.valueOf(64));
   1131 +        // blockLengths.put("Whirlpool", Integer.valueOf(64));
   1132 +        // END android-removed
   1133      }
   1134      
   1135      private static int getByteLength(
   1136 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/signers/RSADigestSigner.java bcprov-jdk15on-147/org/bouncycastle/crypto/signers/RSADigestSigner.java
   1137 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/signers/RSADigestSigner.java	2012-03-22 15:11:48.000000000 +0000
   1138 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/signers/RSADigestSigner.java	2012-09-19 21:17:12.000000000 +0000
   1139 @@ -39,18 +39,24 @@
   1140       */
   1141      static
   1142      {
   1143 -        oidMap.put("RIPEMD128", TeleTrusTObjectIdentifiers.ripemd128);
   1144 -        oidMap.put("RIPEMD160", TeleTrusTObjectIdentifiers.ripemd160);
   1145 -        oidMap.put("RIPEMD256", TeleTrusTObjectIdentifiers.ripemd256);
   1146 +        // BEGIN android-removed
   1147 +        // oidMap.put("RIPEMD128", TeleTrusTObjectIdentifiers.ripemd128);
   1148 +        // oidMap.put("RIPEMD160", TeleTrusTObjectIdentifiers.ripemd160);
   1149 +        // oidMap.put("RIPEMD256", TeleTrusTObjectIdentifiers.ripemd256);
   1150 +        // END android-removed
   1151  
   1152          oidMap.put("SHA-1", X509ObjectIdentifiers.id_SHA1);
   1153 -        oidMap.put("SHA-224", NISTObjectIdentifiers.id_sha224);
   1154 +        // BEGIN android-removed
   1155 +        // oidMap.put("SHA-224", NISTObjectIdentifiers.id_sha224);
   1156 +        // END android-removed
   1157          oidMap.put("SHA-256", NISTObjectIdentifiers.id_sha256);
   1158          oidMap.put("SHA-384", NISTObjectIdentifiers.id_sha384);
   1159          oidMap.put("SHA-512", NISTObjectIdentifiers.id_sha512);
   1160  
   1161 -        oidMap.put("MD2", PKCSObjectIdentifiers.md2);
   1162 -        oidMap.put("MD4", PKCSObjectIdentifiers.md4);
   1163 +        // BEGIN android-removed
   1164 +        // oidMap.put("MD2", PKCSObjectIdentifiers.md2);
   1165 +        // oidMap.put("MD4", PKCSObjectIdentifiers.md4);
   1166 +        // END android-removed
   1167          oidMap.put("MD5", PKCSObjectIdentifiers.md5);
   1168      }
   1169  
   1170 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/util/PrivateKeyFactory.java bcprov-jdk15on-147/org/bouncycastle/crypto/util/PrivateKeyFactory.java
   1171 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/util/PrivateKeyFactory.java	2012-03-22 15:11:48.000000000 +0000
   1172 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/util/PrivateKeyFactory.java	2012-09-19 21:17:12.000000000 +0000
   1173 @@ -11,7 +11,9 @@
   1174  import org.bouncycastle.asn1.ASN1Sequence;
   1175  import org.bouncycastle.asn1.DERInteger;
   1176  import org.bouncycastle.asn1.nist.NISTNamedCurves;
   1177 -import org.bouncycastle.asn1.oiw.ElGamalParameter;
   1178 +// BEGIN android-removed
   1179 +// import org.bouncycastle.asn1.oiw.ElGamalParameter;
   1180 +// END android-removed
   1181  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   1182  import org.bouncycastle.asn1.pkcs.DHParameter;
   1183  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   1184 @@ -19,7 +21,9 @@
   1185  import org.bouncycastle.asn1.pkcs.RSAPrivateKey;
   1186  import org.bouncycastle.asn1.sec.ECPrivateKey;
   1187  import org.bouncycastle.asn1.sec.SECNamedCurves;
   1188 -import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   1189 +// BEGIN android-removed
   1190 +// import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   1191 +// END android-removed
   1192  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   1193  import org.bouncycastle.asn1.x509.DSAParameter;
   1194  import org.bouncycastle.asn1.x9.X962NamedCurves;
   1195 @@ -33,8 +37,10 @@
   1196  import org.bouncycastle.crypto.params.DSAPrivateKeyParameters;
   1197  import org.bouncycastle.crypto.params.ECDomainParameters;
   1198  import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
   1199 -import org.bouncycastle.crypto.params.ElGamalParameters;
   1200 -import org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters;
   1201 +// BEGIN android-removed
   1202 +// import org.bouncycastle.crypto.params.ElGamalParameters;
   1203 +// import org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters;
   1204 +// END android-removed
   1205  import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
   1206  
   1207  /**
   1208 @@ -100,14 +106,16 @@
   1209  
   1210              return new DHPrivateKeyParameters(derX.getValue(), dhParams);
   1211          }
   1212 -        else if (algId.getAlgorithm().equals(OIWObjectIdentifiers.elGamalAlgorithm))
   1213 -        {
   1214 -            ElGamalParameter params = new ElGamalParameter((ASN1Sequence)algId.getParameters());
   1215 -            DERInteger derX = (DERInteger)keyInfo.parsePrivateKey();
   1216 -
   1217 -            return new ElGamalPrivateKeyParameters(derX.getValue(), new ElGamalParameters(
   1218 -                params.getP(), params.getG()));
   1219 -        }
   1220 +        // BEGIN android-removed
   1221 +        // else if (algId.getAlgorithm().equals(OIWObjectIdentifiers.elGamalAlgorithm))
   1222 +        // {
   1223 +        //     ElGamalParameter params = new ElGamalParameter((ASN1Sequence)algId.getParameters());
   1224 +        //     DERInteger derX = (DERInteger)keyInfo.parsePrivateKey();
   1225 +        //
   1226 +        //     return new ElGamalPrivateKeyParameters(derX.getValue(), new ElGamalParameters(
   1227 +        //         params.getP(), params.getG()));
   1228 +        // }
   1229 +        // END android-removed
   1230          else if (algId.getAlgorithm().equals(X9ObjectIdentifiers.id_dsa))
   1231          {
   1232              DERInteger derX = (DERInteger)keyInfo.parsePrivateKey();
   1233 @@ -140,10 +148,12 @@
   1234                      {
   1235                          x9 = NISTNamedCurves.getByOID(oid);
   1236  
   1237 -                        if (x9 == null)
   1238 -                        {
   1239 -                            x9 = TeleTrusTNamedCurves.getByOID(oid);
   1240 -                        }
   1241 +                        // BEGIN android-removed
   1242 +                        // if (x9 == null)
   1243 +                        // {
   1244 +                        //     x9 = TeleTrusTNamedCurves.getByOID(oid);
   1245 +                        // }
   1246 +                        // END android-removed
   1247                      }
   1248                  }
   1249              }
   1250 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/crypto/util/PublicKeyFactory.java bcprov-jdk15on-147/org/bouncycastle/crypto/util/PublicKeyFactory.java
   1251 --- bcprov-jdk15on-147.orig/org/bouncycastle/crypto/util/PublicKeyFactory.java	2012-03-22 15:11:48.000000000 +0000
   1252 +++ bcprov-jdk15on-147/org/bouncycastle/crypto/util/PublicKeyFactory.java	2012-09-19 21:17:12.000000000 +0000
   1253 @@ -13,13 +13,17 @@
   1254  import org.bouncycastle.asn1.DERInteger;
   1255  import org.bouncycastle.asn1.DEROctetString;
   1256  import org.bouncycastle.asn1.nist.NISTNamedCurves;
   1257 -import org.bouncycastle.asn1.oiw.ElGamalParameter;
   1258 +// BEGIN android-removed
   1259 +// import org.bouncycastle.asn1.oiw.ElGamalParameter;
   1260 +// END android-removed
   1261  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   1262  import org.bouncycastle.asn1.pkcs.DHParameter;
   1263  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   1264  import org.bouncycastle.asn1.pkcs.RSAPublicKey;
   1265  import org.bouncycastle.asn1.sec.SECNamedCurves;
   1266 -import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   1267 +// BEGIN android-removed
   1268 +// import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   1269 +// END android-removed
   1270  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   1271  import org.bouncycastle.asn1.x509.DSAParameter;
   1272  import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
   1273 @@ -40,8 +44,10 @@
   1274  import org.bouncycastle.crypto.params.DSAPublicKeyParameters;
   1275  import org.bouncycastle.crypto.params.ECDomainParameters;
   1276  import org.bouncycastle.crypto.params.ECPublicKeyParameters;
   1277 -import org.bouncycastle.crypto.params.ElGamalParameters;
   1278 -import org.bouncycastle.crypto.params.ElGamalPublicKeyParameters;
   1279 +// BEGIN android-removed
   1280 +// import org.bouncycastle.crypto.params.ElGamalParameters;
   1281 +// import org.bouncycastle.crypto.params.ElGamalPublicKeyParameters;
   1282 +// END android-removed
   1283  import org.bouncycastle.crypto.params.RSAKeyParameters;
   1284  
   1285  /**
   1286 @@ -135,14 +141,16 @@
   1287  
   1288              return new DHPublicKeyParameters(derY.getValue(), dhParams);
   1289          }
   1290 -        else if (algId.getAlgorithm().equals(OIWObjectIdentifiers.elGamalAlgorithm))
   1291 -        {
   1292 -            ElGamalParameter params = new ElGamalParameter((ASN1Sequence)algId.getParameters());
   1293 -            DERInteger derY = (DERInteger)keyInfo.parsePublicKey();
   1294 -
   1295 -            return new ElGamalPublicKeyParameters(derY.getValue(), new ElGamalParameters(
   1296 -                params.getP(), params.getG()));
   1297 -        }
   1298 +        // BEGIN android-removed
   1299 +        // else if (algId.getAlgorithm().equals(OIWObjectIdentifiers.elGamalAlgorithm))
   1300 +        // {
   1301 +        //     ElGamalParameter params = new ElGamalParameter((ASN1Sequence)algId.getParameters());
   1302 +        //     DERInteger derY = (DERInteger)keyInfo.parsePublicKey();
   1303 +        //
   1304 +        //     return new ElGamalPublicKeyParameters(derY.getValue(), new ElGamalParameters(
   1305 +        //         params.getP(), params.getG()));
   1306 +        // }
   1307 +        // END android-removed
   1308          else if (algId.getAlgorithm().equals(X9ObjectIdentifiers.id_dsa)
   1309              || algId.getAlgorithm().equals(OIWObjectIdentifiers.dsaWithSHA1))
   1310          {
   1311 @@ -177,10 +185,12 @@
   1312                      {
   1313                          x9 = NISTNamedCurves.getByOID(oid);
   1314  
   1315 -                        if (x9 == null)
   1316 -                        {
   1317 -                            x9 = TeleTrusTNamedCurves.getByOID(oid);
   1318 -                        }
   1319 +                        // BEGIN android-removed
   1320 +                        // if (x9 == null)
   1321 +                        // {
   1322 +                        //     x9 = TeleTrusTNamedCurves.getByOID(oid);
   1323 +                        // }
   1324 +                        // END android-removed
   1325                      }
   1326                  }
   1327              }
   1328 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/DSA.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/DSA.java
   1329 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/DSA.java	2012-03-22 15:11:48.000000000 +0000
   1330 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/DSA.java	2012-09-19 21:17:12.000000000 +0000
   1331 @@ -27,26 +27,34 @@
   1332              provider.addAlgorithm("KeyPairGenerator.DSA", PREFIX + "KeyPairGeneratorSpi");
   1333              provider.addAlgorithm("KeyFactory.DSA", PREFIX + "KeyFactorySpi");
   1334  
   1335 -            provider.addAlgorithm("Signature.DSA", PREFIX + "DSASigner$stdDSA");
   1336 +            // BEGIN android-changed
   1337 +            provider.addAlgorithm("Signature.SHA1withDSA", PREFIX + "DSASigner$stdDSA");
   1338 +            // END android-changed
   1339              provider.addAlgorithm("Signature.NONEWITHDSA", PREFIX + "DSASigner$noneDSA");
   1340  
   1341              provider.addAlgorithm("Alg.Alias.Signature.RAWDSA", "NONEWITHDSA");
   1342  
   1343 -            addSignatureAlgorithm(provider, "SHA224", "DSA", PREFIX + "DSASigner$dsa224", NISTObjectIdentifiers.dsa_with_sha224);
   1344 -            addSignatureAlgorithm(provider, "SHA256", "DSA", PREFIX + "DSASigner$dsa256", NISTObjectIdentifiers.dsa_with_sha256);
   1345 -            addSignatureAlgorithm(provider, "SHA384", "DSA", PREFIX + "DSASigner$dsa384", NISTObjectIdentifiers.dsa_with_sha384);
   1346 -            addSignatureAlgorithm(provider, "SHA512", "DSA", PREFIX + "DSASigner$dsa512", NISTObjectIdentifiers.dsa_with_sha512);
   1347 -
   1348 -            provider.addAlgorithm("Alg.Alias.Signature.SHA/DSA", "DSA");
   1349 -            provider.addAlgorithm("Alg.Alias.Signature.SHA1withDSA", "DSA");
   1350 -            provider.addAlgorithm("Alg.Alias.Signature.SHA1WITHDSA", "DSA");
   1351 -            provider.addAlgorithm("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.10040.4.1", "DSA");
   1352 -            provider.addAlgorithm("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.10040.4.3", "DSA");
   1353 -            provider.addAlgorithm("Alg.Alias.Signature.DSAwithSHA1", "DSA");
   1354 -            provider.addAlgorithm("Alg.Alias.Signature.DSAWITHSHA1", "DSA");
   1355 -            provider.addAlgorithm("Alg.Alias.Signature.SHA1WithDSA", "DSA");
   1356 -            provider.addAlgorithm("Alg.Alias.Signature.DSAWithSHA1", "DSA");
   1357 -            provider.addAlgorithm("Alg.Alias.Signature.1.2.840.10040.4.3", "DSA");
   1358 +            // BEGIN android-removed
   1359 +            // addSignatureAlgorithm(provider, "SHA224", "DSA", PREFIX + "DSASigner$dsa224", NISTObjectIdentifiers.dsa_with_sha224);
   1360 +            // addSignatureAlgorithm(provider, "SHA256", "DSA", PREFIX + "DSASigner$dsa256", NISTObjectIdentifiers.dsa_with_sha256);
   1361 +            // addSignatureAlgorithm(provider, "SHA384", "DSA", PREFIX + "DSASigner$dsa384", NISTObjectIdentifiers.dsa_with_sha384);
   1362 +            // addSignatureAlgorithm(provider, "SHA512", "DSA", PREFIX + "DSASigner$dsa512", NISTObjectIdentifiers.dsa_with_sha512);
   1363 +            // END android-removed
   1364 +
   1365 +            // BEGIN android-added
   1366 +            provider.addAlgorithm("Alg.Alias.Signature.DSA", "SHA1withDSA");
   1367 +            // END android-added
   1368 +            // BEGIN android-changed
   1369 +            provider.addAlgorithm("Alg.Alias.Signature.SHA/DSA", "SHA1withDSA");
   1370 +            provider.addAlgorithm("Alg.Alias.Signature.SHA1WITHDSA", "SHA1withDSA");
   1371 +            provider.addAlgorithm("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.10040.4.1", "SHA1withDSA");
   1372 +            provider.addAlgorithm("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.10040.4.3", "SHA1withDSA");
   1373 +            provider.addAlgorithm("Alg.Alias.Signature.DSAwithSHA1", "SHA1withDSA");
   1374 +            provider.addAlgorithm("Alg.Alias.Signature.DSAWITHSHA1", "SHA1withDSA");
   1375 +            provider.addAlgorithm("Alg.Alias.Signature.SHA1WithDSA", "SHA1withDSA");
   1376 +            provider.addAlgorithm("Alg.Alias.Signature.DSAWithSHA1", "SHA1withDSA");
   1377 +            provider.addAlgorithm("Alg.Alias.Signature.1.2.840.10040.4.3", "SHA1withDSA");
   1378 +            // END android-changed
   1379  
   1380              AsymmetricKeyInfoConverter keyFact = new KeyFactorySpi();
   1381  
   1382 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/EC.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/EC.java
   1383 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/EC.java	2012-03-22 15:11:48.000000000 +0000
   1384 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/EC.java	2012-09-19 21:17:12.000000000 +0000
   1385 @@ -1,7 +1,9 @@
   1386  package org.bouncycastle.jcajce.provider.asymmetric;
   1387  
   1388 -import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
   1389 -import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   1390 +// BEGIN android-removed
   1391 +// import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
   1392 +// import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   1393 +// END android-removed
   1394  import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
   1395  import org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi;
   1396  import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
   1397 @@ -21,33 +23,43 @@
   1398          public void configure(ConfigurableProvider provider)
   1399          {
   1400              provider.addAlgorithm("KeyAgreement.ECDH", PREFIX + "KeyAgreementSpi$DH");
   1401 -            provider.addAlgorithm("KeyAgreement.ECDHC", PREFIX + "KeyAgreementSpi$DHC");
   1402 -            provider.addAlgorithm("KeyAgreement.ECMQV", PREFIX + "KeyAgreementSpi$MQV");
   1403 -            provider.addAlgorithm("KeyAgreement." + X9ObjectIdentifiers.dhSinglePass_stdDH_sha1kdf_scheme, PREFIX + "KeyAgreementSpi$DHwithSHA1KDF");
   1404 -            provider.addAlgorithm("KeyAgreement." + X9ObjectIdentifiers.mqvSinglePass_sha1kdf_scheme, PREFIX + "KeyAgreementSpi$MQVwithSHA1KDF");
   1405 +            // BEGIN android-removed
   1406 +            // provider.addAlgorithm("KeyAgreement.ECDHC", PREFIX + "KeyAgreementSpi$DHC");
   1407 +            // provider.addAlgorithm("KeyAgreement.ECMQV", PREFIX + "KeyAgreementSpi$MQV");
   1408 +            // provider.addAlgorithm("KeyAgreement." + X9ObjectIdentifiers.dhSinglePass_stdDH_sha1kdf_scheme, PREFIX + "KeyAgreementSpi$DHwithSHA1KDF");
   1409 +            // provider.addAlgorithm("KeyAgreement." + X9ObjectIdentifiers.mqvSinglePass_sha1kdf_scheme, PREFIX + "KeyAgreementSpi$MQVwithSHA1KDF");
   1410 +            // END android-removed
   1411  
   1412              registerOid(provider, X9ObjectIdentifiers.id_ecPublicKey, "EC", new KeyFactorySpi.EC());
   1413              // TODO Should this be an alias for ECDH?
   1414              registerOid(provider, X9ObjectIdentifiers.dhSinglePass_stdDH_sha1kdf_scheme, "EC", new KeyFactorySpi.EC());
   1415 -            registerOid(provider, X9ObjectIdentifiers.mqvSinglePass_sha1kdf_scheme, "ECMQV", new KeyFactorySpi.ECMQV());
   1416 -
   1417 -            registerOidAlgorithmParameters(provider, X9ObjectIdentifiers.id_ecPublicKey, "EC");
   1418 -            // TODO Should this be an alias for ECDH?
   1419 -            registerOidAlgorithmParameters(provider, X9ObjectIdentifiers.dhSinglePass_stdDH_sha1kdf_scheme, "EC");
   1420 -            registerOidAlgorithmParameters(provider, X9ObjectIdentifiers.mqvSinglePass_sha1kdf_scheme, "EC");
   1421 +            // BEGIN android-removed
   1422 +            // registerOid(provider, X9ObjectIdentifiers.mqvSinglePass_sha1kdf_scheme, "ECMQV", new KeyFactorySpi.ECMQV());
   1423 +            // END android-removed
   1424 +
   1425 +            // BEGIN android-removed
   1426 +            // registerOidAlgorithmParameters(provider, X9ObjectIdentifiers.id_ecPublicKey, "EC");
   1427 +            // // TODO Should this be an alias for ECDH?
   1428 +            // registerOidAlgorithmParameters(provider, X9ObjectIdentifiers.dhSinglePass_stdDH_sha1kdf_scheme, "EC");
   1429 +            // registerOidAlgorithmParameters(provider, X9ObjectIdentifiers.mqvSinglePass_sha1kdf_scheme, "EC");
   1430 +            // END android-removed
   1431  
   1432              provider.addAlgorithm("KeyFactory.EC", PREFIX + "KeyFactorySpi$EC");
   1433 -            provider.addAlgorithm("KeyFactory.ECDSA", PREFIX + "KeyFactorySpi$ECDSA");
   1434 -            provider.addAlgorithm("KeyFactory.ECDH", PREFIX + "KeyFactorySpi$ECDH");
   1435 -            provider.addAlgorithm("KeyFactory.ECDHC", PREFIX + "KeyFactorySpi$ECDHC");
   1436 -            provider.addAlgorithm("KeyFactory.ECMQV", PREFIX + "KeyFactorySpi$ECMQV");
   1437 +            // BEGIN android-removed
   1438 +            // provider.addAlgorithm("KeyFactory.ECDSA", PREFIX + "KeyFactorySpi$ECDSA");
   1439 +            // provider.addAlgorithm("KeyFactory.ECDH", PREFIX + "KeyFactorySpi$ECDH");
   1440 +            // provider.addAlgorithm("KeyFactory.ECDHC", PREFIX + "KeyFactorySpi$ECDHC");
   1441 +            // provider.addAlgorithm("KeyFactory.ECMQV", PREFIX + "KeyFactorySpi$ECMQV");
   1442 +            // END android-removed
   1443  
   1444              provider.addAlgorithm("KeyPairGenerator.EC", PREFIX + "KeyPairGeneratorSpi$EC");
   1445 -            provider.addAlgorithm("KeyPairGenerator.ECDSA", PREFIX + "KeyPairGeneratorSpi$ECDSA");
   1446 -            provider.addAlgorithm("KeyPairGenerator.ECDH", PREFIX + "KeyPairGeneratorSpi$ECDH");
   1447 -            provider.addAlgorithm("KeyPairGenerator.ECDHC", PREFIX + "KeyPairGeneratorSpi$ECDHC");
   1448 -            provider.addAlgorithm("KeyPairGenerator.ECIES", PREFIX + "KeyPairGeneratorSpi$ECDH");
   1449 -            provider.addAlgorithm("KeyPairGenerator.ECMQV", PREFIX + "KeyPairGeneratorSpi$ECMQV");
   1450 +            // BEGIN android-removed
   1451 +            // provider.addAlgorithm("KeyPairGenerator.ECDSA", PREFIX + "KeyPairGeneratorSpi$ECDSA");
   1452 +            // provider.addAlgorithm("KeyPairGenerator.ECDH", PREFIX + "KeyPairGeneratorSpi$ECDH");
   1453 +            // provider.addAlgorithm("KeyPairGenerator.ECDHC", PREFIX + "KeyPairGeneratorSpi$ECDHC");
   1454 +            // provider.addAlgorithm("KeyPairGenerator.ECIES", PREFIX + "KeyPairGeneratorSpi$ECDH");
   1455 +            // provider.addAlgorithm("KeyPairGenerator.ECMQV", PREFIX + "KeyPairGeneratorSpi$ECMQV");
   1456 +            // END android-removed
   1457  
   1458              provider.addAlgorithm("Signature.ECDSA", PREFIX + "SignatureSpi$ecDSA");
   1459              provider.addAlgorithm("Signature.NONEwithECDSA", PREFIX + "SignatureSpi$ecDSAnone");
   1460 @@ -59,23 +71,29 @@
   1461              provider.addAlgorithm("Alg.Alias.Signature.SHA1WithECDSA", "ECDSA");
   1462              provider.addAlgorithm("Alg.Alias.Signature.ECDSAWithSHA1", "ECDSA");
   1463              provider.addAlgorithm("Alg.Alias.Signature.1.2.840.10045.4.1", "ECDSA");
   1464 -            provider.addAlgorithm("Alg.Alias.Signature." + TeleTrusTObjectIdentifiers.ecSignWithSha1, "ECDSA");
   1465 -
   1466 -            addSignatureAlgorithm(provider, "SHA224", "ECDSA", PREFIX + "SignatureSpi$ecDSA224", X9ObjectIdentifiers.ecdsa_with_SHA224);
   1467 +            // BEGIN android-removed
   1468 +            // provider.addAlgorithm("Alg.Alias.Signature." + TeleTrusTObjectIdentifiers.ecSignWithSha1, "ECDSA");
   1469 +            // END android-removed
   1470 +
   1471 +            // BEGIN android-removed
   1472 +            // addSignatureAlgorithm(provider, "SHA224", "ECDSA", PREFIX + "SignatureSpi$ecDSA224", X9ObjectIdentifiers.ecdsa_with_SHA224);
   1473 +            // END android-removed
   1474              addSignatureAlgorithm(provider, "SHA256", "ECDSA", PREFIX + "SignatureSpi$ecDSA256", X9ObjectIdentifiers.ecdsa_with_SHA256);
   1475              addSignatureAlgorithm(provider, "SHA384", "ECDSA", PREFIX + "SignatureSpi$ecDSA384", X9ObjectIdentifiers.ecdsa_with_SHA384);
   1476              addSignatureAlgorithm(provider, "SHA512", "ECDSA", PREFIX + "SignatureSpi$ecDSA512", X9ObjectIdentifiers.ecdsa_with_SHA512);
   1477 -            addSignatureAlgorithm(provider, "RIPEMD160", "ECDSA", PREFIX + "SignatureSpi$ecDSARipeMD160",TeleTrusTObjectIdentifiers.ecSignWithRipemd160);
   1478 -
   1479 -            provider.addAlgorithm("Signature.SHA1WITHECNR", PREFIX + "SignatureSpi$ecNR");
   1480 -            provider.addAlgorithm("Signature.SHA224WITHECNR", PREFIX + "SignatureSpi$ecNR224");
   1481 -            provider.addAlgorithm("Signature.SHA256WITHECNR", PREFIX + "SignatureSpi$ecNR256");
   1482 -            provider.addAlgorithm("Signature.SHA384WITHECNR", PREFIX + "SignatureSpi$ecNR384");
   1483 -            provider.addAlgorithm("Signature.SHA512WITHECNR", PREFIX + "SignatureSpi$ecNR512");
   1484 -
   1485 -            addSignatureAlgorithm(provider, "SHA1", "CVC-ECDSA", PREFIX + "SignatureSpi$ecCVCDSA", EACObjectIdentifiers.id_TA_ECDSA_SHA_1);
   1486 -            addSignatureAlgorithm(provider, "SHA224", "CVC-ECDSA", PREFIX + "SignatureSpi$ecCVCDSA224", EACObjectIdentifiers.id_TA_ECDSA_SHA_224);
   1487 -            addSignatureAlgorithm(provider, "SHA256", "CVC-ECDSA", PREFIX + "SignatureSpi$ecCVCDSA256", EACObjectIdentifiers.id_TA_ECDSA_SHA_256);
   1488 +            // BEGIN android-removed
   1489 +            // addSignatureAlgorithm(provider, "RIPEMD160", "ECDSA", PREFIX + "SignatureSpi$ecDSARipeMD160",TeleTrusTObjectIdentifiers.ecSignWithRipemd160);
   1490 +            //
   1491 +            // provider.addAlgorithm("Signature.SHA1WITHECNR", PREFIX + "SignatureSpi$ecNR");
   1492 +            // provider.addAlgorithm("Signature.SHA224WITHECNR", PREFIX + "SignatureSpi$ecNR224");
   1493 +            // provider.addAlgorithm("Signature.SHA256WITHECNR", PREFIX + "SignatureSpi$ecNR256");
   1494 +            // provider.addAlgorithm("Signature.SHA384WITHECNR", PREFIX + "SignatureSpi$ecNR384");
   1495 +            // provider.addAlgorithm("Signature.SHA512WITHECNR", PREFIX + "SignatureSpi$ecNR512");
   1496 +            //
   1497 +            // addSignatureAlgorithm(provider, "SHA1", "CVC-ECDSA", PREFIX + "SignatureSpi$ecCVCDSA", EACObjectIdentifiers.id_TA_ECDSA_SHA_1);
   1498 +            // addSignatureAlgorithm(provider, "SHA224", "CVC-ECDSA", PREFIX + "SignatureSpi$ecCVCDSA224", EACObjectIdentifiers.id_TA_ECDSA_SHA_224);
   1499 +            // addSignatureAlgorithm(provider, "SHA256", "CVC-ECDSA", PREFIX + "SignatureSpi$ecCVCDSA256", EACObjectIdentifiers.id_TA_ECDSA_SHA_256);
   1500 +            // END android-removed
   1501          }
   1502      }
   1503  }
   1504 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/RSA.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/RSA.java
   1505 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/RSA.java	2012-03-22 15:11:48.000000000 +0000
   1506 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/RSA.java	2012-11-01 06:02:09.000000000 +0000
   1507 @@ -3,7 +3,9 @@
   1508  import org.bouncycastle.asn1.ASN1ObjectIdentifier;
   1509  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   1510  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   1511 -import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   1512 +// BEGIN android-removed
   1513 +// import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   1514 +// END android-removed
   1515  import org.bouncycastle.asn1.x509.X509ObjectIdentifiers;
   1516  import org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi;
   1517  import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
   1518 @@ -24,41 +26,49 @@
   1519          public void configure(ConfigurableProvider provider)
   1520          {
   1521              provider.addAlgorithm("AlgorithmParameters.OAEP", PREFIX + "AlgorithmParametersSpi$OAEP");
   1522 -            provider.addAlgorithm("AlgorithmParameters.PSS", PREFIX + "AlgorithmParametersSpi$PSS");
   1523 -
   1524 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.RSAPSS", "PSS");
   1525 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.RSASSA-PSS", "PSS");
   1526 -
   1527 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA224withRSA/PSS", "PSS");
   1528 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA256withRSA/PSS", "PSS");
   1529 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA384withRSA/PSS", "PSS");
   1530 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA512withRSA/PSS", "PSS");
   1531 -
   1532 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA224WITHRSAANDMGF1", "PSS");
   1533 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA256WITHRSAANDMGF1", "PSS");
   1534 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA384WITHRSAANDMGF1", "PSS");
   1535 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA512WITHRSAANDMGF1", "PSS");
   1536 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.RAWRSAPSS", "PSS");
   1537 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.NONEWITHRSAPSS", "PSS");
   1538 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.NONEWITHRSASSA-PSS", "PSS");
   1539 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameters.NONEWITHRSAANDMGF1", "PSS");
   1540 +            // BEGIN android-removed
   1541 +            // provider.addAlgorithm("AlgorithmParameters.PSS", PREFIX + "AlgorithmParametersSpi$PSS");
   1542 +            //
   1543 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.RSAPSS", "PSS");
   1544 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.RSASSA-PSS", "PSS");
   1545 +            //
   1546 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA224withRSA/PSS", "PSS");
   1547 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA256withRSA/PSS", "PSS");
   1548 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA384withRSA/PSS", "PSS");
   1549 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA512withRSA/PSS", "PSS");
   1550 +            //
   1551 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA224WITHRSAANDMGF1", "PSS");
   1552 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA256WITHRSAANDMGF1", "PSS");
   1553 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA384WITHRSAANDMGF1", "PSS");
   1554 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA512WITHRSAANDMGF1", "PSS");
   1555 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.RAWRSAPSS", "PSS");
   1556 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.NONEWITHRSAPSS", "PSS");
   1557 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.NONEWITHRSASSA-PSS", "PSS");
   1558 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.NONEWITHRSAANDMGF1", "PSS");
   1559 +            // END android-removed
   1560  
   1561              provider.addAlgorithm("Cipher.RSA", PREFIX + "CipherSpi$NoPadding");
   1562 -            provider.addAlgorithm("Cipher.RSA/RAW", PREFIX + "CipherSpi$NoPadding");
   1563 -            provider.addAlgorithm("Cipher.RSA/PKCS1", PREFIX + "CipherSpi$PKCS1v1_5Padding");
   1564 -            provider.addAlgorithm("Cipher.1.2.840.113549.1.1.1", PREFIX + "CipherSpi$PKCS1v1_5Padding");
   1565 -            provider.addAlgorithm("Cipher.2.5.8.1.1", PREFIX + "CipherSpi$PKCS1v1_5Padding");
   1566 -            provider.addAlgorithm("Cipher.RSA/1", PREFIX + "CipherSpi$PKCS1v1_5Padding_PrivateOnly");
   1567 -            provider.addAlgorithm("Cipher.RSA/2", PREFIX + "CipherSpi$PKCS1v1_5Padding_PublicOnly");
   1568 -            provider.addAlgorithm("Cipher.RSA/OAEP", PREFIX + "CipherSpi$OAEPPadding");
   1569 -            provider.addAlgorithm("Cipher." + PKCSObjectIdentifiers.id_RSAES_OAEP, PREFIX + "CipherSpi$OAEPPadding");
   1570 -            provider.addAlgorithm("Cipher.RSA/ISO9796-1", PREFIX + "CipherSpi$ISO9796d1Padding");
   1571 +            // BEGIN android-changed
   1572 +            provider.addAlgorithm("Alg.Alias.Cipher.RSA/RAW", "RSA");
   1573 +            // END android-changed
   1574 +            // BEGIN android-removed
   1575 +            // provider.addAlgorithm("Cipher.RSA/PKCS1", PREFIX + "CipherSpi$PKCS1v1_5Padding");
   1576 +            // provider.addAlgorithm("Cipher.1.2.840.113549.1.1.1", PREFIX + "CipherSpi$PKCS1v1_5Padding");
   1577 +            // provider.addAlgorithm("Cipher.2.5.8.1.1", PREFIX + "CipherSpi$PKCS1v1_5Padding");
   1578 +            // provider.addAlgorithm("Cipher.RSA/1", PREFIX + "CipherSpi$PKCS1v1_5Padding_PrivateOnly");
   1579 +            // provider.addAlgorithm("Cipher.RSA/2", PREFIX + "CipherSpi$PKCS1v1_5Padding_PublicOnly");
   1580 +            // provider.addAlgorithm("Cipher.RSA/OAEP", PREFIX + "CipherSpi$OAEPPadding");
   1581 +            // provider.addAlgorithm("Cipher." + PKCSObjectIdentifiers.id_RSAES_OAEP, PREFIX + "CipherSpi$OAEPPadding");
   1582 +            // provider.addAlgorithm("Cipher.RSA/ISO9796-1", PREFIX + "CipherSpi$ISO9796d1Padding");
   1583 +            // END android-removed
   1584  
   1585              provider.addAlgorithm("Alg.Alias.Cipher.RSA//RAW", "RSA");
   1586              provider.addAlgorithm("Alg.Alias.Cipher.RSA//NOPADDING", "RSA");
   1587 -            provider.addAlgorithm("Alg.Alias.Cipher.RSA//PKCS1PADDING", "RSA/PKCS1");
   1588 -            provider.addAlgorithm("Alg.Alias.Cipher.RSA//OAEPPADDING", "RSA/OAEP");
   1589 -            provider.addAlgorithm("Alg.Alias.Cipher.RSA//ISO9796-1PADDING", "RSA/ISO9796-1");
   1590 +            // BEGIN android-removed
   1591 +            // provider.addAlgorithm("Alg.Alias.Cipher.RSA//PKCS1PADDING", "RSA/PKCS1");
   1592 +            // provider.addAlgorithm("Alg.Alias.Cipher.RSA//OAEPPADDING", "RSA/OAEP");
   1593 +            // provider.addAlgorithm("Alg.Alias.Cipher.RSA//ISO9796-1PADDING", "RSA/ISO9796-1");
   1594 +            // END android-removed
   1595  
   1596              provider.addAlgorithm("KeyFactory.RSA", PREFIX + "KeyFactorySpi");
   1597              provider.addAlgorithm("KeyPairGenerator.RSA", PREFIX + "KeyPairGeneratorSpi");
   1598 @@ -68,101 +78,117 @@
   1599              registerOid(provider, PKCSObjectIdentifiers.rsaEncryption, "RSA", keyFact);
   1600              registerOid(provider, X509ObjectIdentifiers.id_ea_rsa, "RSA", keyFact);
   1601              registerOid(provider, PKCSObjectIdentifiers.id_RSAES_OAEP, "RSA", keyFact);
   1602 -            registerOid(provider, PKCSObjectIdentifiers.id_RSASSA_PSS, "RSA", keyFact);
   1603 -
   1604 -            registerOidAlgorithmParameters(provider, PKCSObjectIdentifiers.rsaEncryption, "RSA");
   1605 -            registerOidAlgorithmParameters(provider, X509ObjectIdentifiers.id_ea_rsa, "RSA");
   1606 -            registerOidAlgorithmParameters(provider, PKCSObjectIdentifiers.id_RSAES_OAEP, "OAEP");
   1607 -            registerOidAlgorithmParameters(provider, PKCSObjectIdentifiers.id_RSASSA_PSS, "PSS");
   1608 -
   1609 -
   1610 -            provider.addAlgorithm("Signature.RSASSA-PSS", PREFIX + "PSSSignatureSpi$PSSwithRSA");
   1611 -            provider.addAlgorithm("Signature." + PKCSObjectIdentifiers.id_RSASSA_PSS, PREFIX + "PSSSignatureSpi$PSSwithRSA");
   1612 -            provider.addAlgorithm("Signature.OID." + PKCSObjectIdentifiers.id_RSASSA_PSS, PREFIX + "PSSSignatureSpi$PSSwithRSA");
   1613 -
   1614 -            provider.addAlgorithm("Signature.SHA224withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA224withRSA");
   1615 -            provider.addAlgorithm("Signature.SHA256withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA256withRSA");
   1616 -            provider.addAlgorithm("Signature.SHA384withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA384withRSA");
   1617 -            provider.addAlgorithm("Signature.SHA512withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA512withRSA");
   1618 -
   1619 -            provider.addAlgorithm("Signature.RSA", PREFIX + "DigestSignatureSpi$noneRSA");
   1620 -            provider.addAlgorithm("Signature.RAWRSASSA-PSS", PREFIX + "PSSSignatureSpi$nonePSS");
   1621 -
   1622 -            provider.addAlgorithm("Alg.Alias.Signature.RAWRSA", "RSA");
   1623 -            provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSA", "RSA");
   1624 -            provider.addAlgorithm("Alg.Alias.Signature.RAWRSAPSS", "RAWRSASSA-PSS");
   1625 -            provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSAPSS", "RAWRSASSA-PSS");
   1626 -            provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSASSA-PSS", "RAWRSASSA-PSS");
   1627 -            provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSAANDMGF1", "RAWRSASSA-PSS");
   1628 -            provider.addAlgorithm("Alg.Alias.Signature.RSAPSS", "RSASSA-PSS");
   1629 -
   1630 -
   1631 -            provider.addAlgorithm("Alg.Alias.Signature.SHA224withRSAandMGF1", "SHA224withRSA/PSS");
   1632 -            provider.addAlgorithm("Alg.Alias.Signature.SHA256withRSAandMGF1", "SHA256withRSA/PSS");
   1633 -            provider.addAlgorithm("Alg.Alias.Signature.SHA384withRSAandMGF1", "SHA384withRSA/PSS");
   1634 -            provider.addAlgorithm("Alg.Alias.Signature.SHA512withRSAandMGF1", "SHA512withRSA/PSS");
   1635 -            provider.addAlgorithm("Alg.Alias.Signature.SHA224WITHRSAANDMGF1", "SHA224withRSA/PSS");
   1636 -            provider.addAlgorithm("Alg.Alias.Signature.SHA256WITHRSAANDMGF1", "SHA256withRSA/PSS");
   1637 -            provider.addAlgorithm("Alg.Alias.Signature.SHA384WITHRSAANDMGF1", "SHA384withRSA/PSS");
   1638 -            provider.addAlgorithm("Alg.Alias.Signature.SHA512WITHRSAANDMGF1", "SHA512withRSA/PSS");
   1639 -
   1640 -            if (provider.hasAlgorithm("MessageDigest", "MD2"))
   1641 -            {
   1642 -                addDigestSignature(provider, "MD2", PREFIX + "DigestSignatureSpi$MD2", PKCSObjectIdentifiers.md2WithRSAEncryption);
   1643 -            }
   1644 -
   1645 -            if (provider.hasAlgorithm("MessageDigest", "MD2"))
   1646 -            {
   1647 -                addDigestSignature(provider, "MD4", PREFIX + "DigestSignatureSpi$MD4", PKCSObjectIdentifiers.md4WithRSAEncryption);
   1648 -            }
   1649 -
   1650 -            if (provider.hasAlgorithm("MessageDigest", "MD2"))
   1651 +            // BEGIN android-removed
   1652 +            // registerOid(provider, PKCSObjectIdentifiers.id_RSASSA_PSS, "RSA", keyFact);
   1653 +            //
   1654 +            // registerOidAlgorithmParameters(provider, PKCSObjectIdentifiers.rsaEncryption, "RSA");
   1655 +            // registerOidAlgorithmParameters(provider, X509ObjectIdentifiers.id_ea_rsa, "RSA");
   1656 +            // registerOidAlgorithmParameters(provider, PKCSObjectIdentifiers.id_RSAES_OAEP, "OAEP");
   1657 +            // registerOidAlgorithmParameters(provider, PKCSObjectIdentifiers.id_RSASSA_PSS, "PSS");
   1658 +            //
   1659 +            //
   1660 +            // provider.addAlgorithm("Signature.RSASSA-PSS", PREFIX + "PSSSignatureSpi$PSSwithRSA");
   1661 +            // provider.addAlgorithm("Signature." + PKCSObjectIdentifiers.id_RSASSA_PSS, PREFIX + "PSSSignatureSpi$PSSwithRSA");
   1662 +            // provider.addAlgorithm("Signature.OID." + PKCSObjectIdentifiers.id_RSASSA_PSS, PREFIX + "PSSSignatureSpi$PSSwithRSA");
   1663 +            //
   1664 +            // provider.addAlgorithm("Signature.SHA224withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA224withRSA");
   1665 +            // provider.addAlgorithm("Signature.SHA256withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA256withRSA");
   1666 +            // provider.addAlgorithm("Signature.SHA384withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA384withRSA");
   1667 +            // provider.addAlgorithm("Signature.SHA512withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA512withRSA");
   1668 +            //
   1669 +            // provider.addAlgorithm("Signature.RSA", PREFIX + "DigestSignatureSpi$noneRSA");
   1670 +            // provider.addAlgorithm("Signature.RAWRSASSA-PSS", PREFIX + "PSSSignatureSpi$nonePSS");
   1671 +            //
   1672 +            // provider.addAlgorithm("Alg.Alias.Signature.RAWRSA", "RSA");
   1673 +            // provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSA", "RSA");
   1674 +            // provider.addAlgorithm("Alg.Alias.Signature.RAWRSAPSS", "RAWRSASSA-PSS");
   1675 +            // provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSAPSS", "RAWRSASSA-PSS");
   1676 +            // provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSASSA-PSS", "RAWRSASSA-PSS");
   1677 +            // provider.addAlgorithm("Alg.Alias.Signature.NONEWITHRSAANDMGF1", "RAWRSASSA-PSS");
   1678 +            // provider.addAlgorithm("Alg.Alias.Signature.RSAPSS", "RSASSA-PSS");
   1679 +            //
   1680 +            //
   1681 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA224withRSAandMGF1", "SHA224withRSA/PSS");
   1682 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA256withRSAandMGF1", "SHA256withRSA/PSS");
   1683 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA384withRSAandMGF1", "SHA384withRSA/PSS");
   1684 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA512withRSAandMGF1", "SHA512withRSA/PSS");
   1685 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA224WITHRSAANDMGF1", "SHA224withRSA/PSS");
   1686 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA256WITHRSAANDMGF1", "SHA256withRSA/PSS");
   1687 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA384WITHRSAANDMGF1", "SHA384withRSA/PSS");
   1688 +            // provider.addAlgorithm("Alg.Alias.Signature.SHA512WITHRSAANDMGF1", "SHA512withRSA/PSS");
   1689 +            //
   1690 +            // if (provider.hasAlgorithm("MessageDigest", "MD2"))
   1691 +            // {
   1692 +            //     addDigestSignature(provider, "MD2", PREFIX + "DigestSignatureSpi$MD2", PKCSObjectIdentifiers.md2WithRSAEncryption);
   1693 +            // }
   1694 +            //
   1695 +            // // BEGIN android-changed
   1696 +            // if (provider.hasAlgorithm("MessageDigest", "MD4"))
   1697 +            // // END android-changed
   1698 +            // {
   1699 +            //     addDigestSignature(provider, "MD4", PREFIX + "DigestSignatureSpi$MD4", PKCSObjectIdentifiers.md4WithRSAEncryption);
   1700 +            // }
   1701 +            // END android-removed
   1702 +
   1703 +            // BEGIN android-changed
   1704 +            if (provider.hasAlgorithm("MessageDigest", "MD5"))
   1705 +            // END android-changed
   1706              {
   1707                  addDigestSignature(provider, "MD5", PREFIX + "DigestSignatureSpi$MD5", PKCSObjectIdentifiers.md5WithRSAEncryption);
   1708 -                provider.addAlgorithm("Signature.MD5withRSA/ISO9796-2", PREFIX + "ISOSignatureSpi$MD5WithRSAEncryption");
   1709 -                provider.addAlgorithm("Alg.Alias.Signature.MD5WithRSA/ISO9796-2", "MD5withRSA/ISO9796-2");
   1710 +                // BEGIN android-removed
   1711 +                // provider.addAlgorithm("Signature.MD5withRSA/ISO9796-2", PREFIX + "ISOSignatureSpi$MD5WithRSAEncryption");
   1712 +                // provider.addAlgorithm("Alg.Alias.Signature.MD5WithRSA/ISO9796-2", "MD5withRSA/ISO9796-2");
   1713 +                // END android-removed
   1714              }
   1715  
   1716              if (provider.hasAlgorithm("MessageDigest", "SHA1"))
   1717              {
   1718 -                provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA1withRSA/PSS", "PSS");
   1719 -                provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA1WITHRSAANDMGF1", "PSS");
   1720 -                provider.addAlgorithm("Signature.SHA1withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA1withRSA");
   1721 -                provider.addAlgorithm("Alg.Alias.Signature.SHA1withRSAandMGF1", "SHA1withRSA/PSS");
   1722 -                provider.addAlgorithm("Alg.Alias.Signature.SHA1WITHRSAANDMGF1", "SHA1withRSA/PSS");
   1723 +                // BEGIN android-removed
   1724 +                // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA1withRSA/PSS", "PSS");
   1725 +                // provider.addAlgorithm("Alg.Alias.AlgorithmParameters.SHA1WITHRSAANDMGF1", "PSS");
   1726 +                // provider.addAlgorithm("Signature.SHA1withRSA/PSS", PREFIX + "PSSSignatureSpi$SHA1withRSA");
   1727 +                // provider.addAlgorithm("Alg.Alias.Signature.SHA1withRSAandMGF1", "SHA1withRSA/PSS");
   1728 +                // provider.addAlgorithm("Alg.Alias.Signature.SHA1WITHRSAANDMGF1", "SHA1withRSA/PSS");
   1729 +                // END android-removed
   1730  
   1731                  addDigestSignature(provider, "SHA1", PREFIX + "DigestSignatureSpi$SHA1", PKCSObjectIdentifiers.sha1WithRSAEncryption);
   1732  
   1733 -                provider.addAlgorithm("Alg.Alias.Signature.SHA1WithRSA/ISO9796-2", "SHA1withRSA/ISO9796-2");
   1734 -                provider.addAlgorithm("Signature.SHA1withRSA/ISO9796-2", PREFIX + "ISOSignatureSpi$SHA1WithRSAEncryption");
   1735 +                // BEGIN android-removed
   1736 +                // provider.addAlgorithm("Alg.Alias.Signature.SHA1WithRSA/ISO9796-2", "SHA1withRSA/ISO9796-2");
   1737 +                // provider.addAlgorithm("Signature.SHA1withRSA/ISO9796-2", PREFIX + "ISOSignatureSpi$SHA1WithRSAEncryption");
   1738 +                // END android-removed
   1739                  provider.addAlgorithm("Alg.Alias.Signature." + OIWObjectIdentifiers.sha1WithRSA, "SHA1WITHRSA");
   1740                  provider.addAlgorithm("Alg.Alias.Signature.OID." + OIWObjectIdentifiers.sha1WithRSA, "SHA1WITHRSA");
   1741              }
   1742  
   1743 -            addDigestSignature(provider, "SHA224", PREFIX + "DigestSignatureSpi$SHA224", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   1744 +            // BEGIN android-removed
   1745 +            // addDigestSignature(provider, "SHA224", PREFIX + "DigestSignatureSpi$SHA224", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   1746 +            // END android-removed
   1747              addDigestSignature(provider, "SHA256", PREFIX + "DigestSignatureSpi$SHA256", PKCSObjectIdentifiers.sha256WithRSAEncryption);
   1748              addDigestSignature(provider, "SHA384", PREFIX + "DigestSignatureSpi$SHA384", PKCSObjectIdentifiers.sha384WithRSAEncryption);
   1749              addDigestSignature(provider, "SHA512", PREFIX + "DigestSignatureSpi$SHA512", PKCSObjectIdentifiers.sha512WithRSAEncryption);
   1750  
   1751 -            if (provider.hasAlgorithm("MessageDigest", "RIPEMD128"))
   1752 -            {
   1753 -                addDigestSignature(provider, "RIPEMD128", PREFIX + "DigestSignatureSpi$RIPEMD128", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   1754 -                addDigestSignature(provider, "RMD128", PREFIX + "DigestSignatureSpi$RIPEMD128", null);
   1755 -            }
   1756 -
   1757 -            if (provider.hasAlgorithm("MessageDigest", "RIPEMD160"))
   1758 -            {
   1759 -                addDigestSignature(provider, "RIPEMD160", PREFIX + "DigestSignatureSpi$RIPEMD160", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   1760 -                addDigestSignature(provider, "RMD160", PREFIX + "DigestSignatureSpi$RIPEMD160", null);
   1761 -                provider.addAlgorithm("Alg.Alias.Signature.RIPEMD160WithRSA/ISO9796-2", "RIPEMD160withRSA/ISO9796-2");
   1762 -                provider.addAlgorithm("Signature.RIPEMD160withRSA/ISO9796-2", PREFIX + "ISOSignatureSpi$RIPEMD160WithRSAEncryption");
   1763 -            }
   1764 -
   1765 -            if (provider.hasAlgorithm("MessageDigest", "RIPEMD256"))
   1766 -            {
   1767 -                addDigestSignature(provider, "RIPEMD256", PREFIX + "DigestSignatureSpi$RIPEMD256", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   1768 -                addDigestSignature(provider, "RMD256", PREFIX + "DigestSignatureSpi$RIPEMD256", null);
   1769 -            }
   1770 +            // BEGIN android-removed
   1771 +            // if (provider.hasAlgorithm("MessageDigest", "RIPEMD128"))
   1772 +            // {
   1773 +            //     addDigestSignature(provider, "RIPEMD128", PREFIX + "DigestSignatureSpi$RIPEMD128", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   1774 +            //     addDigestSignature(provider, "RMD128", PREFIX + "DigestSignatureSpi$RIPEMD128", null);
   1775 +            // }
   1776 +            //
   1777 +            // if (provider.hasAlgorithm("MessageDigest", "RIPEMD160"))
   1778 +            // {
   1779 +            //     addDigestSignature(provider, "RIPEMD160", PREFIX + "DigestSignatureSpi$RIPEMD160", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   1780 +            //     addDigestSignature(provider, "RMD160", PREFIX + "DigestSignatureSpi$RIPEMD160", null);
   1781 +            //     provider.addAlgorithm("Alg.Alias.Signature.RIPEMD160WithRSA/ISO9796-2", "RIPEMD160withRSA/ISO9796-2");
   1782 +            //     provider.addAlgorithm("Signature.RIPEMD160withRSA/ISO9796-2", PREFIX + "ISOSignatureSpi$RIPEMD160WithRSAEncryption");
   1783 +            // }
   1784 +            //
   1785 +            // if (provider.hasAlgorithm("MessageDigest", "RIPEMD256"))
   1786 +            // {
   1787 +            //     addDigestSignature(provider, "RIPEMD256", PREFIX + "DigestSignatureSpi$RIPEMD256", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   1788 +            //     addDigestSignature(provider, "RMD256", PREFIX + "DigestSignatureSpi$RIPEMD256", null);
   1789 +            // }
   1790 +            // END android-removed
   1791          }
   1792  
   1793          private void addDigestSignature(
   1794 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/X509.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/X509.java
   1795 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/X509.java	2012-03-22 15:11:48.000000000 +0000
   1796 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/X509.java	2012-09-19 21:17:12.000000000 +0000
   1797 @@ -18,8 +18,10 @@
   1798  
   1799          public void configure(ConfigurableProvider provider)
   1800          {
   1801 -            provider.addAlgorithm("KeyFactory.X.509", "org.bouncycastle.jcajce.provider.asymmetric.x509.KeyFactory");
   1802 -            provider.addAlgorithm("Alg.Alias.KeyFactory.X509", "X.509");
   1803 +            // BEGIN android-removed
   1804 +            // provider.addAlgorithm("KeyFactory.X.509", "org.bouncycastle.jcajce.provider.asymmetric.x509.KeyFactory");
   1805 +            // provider.addAlgorithm("Alg.Alias.KeyFactory.X509", "X.509");
   1806 +            // END android-removed
   1807  
   1808              //
   1809              // certificate factories.
   1810 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyAgreementSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyAgreementSpi.java
   1811 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyAgreementSpi.java	2012-03-22 15:11:48.000000000 +0000
   1812 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyAgreementSpi.java	2012-09-19 21:17:12.000000000 +0000
   1813 @@ -35,10 +35,12 @@
   1814  
   1815      static
   1816      {
   1817 -        Integer i64 = new Integer(64);
   1818 -        Integer i192 = new Integer(192);
   1819 -        Integer i128 = new Integer(128);
   1820 -        Integer i256 = new Integer(256);
   1821 +        // BEGIN android-changed
   1822 +        Integer i64 = Integer.valueOf(64);
   1823 +        Integer i192 = Integer.valueOf(192);
   1824 +        Integer i128 = Integer.valueOf(128);
   1825 +        Integer i256 = Integer.valueOf(256);
   1826 +        // END android-changed
   1827  
   1828          algorithms.put("DES", i64);
   1829          algorithms.put("DESEDE", i192);
   1830 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyPairGeneratorSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyPairGeneratorSpi.java
   1831 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyPairGeneratorSpi.java	2012-03-22 15:11:48.000000000 +0000
   1832 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/dh/KeyPairGeneratorSpi.java	2012-09-19 21:17:12.000000000 +0000
   1833 @@ -63,7 +63,9 @@
   1834      {
   1835          if (!initialised)
   1836          {
   1837 -            Integer paramStrength = new Integer(strength);
   1838 +            // BEGIN android-changed
   1839 +            Integer paramStrength = Integer.valueOf(strength);
   1840 +            // END android-changed
   1841  
   1842              if (params.containsKey(paramStrength))
   1843              {
   1844 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/dsa/DSASigner.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/dsa/DSASigner.java
   1845 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/dsa/DSASigner.java	2012-03-22 15:11:48.000000000 +0000
   1846 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/dsa/DSASigner.java	2012-09-19 21:17:12.000000000 +0000
   1847 @@ -23,11 +23,16 @@
   1848  import org.bouncycastle.crypto.DSA;
   1849  import org.bouncycastle.crypto.Digest;
   1850  import org.bouncycastle.crypto.digests.NullDigest;
   1851 -import org.bouncycastle.crypto.digests.SHA1Digest;
   1852 -import org.bouncycastle.crypto.digests.SHA224Digest;
   1853 -import org.bouncycastle.crypto.digests.SHA256Digest;
   1854 -import org.bouncycastle.crypto.digests.SHA384Digest;
   1855 -import org.bouncycastle.crypto.digests.SHA512Digest;
   1856 +// BEGIN android-added
   1857 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   1858 +// END android-added
   1859 +// BEGIN android-removed
   1860 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   1861 +// import org.bouncycastle.crypto.digests.SHA224Digest;
   1862 +// import org.bouncycastle.crypto.digests.SHA256Digest;
   1863 +// import org.bouncycastle.crypto.digests.SHA384Digest;
   1864 +// import org.bouncycastle.crypto.digests.SHA512Digest;
   1865 +// END android-removed
   1866  import org.bouncycastle.crypto.params.ParametersWithRandom;
   1867  
   1868  public class DSASigner
   1869 @@ -228,45 +233,49 @@
   1870      {
   1871          public stdDSA()
   1872          {
   1873 -            super(new SHA1Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1874 +            // BEGIN android-changed
   1875 +            super(AndroidDigestFactory.getSHA1(), new org.bouncycastle.crypto.signers.DSASigner());
   1876 +            // END android-changed
   1877          }
   1878      }
   1879  
   1880 -    static public class dsa224
   1881 -        extends DSASigner
   1882 -    {
   1883 -        public dsa224()
   1884 -        {
   1885 -            super(new SHA224Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1886 -        }
   1887 -    }
   1888 -    
   1889 -    static public class dsa256
   1890 -        extends DSASigner
   1891 -    {
   1892 -        public dsa256()
   1893 -        {
   1894 -            super(new SHA256Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1895 -        }
   1896 -    }
   1897 -    
   1898 -    static public class dsa384
   1899 -        extends DSASigner
   1900 -    {
   1901 -        public dsa384()
   1902 -        {
   1903 -            super(new SHA384Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1904 -        }
   1905 -    }
   1906 -    
   1907 -    static public class dsa512
   1908 -        extends DSASigner
   1909 -    {
   1910 -        public dsa512()
   1911 -        {
   1912 -            super(new SHA512Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1913 -        }
   1914 -    }
   1915 +    // BEGIN android-removed
   1916 +    // static public class dsa224
   1917 +    //     extends DSASigner
   1918 +    // {
   1919 +    //     public dsa224()
   1920 +    //     {
   1921 +    //         super(new SHA224Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1922 +    //     }
   1923 +    // }
   1924 +    //
   1925 +    // static public class dsa256
   1926 +    //     extends DSASigner
   1927 +    // {
   1928 +    //     public dsa256()
   1929 +    //     {
   1930 +    //         super(new SHA256Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1931 +    //     }
   1932 +    // }
   1933 +    //
   1934 +    // static public class dsa384
   1935 +    //     extends DSASigner
   1936 +    // {
   1937 +    //     public dsa384()
   1938 +    //     {
   1939 +    //         super(new SHA384Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1940 +    //     }
   1941 +    // }
   1942 +    //
   1943 +    // static public class dsa512
   1944 +    //     extends DSASigner
   1945 +    // {
   1946 +    //     public dsa512()
   1947 +    //     {
   1948 +    //         super(new SHA512Digest(), new org.bouncycastle.crypto.signers.DSASigner());
   1949 +    //     }
   1950 +    // }
   1951 +    // END android-removed
   1952  
   1953      static public class noneDSA
   1954          extends DSASigner
   1955 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java
   1956 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java	2012-03-22 15:11:48.000000000 +0000
   1957 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java	2012-09-19 21:17:12.000000000 +0000
   1958 @@ -19,8 +19,10 @@
   1959  import org.bouncycastle.asn1.DERInteger;
   1960  import org.bouncycastle.asn1.DERNull;
   1961  import org.bouncycastle.asn1.DERObjectIdentifier;
   1962 -import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   1963 -import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   1964 +// BEGIN android-removed
   1965 +// import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   1966 +// import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   1967 +// END android-removed
   1968  import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
   1969  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   1970  import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
   1971 @@ -222,21 +224,23 @@
   1972              ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());
   1973              X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
   1974  
   1975 -            if (ecP == null) // GOST Curve
   1976 -            {
   1977 -                ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
   1978 -                EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
   1979 -
   1980 -                ecSpec = new ECNamedCurveSpec(
   1981 -                        ECGOST3410NamedCurves.getName(oid),
   1982 -                        ellipticCurve,
   1983 -                        new ECPoint(
   1984 -                                gParam.getG().getX().toBigInteger(),
   1985 -                                gParam.getG().getY().toBigInteger()),
   1986 -                        gParam.getN(),
   1987 -                        gParam.getH());
   1988 -            }
   1989 -            else
   1990 +            // BEGIN android-removed
   1991 +            // if (ecP == null) // GOST Curve
   1992 +            // {
   1993 +            //     ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
   1994 +            //     EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
   1995 +            //
   1996 +            //     ecSpec = new ECNamedCurveSpec(
   1997 +            //             ECGOST3410NamedCurves.getName(oid),
   1998 +            //             ellipticCurve,
   1999 +            //             new ECPoint(
   2000 +            //                     gParam.getG().getX().toBigInteger(),
   2001 +            //                     gParam.getG().getY().toBigInteger()),
   2002 +            //             gParam.getN(),
   2003 +            //             gParam.getH());
   2004 +            // }
   2005 +            // else
   2006 +            // END android-removed
   2007              {
   2008                  EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
   2009  
   2010 @@ -350,11 +354,13 @@
   2011  
   2012          try
   2013          {
   2014 -            if (algorithm.equals("ECGOST3410"))
   2015 -            {
   2016 -                info = new PrivateKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params.toASN1Primitive()), keyStructure.toASN1Primitive());
   2017 -            }
   2018 -            else
   2019 +            // BEGIN android-removed
   2020 +            // if (algorithm.equals("ECGOST3410"))
   2021 +            // {
   2022 +            //     info = new PrivateKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params.toASN1Primitive()), keyStructure.toASN1Primitive());
   2023 +            // }
   2024 +            // else
   2025 +            // END android-removed
   2026              {
   2027  
   2028                  info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.toASN1Primitive()), keyStructure.toASN1Primitive());
   2029 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/ECUtil.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/ECUtil.java
   2030 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/ECUtil.java	2012-03-22 15:11:48.000000000 +0000
   2031 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/ECUtil.java	2012-09-19 21:17:12.000000000 +0000
   2032 @@ -5,10 +5,14 @@
   2033  import java.security.PublicKey;
   2034  
   2035  import org.bouncycastle.asn1.ASN1ObjectIdentifier;
   2036 -import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   2037 +// BEGIN android-removed
   2038 +// import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   2039 +// END android-removed
   2040  import org.bouncycastle.asn1.nist.NISTNamedCurves;
   2041  import org.bouncycastle.asn1.sec.SECNamedCurves;
   2042 -import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   2043 +// BEGIN android-removed
   2044 +// import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   2045 +// END android-removed
   2046  import org.bouncycastle.asn1.x9.X962NamedCurves;
   2047  import org.bouncycastle.asn1.x9.X9ECParameters;
   2048  import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
   2049 @@ -166,14 +170,16 @@
   2050              {
   2051                  oid = NISTNamedCurves.getOID(name);
   2052              }
   2053 -            if (oid == null)
   2054 -            {
   2055 -                oid = TeleTrusTNamedCurves.getOID(name);
   2056 -            }
   2057 -            if (oid == null)
   2058 -            {
   2059 -                oid = ECGOST3410NamedCurves.getOID(name);
   2060 -            }
   2061 +            // BEGIN android-removed
   2062 +            // if (oid == null)
   2063 +            // {
   2064 +            //     oid = TeleTrusTNamedCurves.getOID(name);
   2065 +            // }
   2066 +            // if (oid == null)
   2067 +            // {
   2068 +            //     oid = ECGOST3410NamedCurves.getOID(name);
   2069 +            // }
   2070 +            // END android-removed
   2071          }
   2072  
   2073          return oid;
   2074 @@ -191,10 +197,12 @@
   2075              {
   2076                  params = NISTNamedCurves.getByOID(oid);
   2077              }
   2078 -            if (params == null)
   2079 -            {
   2080 -                params = TeleTrusTNamedCurves.getByOID(oid);
   2081 -            }
   2082 +            // BEGIN android-removed
   2083 +            // if (params == null)
   2084 +            // {
   2085 +            //     params = TeleTrusTNamedCurves.getByOID(oid);
   2086 +            // }
   2087 +            // END android-removed
   2088          }
   2089  
   2090          return params;
   2091 @@ -212,14 +220,16 @@
   2092              {
   2093                  name = NISTNamedCurves.getName(oid);
   2094              }
   2095 -            if (name == null)
   2096 -            {
   2097 -                name = TeleTrusTNamedCurves.getName(oid);
   2098 -            }
   2099 -            if (name == null)
   2100 -            {
   2101 -                name = ECGOST3410NamedCurves.getName(oid);
   2102 -            }
   2103 +            // BEGIN android-removed
   2104 +            // if (name == null)
   2105 +            // {
   2106 +            //     name = TeleTrusTNamedCurves.getName(oid);
   2107 +            // }
   2108 +            // if (name == null)
   2109 +            // {
   2110 +            //     name = ECGOST3410NamedCurves.getName(oid);
   2111 +            // }
   2112 +            // END android-removed
   2113          }
   2114  
   2115          return name;
   2116 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyAgreementSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyAgreementSpi.java
   2117 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyAgreementSpi.java	2012-03-22 15:11:48.000000000 +0000
   2118 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyAgreementSpi.java	2012-09-19 21:17:12.000000000 +0000
   2119 @@ -23,20 +23,26 @@
   2120  import org.bouncycastle.crypto.CipherParameters;
   2121  import org.bouncycastle.crypto.DerivationFunction;
   2122  import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
   2123 -import org.bouncycastle.crypto.agreement.ECDHCBasicAgreement;
   2124 -import org.bouncycastle.crypto.agreement.ECMQVBasicAgreement;
   2125 -import org.bouncycastle.crypto.agreement.kdf.DHKDFParameters;
   2126 -import org.bouncycastle.crypto.agreement.kdf.ECDHKEKGenerator;
   2127 +// BEGIN android-removed
   2128 +// import org.bouncycastle.crypto.agreement.ECDHCBasicAgreement;
   2129 +// import org.bouncycastle.crypto.agreement.ECMQVBasicAgreement;
   2130 +// import org.bouncycastle.crypto.agreement.kdf.DHKDFParameters;
   2131 +// import org.bouncycastle.crypto.agreement.kdf.ECDHKEKGenerator;
   2132 +// END android-removed
   2133  import org.bouncycastle.crypto.digests.SHA1Digest;
   2134  import org.bouncycastle.crypto.params.ECDomainParameters;
   2135  import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
   2136  import org.bouncycastle.crypto.params.ECPublicKeyParameters;
   2137 -import org.bouncycastle.crypto.params.MQVPrivateParameters;
   2138 -import org.bouncycastle.crypto.params.MQVPublicParameters;
   2139 +// BEGIN android-removed
   2140 +// import org.bouncycastle.crypto.params.MQVPrivateParameters;
   2141 +// import org.bouncycastle.crypto.params.MQVPublicParameters;
   2142 +// END android-removed
   2143  import org.bouncycastle.jce.interfaces.ECPrivateKey;
   2144  import org.bouncycastle.jce.interfaces.ECPublicKey;
   2145 -import org.bouncycastle.jce.interfaces.MQVPrivateKey;
   2146 -import org.bouncycastle.jce.interfaces.MQVPublicKey;
   2147 +// BEGIN android-removed
   2148 +// import org.bouncycastle.jce.interfaces.MQVPrivateKey;
   2149 +// import org.bouncycastle.jce.interfaces.MQVPublicKey;
   2150 +// END android-removed
   2151  
   2152  /**
   2153   * Diffie-Hellman key agreement using elliptic curve keys, ala IEEE P1363
   2154 @@ -52,9 +58,11 @@
   2155  
   2156      static
   2157      {
   2158 -        Integer i128 = new Integer(128);
   2159 -        Integer i192 = new Integer(192);
   2160 -        Integer i256 = new Integer(256);
   2161 +        // BEGIN android-changed
   2162 +        Integer i128 = Integer.valueOf(128);
   2163 +        Integer i192 = Integer.valueOf(192);
   2164 +        Integer i256 = Integer.valueOf(256);
   2165 +        // END android-changed
   2166  
   2167          algorithms.put(NISTObjectIdentifiers.id_aes128_CBC.getId(), i128);
   2168          algorithms.put(NISTObjectIdentifiers.id_aes192_CBC.getId(), i192);
   2169 @@ -69,7 +77,9 @@
   2170      private BigInteger             result;
   2171      private ECDomainParameters     parameters;
   2172      private BasicAgreement         agreement;
   2173 -    private DerivationFunction     kdf;
   2174 +    // BEGIN android-removed
   2175 +    // private DerivationFunction     kdf;
   2176 +    // END android-removed
   2177  
   2178      private byte[] bigIntToBytes(
   2179          BigInteger    r)
   2180 @@ -84,7 +94,9 @@
   2181      {
   2182          this.kaAlgorithm = kaAlgorithm;
   2183          this.agreement = agreement;
   2184 -        this.kdf = kdf;
   2185 +        // BEGIN android-removed
   2186 +        // this.kdf = kdf;
   2187 +        // END android-removed
   2188      }
   2189  
   2190      protected Key engineDoPhase(
   2191 @@ -103,25 +115,27 @@
   2192          }
   2193  
   2194          CipherParameters pubKey;        
   2195 -        if (agreement instanceof ECMQVBasicAgreement)
   2196 -        {
   2197 -            if (!(key instanceof MQVPublicKey))
   2198 -            {
   2199 -                throw new InvalidKeyException(kaAlgorithm + " key agreement requires "
   2200 -                    + getSimpleName(MQVPublicKey.class) + " for doPhase");
   2201 -            }
   2202 -
   2203 -            MQVPublicKey mqvPubKey = (MQVPublicKey)key;
   2204 -            ECPublicKeyParameters staticKey = (ECPublicKeyParameters)
   2205 -                ECUtil.generatePublicKeyParameter(mqvPubKey.getStaticKey());
   2206 -            ECPublicKeyParameters ephemKey = (ECPublicKeyParameters)
   2207 -                ECUtil.generatePublicKeyParameter(mqvPubKey.getEphemeralKey());
   2208 -
   2209 -            pubKey = new MQVPublicParameters(staticKey, ephemKey);
   2210 -
   2211 -            // TODO Validate that all the keys are using the same parameters?
   2212 -        }
   2213 -        else
   2214 +        // BEGIN android-removed
   2215 +        // if (agreement instanceof ECMQVBasicAgreement)
   2216 +        // {
   2217 +        //     if (!(key instanceof MQVPublicKey))
   2218 +        //     {
   2219 +        //         throw new InvalidKeyException(kaAlgorithm + " key agreement requires "
   2220 +        //             + getSimpleName(MQVPublicKey.class) + " for doPhase");
   2221 +        //     }
   2222 +        //
   2223 +        //     MQVPublicKey mqvPubKey = (MQVPublicKey)key;
   2224 +        //     ECPublicKeyParameters staticKey = (ECPublicKeyParameters)
   2225 +        //         ECUtil.generatePublicKeyParameter(mqvPubKey.getStaticKey());
   2226 +        //     ECPublicKeyParameters ephemKey = (ECPublicKeyParameters)
   2227 +        //         ECUtil.generatePublicKeyParameter(mqvPubKey.getEphemeralKey());
   2228 +        //
   2229 +        //     pubKey = new MQVPublicParameters(staticKey, ephemKey);
   2230 +        //
   2231 +        //     // TODO Validate that all the keys are using the same parameters?
   2232 +        // }
   2233 +        // else
   2234 +        // END android-removed
   2235          {
   2236              if (!(key instanceof ECPublicKey))
   2237              {
   2238 @@ -142,11 +156,13 @@
   2239      protected byte[] engineGenerateSecret()
   2240          throws IllegalStateException
   2241      {
   2242 -        if (kdf != null)
   2243 -        {
   2244 -            throw new UnsupportedOperationException(
   2245 -                "KDF can only be used when algorithm is known");
   2246 -        }
   2247 +        // BEGIN android-removed
   2248 +        // if (kdf != null)
   2249 +        // {
   2250 +        //     throw new UnsupportedOperationException(
   2251 +        //         "KDF can only be used when algorithm is known");
   2252 +        // }
   2253 +        // END android-removed
   2254  
   2255          return bigIntToBytes(result);
   2256      }
   2257 @@ -174,23 +190,25 @@
   2258      {
   2259          byte[] secret = bigIntToBytes(result);
   2260  
   2261 -        if (kdf != null)
   2262 -        {
   2263 -            if (!algorithms.containsKey(algorithm))
   2264 -            {
   2265 -                throw new NoSuchAlgorithmException("unknown algorithm encountered: " + algorithm);
   2266 -            }
   2267 -            
   2268 -            int    keySize = ((Integer)algorithms.get(algorithm)).intValue();
   2269 -
   2270 -            DHKDFParameters params = new DHKDFParameters(new DERObjectIdentifier(algorithm), keySize, secret);
   2271 -
   2272 -            byte[] keyBytes = new byte[keySize / 8];
   2273 -            kdf.init(params);
   2274 -            kdf.generateBytes(keyBytes, 0, keyBytes.length);
   2275 -            secret = keyBytes;
   2276 -        }
   2277 -        else
   2278 +        // BEGIN android-removed
   2279 +        // if (kdf != null)
   2280 +        // {
   2281 +        //     if (!algorithms.containsKey(algorithm))
   2282 +        //     {
   2283 +        //         throw new NoSuchAlgorithmException("unknown algorithm encountered: " + algorithm);
   2284 +        //     }
   2285 +        //  
   2286 +        //     int    keySize = ((Integer)algorithms.get(algorithm)).intValue();
   2287 +        //
   2288 +        //     DHKDFParameters params = new DHKDFParameters(new DERObjectIdentifier(algorithm), keySize, secret);
   2289 +        //
   2290 +        //     byte[] keyBytes = new byte[keySize / 8];
   2291 +        //     kdf.init(params);
   2292 +        //     kdf.generateBytes(keyBytes, 0, keyBytes.length);
   2293 +        //     secret = keyBytes;
   2294 +        // }
   2295 +        // else
   2296 +        // END android-removed
   2297          {
   2298              // TODO Should we be ensuring the key is the right length?
   2299          }
   2300 @@ -218,35 +236,37 @@
   2301      private void initFromKey(Key key)
   2302          throws InvalidKeyException
   2303      {
   2304 -        if (agreement instanceof ECMQVBasicAgreement)
   2305 -        {
   2306 -            if (!(key instanceof MQVPrivateKey))
   2307 -            {
   2308 -                throw new InvalidKeyException(kaAlgorithm + " key agreement requires "
   2309 -                    + getSimpleName(MQVPrivateKey.class) + " for initialisation");
   2310 -            }
   2311 -
   2312 -            MQVPrivateKey mqvPrivKey = (MQVPrivateKey)key;
   2313 -            ECPrivateKeyParameters staticPrivKey = (ECPrivateKeyParameters)
   2314 -                ECUtil.generatePrivateKeyParameter(mqvPrivKey.getStaticPrivateKey());
   2315 -            ECPrivateKeyParameters ephemPrivKey = (ECPrivateKeyParameters)
   2316 -                ECUtil.generatePrivateKeyParameter(mqvPrivKey.getEphemeralPrivateKey());
   2317 -
   2318 -            ECPublicKeyParameters ephemPubKey = null;
   2319 -            if (mqvPrivKey.getEphemeralPublicKey() != null)
   2320 -            {
   2321 -                ephemPubKey = (ECPublicKeyParameters)
   2322 -                    ECUtil.generatePublicKeyParameter(mqvPrivKey.getEphemeralPublicKey());
   2323 -            }
   2324 -
   2325 -            MQVPrivateParameters localParams = new MQVPrivateParameters(staticPrivKey, ephemPrivKey, ephemPubKey);
   2326 -            this.parameters = staticPrivKey.getParameters();
   2327 -
   2328 -            // TODO Validate that all the keys are using the same parameters?
   2329 -
   2330 -            agreement.init(localParams);
   2331 -        }
   2332 -        else
   2333 +        // BEGIN android-removed
   2334 +        // if (agreement instanceof ECMQVBasicAgreement)
   2335 +        // {
   2336 +        //     if (!(key instanceof MQVPrivateKey))
   2337 +        //     {
   2338 +        //         throw new InvalidKeyException(kaAlgorithm + " key agreement requires "
   2339 +        //             + getSimpleName(MQVPrivateKey.class) + " for initialisation");
   2340 +        //     }
   2341 +        //
   2342 +        //     MQVPrivateKey mqvPrivKey = (MQVPrivateKey)key;
   2343 +        //     ECPrivateKeyParameters staticPrivKey = (ECPrivateKeyParameters)
   2344 +        //         ECUtil.generatePrivateKeyParameter(mqvPrivKey.getStaticPrivateKey());
   2345 +        //     ECPrivateKeyParameters ephemPrivKey = (ECPrivateKeyParameters)
   2346 +        //         ECUtil.generatePrivateKeyParameter(mqvPrivKey.getEphemeralPrivateKey());
   2347 +        //
   2348 +        //     ECPublicKeyParameters ephemPubKey = null;
   2349 +        //     if (mqvPrivKey.getEphemeralPublicKey() != null)
   2350 +        //     {
   2351 +        //         ephemPubKey = (ECPublicKeyParameters)
   2352 +        //             ECUtil.generatePublicKeyParameter(mqvPrivKey.getEphemeralPublicKey());
   2353 +        //     }
   2354 +        //
   2355 +        //     MQVPrivateParameters localParams = new MQVPrivateParameters(staticPrivKey, ephemPrivKey, ephemPubKey);
   2356 +        //     this.parameters = staticPrivKey.getParameters();
   2357 +        //
   2358 +        //     // TODO Validate that all the keys are using the same parameters?
   2359 +        //
   2360 +        //     agreement.init(localParams);
   2361 +        // }
   2362 +        // else
   2363 +        // END android-removed
   2364          {
   2365              if (!(key instanceof ECPrivateKey))
   2366              {
   2367 @@ -277,39 +297,41 @@
   2368          }
   2369      }
   2370  
   2371 -    public static class DHC
   2372 -        extends KeyAgreementSpi
   2373 -    {
   2374 -        public DHC()
   2375 -        {
   2376 -            super("ECDHC", new ECDHCBasicAgreement(), null);
   2377 -        }
   2378 -    }
   2379 -
   2380 -    public static class MQV
   2381 -        extends KeyAgreementSpi
   2382 -    {
   2383 -        public MQV()
   2384 -        {
   2385 -            super("ECMQV", new ECMQVBasicAgreement(), null);
   2386 -        }
   2387 -    }
   2388 -
   2389 -    public static class DHwithSHA1KDF
   2390 -        extends KeyAgreementSpi
   2391 -    {
   2392 -        public DHwithSHA1KDF()
   2393 -        {
   2394 -            super("ECDHwithSHA1KDF", new ECDHBasicAgreement(), new ECDHKEKGenerator(new SHA1Digest()));
   2395 -        }
   2396 -    }
   2397 -
   2398 -    public static class MQVwithSHA1KDF
   2399 -        extends KeyAgreementSpi
   2400 -    {
   2401 -        public MQVwithSHA1KDF()
   2402 -        {
   2403 -            super("ECMQVwithSHA1KDF", new ECMQVBasicAgreement(), new ECDHKEKGenerator(new SHA1Digest()));
   2404 -        }
   2405 -    }
   2406 +    // BEGIN android-removed
   2407 +    // public static class DHC
   2408 +    //     extends KeyAgreementSpi
   2409 +    // {
   2410 +    //     public DHC()
   2411 +    //     {
   2412 +    //         super("ECDHC", new ECDHCBasicAgreement(), null);
   2413 +    //     }
   2414 +    // }
   2415 +    //
   2416 +    // public static class MQV
   2417 +    //     extends KeyAgreementSpi
   2418 +    // {
   2419 +    //     public MQV()
   2420 +    //     {
   2421 +    //         super("ECMQV", new ECMQVBasicAgreement(), null);
   2422 +    //     }
   2423 +    // }
   2424 +    //
   2425 +    // public static class DHwithSHA1KDF
   2426 +    //     extends KeyAgreementSpi
   2427 +    // {
   2428 +    //     public DHwithSHA1KDF()
   2429 +    //     {
   2430 +    //         super("ECDHwithSHA1KDF", new ECDHBasicAgreement(), new ECDHKEKGenerator(new SHA1Digest()));
   2431 +    //     }
   2432 +    // }
   2433 +    //
   2434 +    // public static class MQVwithSHA1KDF
   2435 +    //     extends KeyAgreementSpi
   2436 +    // {
   2437 +    //     public MQVwithSHA1KDF()
   2438 +    //     {
   2439 +    //         super("ECMQVwithSHA1KDF", new ECMQVBasicAgreement(), new ECDHKEKGenerator(new SHA1Digest()));
   2440 +    //     }
   2441 +    // }
   2442 +    // END android-removed
   2443  }
   2444 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyFactorySpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyFactorySpi.java
   2445 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyFactorySpi.java	2012-03-22 15:11:48.000000000 +0000
   2446 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyFactorySpi.java	2012-09-19 21:17:12.000000000 +0000
   2447 @@ -200,14 +200,16 @@
   2448          }
   2449      }
   2450  
   2451 -    public static class ECGOST3410
   2452 -        extends KeyFactorySpi
   2453 -    {
   2454 -        public ECGOST3410()
   2455 -        {
   2456 -            super("ECGOST3410", BouncyCastleProvider.CONFIGURATION);
   2457 -        }
   2458 -    }
   2459 +    // BEGIN android-removed
   2460 +    // public static class ECGOST3410
   2461 +    //     extends KeyFactorySpi
   2462 +    // {
   2463 +    //     public ECGOST3410()
   2464 +    //     {
   2465 +    //         super("ECGOST3410", BouncyCastleProvider.CONFIGURATION);
   2466 +    //     }
   2467 +    // }
   2468 +    // END android-removed
   2469  
   2470      public static class ECDH
   2471          extends KeyFactorySpi
   2472 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyPairGeneratorSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyPairGeneratorSpi.java
   2473 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyPairGeneratorSpi.java	2012-03-22 15:11:48.000000000 +0000
   2474 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/KeyPairGeneratorSpi.java	2012-09-19 21:17:12.000000000 +0000
   2475 @@ -12,7 +12,9 @@
   2476  import org.bouncycastle.asn1.ASN1ObjectIdentifier;
   2477  import org.bouncycastle.asn1.nist.NISTNamedCurves;
   2478  import org.bouncycastle.asn1.sec.SECNamedCurves;
   2479 -import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   2480 +// BEGIN android-removed
   2481 +// import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   2482 +// END android-removed
   2483  import org.bouncycastle.asn1.x9.X962NamedCurves;
   2484  import org.bouncycastle.asn1.x9.X9ECParameters;
   2485  import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
   2486 @@ -55,13 +57,15 @@
   2487          static {
   2488              ecParameters = new Hashtable();
   2489  
   2490 -            ecParameters.put(new Integer(192), new ECGenParameterSpec("prime192v1")); // a.k.a P-192
   2491 -            ecParameters.put(new Integer(239), new ECGenParameterSpec("prime239v1"));
   2492 -            ecParameters.put(new Integer(256), new ECGenParameterSpec("prime256v1")); // a.k.a P-256
   2493 -
   2494 -            ecParameters.put(new Integer(224), new ECGenParameterSpec("P-224"));
   2495 -            ecParameters.put(new Integer(384), new ECGenParameterSpec("P-384"));
   2496 -            ecParameters.put(new Integer(521), new ECGenParameterSpec("P-521"));
   2497 +            // BEGIN android-changed
   2498 +            ecParameters.put(Integer.valueOf(192), new ECGenParameterSpec("prime192v1")); // a.k.a P-192
   2499 +            ecParameters.put(Integer.valueOf(239), new ECGenParameterSpec("prime239v1"));
   2500 +            ecParameters.put(Integer.valueOf(256), new ECGenParameterSpec("prime256v1")); // a.k.a P-256
   2501 +
   2502 +            ecParameters.put(Integer.valueOf(224), new ECGenParameterSpec("P-224"));
   2503 +            ecParameters.put(Integer.valueOf(384), new ECGenParameterSpec("P-384"));
   2504 +            ecParameters.put(Integer.valueOf(521), new ECGenParameterSpec("P-521"));
   2505 +            // END android-changed
   2506          }
   2507  
   2508          public EC()
   2509 @@ -85,8 +89,16 @@
   2510              SecureRandom    random)
   2511          {
   2512              this.strength = strength;
   2513 +            // BEGIN android-added
   2514 +            if (random != null) {
   2515 +            // END android-added
   2516              this.random = random;
   2517 -            ECGenParameterSpec ecParams = (ECGenParameterSpec)ecParameters.get(new Integer(strength));
   2518 +            // BEGIN android-added
   2519 +            }
   2520 +            // END android-added
   2521 +            // BEGIN android-changed
   2522 +            ECGenParameterSpec ecParams = (ECGenParameterSpec)ecParameters.get(Integer.valueOf(strength));
   2523 +            // END android-changed
   2524  
   2525              if (ecParams != null)
   2526              {
   2527 @@ -110,6 +122,11 @@
   2528              SecureRandom            random)
   2529              throws InvalidAlgorithmParameterException
   2530          {
   2531 +            // BEGIN android-added
   2532 +            if (random == null) {
   2533 +                random = this.random;
   2534 +            }
   2535 +            // END android-added
   2536              if (params instanceof ECParameterSpec)
   2537              {
   2538                  ECParameterSpec p = (ECParameterSpec)params;
   2539 @@ -154,10 +171,12 @@
   2540                      {
   2541                          ecP = NISTNamedCurves.getByName(curveName);
   2542                      }
   2543 -                    if (ecP == null)
   2544 -                    {
   2545 -                        ecP = TeleTrusTNamedCurves.getByName(curveName);
   2546 -                    }
   2547 +                    // BEGIN android-removed
   2548 +                    // if (ecP == null)
   2549 +                    // {
   2550 +                    //     ecP = TeleTrusTNamedCurves.getByName(curveName);
   2551 +                    // }
   2552 +                    // END android-removed
   2553                      if (ecP == null)
   2554                      {
   2555                          // See if it's actually an OID string (SunJSSE ServerHandshaker setupEphemeralECDHKeys bug)
   2556 @@ -173,10 +192,12 @@
   2557                              {
   2558                                  ecP = NISTNamedCurves.getByOID(oid);
   2559                              }
   2560 -                            if (ecP == null)
   2561 -                            {
   2562 -                                ecP = TeleTrusTNamedCurves.getByOID(oid);
   2563 -                            }
   2564 +                            // BEGIN android-removed
   2565 +                            // if (ecP == null)
   2566 +                            // {
   2567 +                            //     ecP = TeleTrusTNamedCurves.getByOID(oid);
   2568 +                            // }
   2569 +                            // END android-removed
   2570                              if (ecP == null)
   2571                              {
   2572                                  throw new InvalidAlgorithmParameterException("unknown curve OID: " + curveName);
   2573 @@ -231,7 +252,15 @@
   2574          {
   2575              if (!initialised)
   2576              {
   2577 -                throw new IllegalStateException("EC Key Pair Generator not initialised");
   2578 +                // BEGIN android-removed
   2579 +                // throw new IllegalStateException("EC Key Pair Generator not initialised");
   2580 +                // END android-removed
   2581 +                // BEGIN android-added
   2582 +                /*
   2583 +                 * KeyPairGenerator documentation says that a default initialization must be provided
   2584 +                 */
   2585 +                initialize(192, random);
   2586 +                // END android-added
   2587              }
   2588  
   2589              AsymmetricCipherKeyPair     pair = engine.generateKeyPair();
   2590 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java
   2591 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java	2012-03-22 15:11:48.000000000 +0000
   2592 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java	2012-09-19 21:17:12.000000000 +0000
   2593 @@ -18,15 +18,22 @@
   2594  import org.bouncycastle.crypto.DSA;
   2595  import org.bouncycastle.crypto.Digest;
   2596  import org.bouncycastle.crypto.digests.NullDigest;
   2597 -import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   2598 -import org.bouncycastle.crypto.digests.SHA1Digest;
   2599 -import org.bouncycastle.crypto.digests.SHA224Digest;
   2600 -import org.bouncycastle.crypto.digests.SHA256Digest;
   2601 -import org.bouncycastle.crypto.digests.SHA384Digest;
   2602 -import org.bouncycastle.crypto.digests.SHA512Digest;
   2603 +// BEGIN android-added
   2604 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   2605 +// END android-added
   2606 +// BEGIN android-removed
   2607 +// import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   2608 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   2609 +// import org.bouncycastle.crypto.digests.SHA224Digest;
   2610 +// import org.bouncycastle.crypto.digests.SHA256Digest;
   2611 +// import org.bouncycastle.crypto.digests.SHA384Digest;
   2612 +// import org.bouncycastle.crypto.digests.SHA512Digest;
   2613 +// END android-removed
   2614  import org.bouncycastle.crypto.params.ParametersWithRandom;
   2615  import org.bouncycastle.crypto.signers.ECDSASigner;
   2616 -import org.bouncycastle.crypto.signers.ECNRSigner;
   2617 +// BEGIN android-removed
   2618 +// import org.bouncycastle.crypto.signers.ECNRSigner;
   2619 +// END android-removed
   2620  import org.bouncycastle.jcajce.provider.asymmetric.util.DSABase;
   2621  import org.bouncycastle.jcajce.provider.asymmetric.util.DSAEncoder;
   2622  import org.bouncycastle.jce.interfaces.ECKey;
   2623 @@ -108,7 +115,9 @@
   2624      {
   2625          public ecDSA()
   2626          {
   2627 -            super(new SHA1Digest(), new ECDSASigner(), new StdDSAEncoder());
   2628 +            // BEGIN android-changed
   2629 +            super(AndroidDigestFactory.getSHA1(), new ECDSASigner(), new StdDSAEncoder());
   2630 +            // END android-changed
   2631          }
   2632      }
   2633  
   2634 @@ -121,21 +130,25 @@
   2635          }
   2636      }
   2637  
   2638 -    static public class ecDSA224
   2639 -        extends SignatureSpi
   2640 -    {
   2641 -        public ecDSA224()
   2642 -        {
   2643 -            super(new SHA224Digest(), new ECDSASigner(), new StdDSAEncoder());
   2644 -        }
   2645 -    }
   2646 +    // BEGIN android-removed
   2647 +    // static public class ecDSA224
   2648 +    //     extends SignatureSpi
   2649 +    // {
   2650 +    //     public ecDSA224()
   2651 +    //     {
   2652 +    //         super(new SHA224Digest(), new ECDSASigner(), new StdDSAEncoder());
   2653 +    //     }
   2654 +    // }
   2655 +    // END android-removed
   2656  
   2657      static public class ecDSA256
   2658          extends SignatureSpi
   2659      {
   2660          public ecDSA256()
   2661          {
   2662 -            super(new SHA256Digest(), new ECDSASigner(), new StdDSAEncoder());
   2663 +            // BEGIN android-changed
   2664 +            super(AndroidDigestFactory.getSHA256(), new ECDSASigner(), new StdDSAEncoder());
   2665 +            // END android-changed
   2666          }
   2667      }
   2668  
   2669 @@ -144,7 +157,9 @@
   2670      {
   2671          public ecDSA384()
   2672          {
   2673 -            super(new SHA384Digest(), new ECDSASigner(), new StdDSAEncoder());
   2674 +            // BEGIN android-changed
   2675 +            super(AndroidDigestFactory.getSHA384(), new ECDSASigner(), new StdDSAEncoder());
   2676 +            // END android-changed
   2677          }
   2678      }
   2679  
   2680 @@ -153,90 +168,94 @@
   2681      {
   2682          public ecDSA512()
   2683          {
   2684 -            super(new SHA512Digest(), new ECDSASigner(), new StdDSAEncoder());
   2685 -        }
   2686 -    }
   2687 -
   2688 -    static public class ecDSARipeMD160
   2689 -        extends SignatureSpi
   2690 -    {
   2691 -        public ecDSARipeMD160()
   2692 -        {
   2693 -            super(new RIPEMD160Digest(), new ECDSASigner(), new StdDSAEncoder());
   2694 -        }
   2695 -    }
   2696 -
   2697 -    static public class ecNR
   2698 -        extends SignatureSpi
   2699 -    {
   2700 -        public ecNR()
   2701 -        {
   2702 -            super(new SHA1Digest(), new ECNRSigner(), new StdDSAEncoder());
   2703 -        }
   2704 -    }
   2705 -
   2706 -    static public class ecNR224
   2707 -        extends SignatureSpi
   2708 -    {
   2709 -        public ecNR224()
   2710 -        {
   2711 -            super(new SHA224Digest(), new ECNRSigner(), new StdDSAEncoder());
   2712 -        }
   2713 -    }
   2714 -
   2715 -    static public class ecNR256
   2716 -        extends SignatureSpi
   2717 -    {
   2718 -        public ecNR256()
   2719 -        {
   2720 -            super(new SHA256Digest(), new ECNRSigner(), new StdDSAEncoder());
   2721 -        }
   2722 -    }
   2723 -
   2724 -    static public class ecNR384
   2725 -        extends SignatureSpi
   2726 -    {
   2727 -        public ecNR384()
   2728 -        {
   2729 -            super(new SHA384Digest(), new ECNRSigner(), new StdDSAEncoder());
   2730 -        }
   2731 -    }
   2732 -
   2733 -    static public class ecNR512
   2734 -        extends SignatureSpi
   2735 -    {
   2736 -        public ecNR512()
   2737 -        {
   2738 -            super(new SHA512Digest(), new ECNRSigner(), new StdDSAEncoder());
   2739 -        }
   2740 -    }
   2741 -
   2742 -    static public class ecCVCDSA
   2743 -        extends SignatureSpi
   2744 -    {
   2745 -        public ecCVCDSA()
   2746 -        {
   2747 -            super(new SHA1Digest(), new ECDSASigner(), new CVCDSAEncoder());
   2748 -        }
   2749 -    }
   2750 -
   2751 -    static public class ecCVCDSA224
   2752 -        extends SignatureSpi
   2753 -    {
   2754 -        public ecCVCDSA224()
   2755 -        {
   2756 -            super(new SHA224Digest(), new ECDSASigner(), new CVCDSAEncoder());
   2757 -        }
   2758 -    }
   2759 -
   2760 -    static public class ecCVCDSA256
   2761 -        extends SignatureSpi
   2762 -    {
   2763 -        public ecCVCDSA256()
   2764 -        {
   2765 -            super(new SHA256Digest(), new ECDSASigner(), new CVCDSAEncoder());
   2766 -        }
   2767 -    }
   2768 +            // BEGIN android-changed
   2769 +            super(AndroidDigestFactory.getSHA512(), new ECDSASigner(), new StdDSAEncoder());
   2770 +            // END android-changed
   2771 +        }
   2772 +    }
   2773 +
   2774 +    // BEGIN android-removed
   2775 +    // static public class ecDSARipeMD160
   2776 +    //     extends SignatureSpi
   2777 +    // {
   2778 +    //     public ecDSARipeMD160()
   2779 +    //     {
   2780 +    //         super(new RIPEMD160Digest(), new ECDSASigner(), new StdDSAEncoder());
   2781 +    //     }
   2782 +    // }
   2783 +    //
   2784 +    // static public class ecNR
   2785 +    //     extends SignatureSpi
   2786 +    // {
   2787 +    //     public ecNR()
   2788 +    //     {
   2789 +    //         super(new SHA1Digest(), new ECNRSigner(), new StdDSAEncoder());
   2790 +    //     }
   2791 +    // }
   2792 +    //
   2793 +    // static public class ecNR224
   2794 +    //     extends SignatureSpi
   2795 +    // {
   2796 +    //     public ecNR224()
   2797 +    //     {
   2798 +    //         super(new SHA224Digest(), new ECNRSigner(), new StdDSAEncoder());
   2799 +    //     }
   2800 +    // }
   2801 +    //
   2802 +    // static public class ecNR256
   2803 +    //     extends SignatureSpi
   2804 +    // {
   2805 +    //     public ecNR256()
   2806 +    //     {
   2807 +    //         super(new SHA256Digest(), new ECNRSigner(), new StdDSAEncoder());
   2808 +    //     }
   2809 +    // }
   2810 +    //
   2811 +    // static public class ecNR384
   2812 +    //     extends SignatureSpi
   2813 +    // {
   2814 +    //     public ecNR384()
   2815 +    //     {
   2816 +    //         super(new SHA384Digest(), new ECNRSigner(), new StdDSAEncoder());
   2817 +    //     }
   2818 +    // }
   2819 +    //
   2820 +    // static public class ecNR512
   2821 +    //     extends SignatureSpi
   2822 +    // {
   2823 +    //     public ecNR512()
   2824 +    //     {
   2825 +    //         super(new SHA512Digest(), new ECNRSigner(), new StdDSAEncoder());
   2826 +    //     }
   2827 +    // }
   2828 +    //
   2829 +    // static public class ecCVCDSA
   2830 +    //     extends SignatureSpi
   2831 +    // {
   2832 +    //     public ecCVCDSA()
   2833 +    //     {
   2834 +    //         super(new SHA1Digest(), new ECDSASigner(), new CVCDSAEncoder());
   2835 +    //     }
   2836 +    // }
   2837 +    //
   2838 +    // static public class ecCVCDSA224
   2839 +    //     extends SignatureSpi
   2840 +    // {
   2841 +    //     public ecCVCDSA224()
   2842 +    //     {
   2843 +    //         super(new SHA224Digest(), new ECDSASigner(), new CVCDSAEncoder());
   2844 +    //     }
   2845 +    // }
   2846 +    //
   2847 +    // static public class ecCVCDSA256
   2848 +    //     extends SignatureSpi
   2849 +    // {
   2850 +    //     public ecCVCDSA256()
   2851 +    //     {
   2852 +    //         super(new SHA256Digest(), new ECDSASigner(), new CVCDSAEncoder());
   2853 +    //     }
   2854 +    // }
   2855 +    // END android-removed
   2856  
   2857      private static class StdDSAEncoder
   2858          implements DSAEncoder
   2859 @@ -330,4 +349,4 @@
   2860              return sig;
   2861          }
   2862      }
   2863 -}
   2864 \ No newline at end of file
   2865 +}
   2866 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/AlgorithmParametersSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/AlgorithmParametersSpi.java
   2867 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/AlgorithmParametersSpi.java	2012-03-22 15:11:48.000000000 +0000
   2868 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/AlgorithmParametersSpi.java	2012-09-19 21:17:12.000000000 +0000
   2869 @@ -55,11 +55,15 @@
   2870          {
   2871              AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
   2872                                                              DigestFactory.getOID(currentSpec.getDigestAlgorithm()),
   2873 -                                                            new DERNull());
   2874 +                                                            // BEGIN android-changed
   2875 +                                                            DERNull.INSTANCE);
   2876 +                                                            // END android-changed
   2877              MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)currentSpec.getMGFParameters();
   2878              AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
   2879                                                              PKCSObjectIdentifiers.id_mgf1,
   2880 -                                                            new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), new DERNull()));
   2881 +                                                            // BEGIN android-changed
   2882 +                                                            new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
   2883 +                                                            // END android-changed
   2884              PSource.PSpecified      pSource = (PSource.PSpecified)currentSpec.getPSource();
   2885              AlgorithmIdentifier pSourceAlgorithm = new AlgorithmIdentifier(
   2886                                                              PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(pSource.getValue()));
   2887 @@ -170,11 +174,15 @@
   2888              PSSParameterSpec pssSpec = currentSpec;
   2889              AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
   2890                                                  DigestFactory.getOID(pssSpec.getDigestAlgorithm()),
   2891 -                                                new DERNull());
   2892 +                                                // BEGIN android-changed
   2893 +                                                DERNull.INSTANCE);
   2894 +                                                // END android-changed
   2895              MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)pssSpec.getMGFParameters();
   2896              AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
   2897                                                  PKCSObjectIdentifiers.id_mgf1,
   2898 -                                                new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), new DERNull()));
   2899 +                                                // BEGIN android-changed
   2900 +                                                new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
   2901 +                                                // END android-changed
   2902              RSASSAPSSparams pssP = new RSASSAPSSparams(hashAlgorithm, maskGenAlgorithm, new ASN1Integer(pssSpec.getSaltLength()), new ASN1Integer(pssSpec.getTrailerField()));
   2903              
   2904              return pssP.getEncoded("DER");
   2905 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateCrtKey.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateCrtKey.java
   2906 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateCrtKey.java	2012-03-22 15:11:48.000000000 +0000
   2907 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateCrtKey.java	2012-09-19 21:17:12.000000000 +0000
   2908 @@ -127,7 +127,9 @@
   2909       */
   2910      public byte[] getEncoded()
   2911      {
   2912 -        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient()));
   2913 +        // BEGIN android-changed
   2914 +        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient()));
   2915 +        // END android-changed
   2916      }
   2917  
   2918      /**
   2919 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java
   2920 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java	2012-03-22 15:11:48.000000000 +0000
   2921 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java	2012-09-19 21:17:12.000000000 +0000
   2922 @@ -78,7 +78,9 @@
   2923  
   2924      public byte[] getEncoded()
   2925      {
   2926 -        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO));
   2927 +        // BEGIN android-changed
   2928 +        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO));
   2929 +        // END android-changed
   2930      }
   2931  
   2932      public boolean equals(Object o)
   2933 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPublicKey.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPublicKey.java
   2934 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPublicKey.java	2012-03-22 15:11:48.000000000 +0000
   2935 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPublicKey.java	2012-09-19 21:17:12.000000000 +0000
   2936 @@ -89,7 +89,9 @@
   2937  
   2938      public byte[] getEncoded()
   2939      {
   2940 -        return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new org.bouncycastle.asn1.pkcs.RSAPublicKey(getModulus(), getPublicExponent()));
   2941 +        // BEGIN android-changed
   2942 +        return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.bouncycastle.asn1.pkcs.RSAPublicKey(getModulus(), getPublicExponent()));
   2943 +        // END android-changed
   2944      }
   2945  
   2946      public int hashCode()
   2947 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/CipherSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/CipherSpi.java
   2948 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/CipherSpi.java	2012-03-22 15:11:48.000000000 +0000
   2949 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/CipherSpi.java	2012-09-19 21:17:12.000000000 +0000
   2950 @@ -26,7 +26,9 @@
   2951  import org.bouncycastle.crypto.CipherParameters;
   2952  import org.bouncycastle.crypto.Digest;
   2953  import org.bouncycastle.crypto.InvalidCipherTextException;
   2954 -import org.bouncycastle.crypto.encodings.ISO9796d1Encoding;
   2955 +// BEGIN android-removed
   2956 +// import org.bouncycastle.crypto.encodings.ISO9796d1Encoding;
   2957 +// END android-removed
   2958  import org.bouncycastle.crypto.encodings.OAEPEncoding;
   2959  import org.bouncycastle.crypto.encodings.PKCS1Encoding;
   2960  import org.bouncycastle.crypto.engines.RSABlindedEngine;
   2961 @@ -197,10 +199,12 @@
   2962          {
   2963              cipher = new PKCS1Encoding(new RSABlindedEngine());
   2964          }
   2965 -        else if (pad.equals("ISO9796-1PADDING"))
   2966 -        {
   2967 -            cipher = new ISO9796d1Encoding(new RSABlindedEngine());
   2968 -        }
   2969 +        // BEGIN android-removed
   2970 +        // else if (pad.equals("ISO9796-1PADDING"))
   2971 +        // {
   2972 +        //     cipher = new ISO9796d1Encoding(new RSABlindedEngine());
   2973 +        // }
   2974 +        // END android-removed
   2975          else if (pad.equals("OAEPWITHMD5ANDMGF1PADDING"))
   2976          {
   2977              initFromSpec(new OAEPParameterSpec("MD5", "MGF1", new MGF1ParameterSpec("MD5"), PSource.PSpecified.DEFAULT));
   2978 @@ -213,10 +217,12 @@
   2979          {
   2980              initFromSpec(OAEPParameterSpec.DEFAULT);
   2981          }
   2982 -        else if (pad.equals("OAEPWITHSHA224ANDMGF1PADDING") || pad.equals("OAEPWITHSHA-224ANDMGF1PADDING"))
   2983 -        {
   2984 -            initFromSpec(new OAEPParameterSpec("SHA-224", "MGF1", new MGF1ParameterSpec("SHA-224"), PSource.PSpecified.DEFAULT));
   2985 -        }
   2986 +        // BEGIN android-removed
   2987 +        // else if (pad.equals("OAEPWITHSHA224ANDMGF1PADDING") || pad.equals("OAEPWITHSHA-224ANDMGF1PADDING"))
   2988 +        // {
   2989 +        //     initFromSpec(new OAEPParameterSpec("SHA-224", "MGF1", new MGF1ParameterSpec("SHA-224"), PSource.PSpecified.DEFAULT));
   2990 +        // }
   2991 +        // END android-removed
   2992          else if (pad.equals("OAEPWITHSHA256ANDMGF1PADDING") || pad.equals("OAEPWITHSHA-256ANDMGF1PADDING"))
   2993          {
   2994              initFromSpec(new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, PSource.PSpecified.DEFAULT));
   2995 @@ -534,48 +540,50 @@
   2996          }
   2997      }
   2998  
   2999 -    static public class PKCS1v1_5Padding
   3000 -        extends CipherSpi
   3001 -    {
   3002 -        public PKCS1v1_5Padding()
   3003 -        {
   3004 -            super(new PKCS1Encoding(new RSABlindedEngine()));
   3005 -        }
   3006 -    }
   3007 -
   3008 -    static public class PKCS1v1_5Padding_PrivateOnly
   3009 -        extends CipherSpi
   3010 -    {
   3011 -        public PKCS1v1_5Padding_PrivateOnly()
   3012 -        {
   3013 -            super(false, true, new PKCS1Encoding(new RSABlindedEngine()));
   3014 -        }
   3015 -    }
   3016 -
   3017 -    static public class PKCS1v1_5Padding_PublicOnly
   3018 -        extends CipherSpi
   3019 -    {
   3020 -        public PKCS1v1_5Padding_PublicOnly()
   3021 -        {
   3022 -            super(true, false, new PKCS1Encoding(new RSABlindedEngine()));
   3023 -        }
   3024 -    }
   3025 -
   3026 -    static public class OAEPPadding
   3027 -        extends CipherSpi
   3028 -    {
   3029 -        public OAEPPadding()
   3030 -        {
   3031 -            super(OAEPParameterSpec.DEFAULT);
   3032 -        }
   3033 -    }
   3034 -    
   3035 -    static public class ISO9796d1Padding
   3036 -        extends CipherSpi
   3037 -    {
   3038 -        public ISO9796d1Padding()
   3039 -        {
   3040 -            super(new ISO9796d1Encoding(new RSABlindedEngine()));
   3041 -        }
   3042 -    }
   3043 +    // BEGIN android-removed
   3044 +    // static public class PKCS1v1_5Padding
   3045 +    //     extends CipherSpi
   3046 +    // {
   3047 +    //     public PKCS1v1_5Padding()
   3048 +    //     {
   3049 +    //         super(new PKCS1Encoding(new RSABlindedEngine()));
   3050 +    //     }
   3051 +    // }
   3052 +    //
   3053 +    // static public class PKCS1v1_5Padding_PrivateOnly
   3054 +    //     extends CipherSpi
   3055 +    // {
   3056 +    //     public PKCS1v1_5Padding_PrivateOnly()
   3057 +    //     {
   3058 +    //         super(false, true, new PKCS1Encoding(new RSABlindedEngine()));
   3059 +    //     }
   3060 +    // }
   3061 +    //
   3062 +    // static public class PKCS1v1_5Padding_PublicOnly
   3063 +    //     extends CipherSpi
   3064 +    // {
   3065 +    //     public PKCS1v1_5Padding_PublicOnly()
   3066 +    //     {
   3067 +    //         super(true, false, new PKCS1Encoding(new RSABlindedEngine()));
   3068 +    //     }
   3069 +    // }
   3070 +    //
   3071 +    // static public class OAEPPadding
   3072 +    //     extends CipherSpi
   3073 +    // {
   3074 +    //     public OAEPPadding()
   3075 +    //     {
   3076 +    //         super(OAEPParameterSpec.DEFAULT);
   3077 +    //     }
   3078 +    // }
   3079 +    //
   3080 +    // static public class ISO9796d1Padding
   3081 +    //     extends CipherSpi
   3082 +    // {
   3083 +    //     public ISO9796d1Padding()
   3084 +    //     {
   3085 +    //         super(new ISO9796d1Encoding(new RSABlindedEngine()));
   3086 +    //     }
   3087 +    // }
   3088 +    // END android-removed
   3089  }
   3090 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/DigestSignatureSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/DigestSignatureSpi.java
   3091 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/rsa/DigestSignatureSpi.java	2012-03-22 15:11:48.000000000 +0000
   3092 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/rsa/DigestSignatureSpi.java	2012-09-19 21:17:12.000000000 +0000
   3093 @@ -17,24 +17,31 @@
   3094  import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
   3095  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   3096  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   3097 -import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   3098 +// BEGIN android-removed
   3099 +// import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   3100 +// END android-removed
   3101  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   3102  import org.bouncycastle.asn1.x509.DigestInfo;
   3103  import org.bouncycastle.crypto.AsymmetricBlockCipher;
   3104  import org.bouncycastle.crypto.CipherParameters;
   3105  import org.bouncycastle.crypto.Digest;
   3106 -import org.bouncycastle.crypto.digests.MD2Digest;
   3107 -import org.bouncycastle.crypto.digests.MD4Digest;
   3108 -import org.bouncycastle.crypto.digests.MD5Digest;
   3109 -import org.bouncycastle.crypto.digests.NullDigest;
   3110 -import org.bouncycastle.crypto.digests.RIPEMD128Digest;
   3111 -import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   3112 -import org.bouncycastle.crypto.digests.RIPEMD256Digest;
   3113 -import org.bouncycastle.crypto.digests.SHA1Digest;
   3114 -import org.bouncycastle.crypto.digests.SHA224Digest;
   3115 -import org.bouncycastle.crypto.digests.SHA256Digest;
   3116 -import org.bouncycastle.crypto.digests.SHA384Digest;
   3117 -import org.bouncycastle.crypto.digests.SHA512Digest;
   3118 +// BEGIN android-removed
   3119 +// import org.bouncycastle.crypto.digests.MD2Digest;
   3120 +// import org.bouncycastle.crypto.digests.MD4Digest;
   3121 +// import org.bouncycastle.crypto.digests.MD5Digest;
   3122 +// import org.bouncycastle.crypto.digests.NullDigest;
   3123 +// import org.bouncycastle.crypto.digests.RIPEMD128Digest;
   3124 +// import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   3125 +// import org.bouncycastle.crypto.digests.RIPEMD256Digest;
   3126 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   3127 +// import org.bouncycastle.crypto.digests.SHA224Digest;
   3128 +// import org.bouncycastle.crypto.digests.SHA256Digest;
   3129 +// import org.bouncycastle.crypto.digests.SHA384Digest;
   3130 +// import org.bouncycastle.crypto.digests.SHA512Digest;
   3131 +// END android-removed
   3132 +// BEGIN android-added
   3133 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   3134 +// END android-added
   3135  import org.bouncycastle.crypto.encodings.PKCS1Encoding;
   3136  import org.bouncycastle.crypto.engines.RSABlindedEngine;
   3137  
   3138 @@ -261,25 +268,31 @@
   3139      {
   3140          public SHA1()
   3141          {
   3142 -            super(OIWObjectIdentifiers.idSHA1, new SHA1Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3143 +            // BEGIN android-changed
   3144 +            super(OIWObjectIdentifiers.idSHA1, AndroidDigestFactory.getSHA1(), new PKCS1Encoding(new RSABlindedEngine()));
   3145 +            // END android-changed
   3146          }
   3147      }
   3148  
   3149 -    static public class SHA224
   3150 -        extends DigestSignatureSpi
   3151 -    {
   3152 -        public SHA224()
   3153 -        {
   3154 -            super(NISTObjectIdentifiers.id_sha224, new SHA224Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3155 -        }
   3156 -    }
   3157 +    // BEGIN android-removed
   3158 +    // static public class SHA224
   3159 +    //     extends DigestSignatureSpi
   3160 +    // {
   3161 +    //     public SHA224()
   3162 +    //     {
   3163 +    //         super(NISTObjectIdentifiers.id_sha224, new SHA224Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3164 +    //     }
   3165 +    // }
   3166 +    // END android-removed
   3167  
   3168      static public class SHA256
   3169          extends DigestSignatureSpi
   3170      {
   3171          public SHA256()
   3172          {
   3173 -            super(NISTObjectIdentifiers.id_sha256, new SHA256Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3174 +            // BEGIN android-changed
   3175 +            super(NISTObjectIdentifiers.id_sha256, AndroidDigestFactory.getSHA256(), new PKCS1Encoding(new RSABlindedEngine()));
   3176 +            // END android-changed
   3177          }
   3178      }
   3179  
   3180 @@ -288,7 +301,9 @@
   3181      {
   3182          public SHA384()
   3183          {
   3184 -            super(NISTObjectIdentifiers.id_sha384, new SHA384Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3185 +            // BEGIN android-changed
   3186 +            super(NISTObjectIdentifiers.id_sha384, AndroidDigestFactory.getSHA384(), new PKCS1Encoding(new RSABlindedEngine()));
   3187 +            // END android-changed
   3188          }
   3189      }
   3190  
   3191 @@ -297,70 +312,78 @@
   3192      {
   3193          public SHA512()
   3194          {
   3195 -            super(NISTObjectIdentifiers.id_sha512, new SHA512Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3196 -        }
   3197 -    }
   3198 -
   3199 -    static public class MD2
   3200 -        extends DigestSignatureSpi
   3201 -    {
   3202 -        public MD2()
   3203 -        {
   3204 -            super(PKCSObjectIdentifiers.md2, new MD2Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3205 +            // BEGIN android-changed
   3206 +            super(NISTObjectIdentifiers.id_sha512, AndroidDigestFactory.getSHA512(), new PKCS1Encoding(new RSABlindedEngine()));
   3207 +            // END android-changed
   3208          }
   3209      }
   3210  
   3211 -    static public class MD4
   3212 -        extends DigestSignatureSpi
   3213 -    {
   3214 -        public MD4()
   3215 -        {
   3216 -            super(PKCSObjectIdentifiers.md4, new MD4Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3217 -        }
   3218 -    }
   3219 +    // BEGIN android-removed
   3220 +    // static public class MD2
   3221 +    //     extends DigestSignatureSpi
   3222 +    // {
   3223 +    //     public MD2()
   3224 +    //     {
   3225 +    //         super(PKCSObjectIdentifiers.md2, new MD2Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3226 +    //     }
   3227 +    // }
   3228 +    //
   3229 +    // static public class MD4
   3230 +    //     extends DigestSignatureSpi
   3231 +    // {
   3232 +    //     public MD4()
   3233 +    //     {
   3234 +    //         super(PKCSObjectIdentifiers.md4, new MD4Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3235 +    //     }
   3236 +    // }
   3237 +    // END android-removed
   3238  
   3239      static public class MD5
   3240          extends DigestSignatureSpi
   3241      {
   3242          public MD5()
   3243          {
   3244 -            super(PKCSObjectIdentifiers.md5, new MD5Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3245 +            // BEGIN android-changed
   3246 +            super(PKCSObjectIdentifiers.md5, AndroidDigestFactory.getMD5(), new PKCS1Encoding(new RSABlindedEngine()));
   3247 +            // END android-changed
   3248          }
   3249      }
   3250  
   3251 -    static public class RIPEMD160
   3252 -        extends DigestSignatureSpi
   3253 -    {
   3254 -        public RIPEMD160()
   3255 -        {
   3256 -            super(TeleTrusTObjectIdentifiers.ripemd160, new RIPEMD160Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3257 -        }
   3258 -    }
   3259 -
   3260 -    static public class RIPEMD128
   3261 -        extends DigestSignatureSpi
   3262 -    {
   3263 -        public RIPEMD128()
   3264 -        {
   3265 -            super(TeleTrusTObjectIdentifiers.ripemd128, new RIPEMD128Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3266 -        }
   3267 -    }
   3268 -
   3269 -    static public class RIPEMD256
   3270 -        extends DigestSignatureSpi
   3271 -    {
   3272 -        public RIPEMD256()
   3273 -        {
   3274 -            super(TeleTrusTObjectIdentifiers.ripemd256, new RIPEMD256Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3275 -        }
   3276 -    }
   3277 -
   3278 -    static public class noneRSA
   3279 -        extends DigestSignatureSpi
   3280 -    {
   3281 -        public noneRSA()
   3282 -        {
   3283 -            super(new NullDigest(), new PKCS1Encoding(new RSABlindedEngine()));
   3284 -        }
   3285 -    }
   3286 +    // BEGIN android-removed
   3287 +    // static public class RIPEMD160
   3288 +    //     extends DigestSignatureSpi
   3289 +    // {
   3290 +    //     public RIPEMD160()
   3291 +    //     {
   3292 +    //         super(TeleTrusTObjectIdentifiers.ripemd160, new RIPEMD160Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3293 +    //     }
   3294 +    // }
   3295 +    //
   3296 +    // static public class RIPEMD128
   3297 +    //     extends DigestSignatureSpi
   3298 +    // {
   3299 +    //     public RIPEMD128()
   3300 +    //     {
   3301 +    //         super(TeleTrusTObjectIdentifiers.ripemd128, new RIPEMD128Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3302 +    //     }
   3303 +    // }
   3304 +    //
   3305 +    // static public class RIPEMD256
   3306 +    //     extends DigestSignatureSpi
   3307 +    // {
   3308 +    //     public RIPEMD256()
   3309 +    //     {
   3310 +    //         super(TeleTrusTObjectIdentifiers.ripemd256, new RIPEMD256Digest(), new PKCS1Encoding(new RSABlindedEngine()));
   3311 +    //     }
   3312 +    // }
   3313 +    //
   3314 +    // static public class noneRSA
   3315 +    //     extends DigestSignatureSpi
   3316 +    // {
   3317 +    //     public noneRSA()
   3318 +    //     {
   3319 +    //         super(new NullDigest(), new PKCS1Encoding(new RSABlindedEngine()));
   3320 +    //     }
   3321 +    // }
   3322 +    // END android-removed
   3323  }
   3324 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/util/BaseCipherSpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/util/BaseCipherSpi.java
   3325 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/util/BaseCipherSpi.java	2012-03-22 15:11:48.000000000 +0000
   3326 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/util/BaseCipherSpi.java	2012-09-19 21:17:12.000000000 +0000
   3327 @@ -18,8 +18,10 @@
   3328  import javax.crypto.NoSuchPaddingException;
   3329  import javax.crypto.spec.IvParameterSpec;
   3330  import javax.crypto.spec.PBEParameterSpec;
   3331 -import javax.crypto.spec.RC2ParameterSpec;
   3332 -import javax.crypto.spec.RC5ParameterSpec;
   3333 +// BEGIN android-removed
   3334 +// import javax.crypto.spec.RC2ParameterSpec;
   3335 +// import javax.crypto.spec.RC5ParameterSpec;
   3336 +// END android-removed
   3337  import javax.crypto.spec.SecretKeySpec;
   3338  
   3339  import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
   3340 @@ -37,8 +39,10 @@
   3341                                      {
   3342                                          IvParameterSpec.class,
   3343                                          PBEParameterSpec.class,
   3344 -                                        RC2ParameterSpec.class,
   3345 -                                        RC5ParameterSpec.class
   3346 +                                        // BEGIN android-removed
   3347 +                                        // RC2ParameterSpec.class,
   3348 +                                        // RC5ParameterSpec.class
   3349 +                                        // END android-removed
   3350                                      };
   3351  
   3352  
   3353 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/util/BaseKeyFactorySpi.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/util/BaseKeyFactorySpi.java
   3354 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/util/BaseKeyFactorySpi.java	2012-03-22 15:11:48.000000000 +0000
   3355 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/util/BaseKeyFactorySpi.java	2012-09-19 21:17:12.000000000 +0000
   3356 @@ -27,7 +27,9 @@
   3357              {
   3358                  return generatePrivate(PrivateKeyInfo.getInstance(((PKCS8EncodedKeySpec)keySpec).getEncoded()));
   3359              }
   3360 -            catch (IOException e)
   3361 +            // BEGIN android-changed
   3362 +            catch (Exception e)
   3363 +            // END android-changed
   3364              {
   3365                  throw new InvalidKeySpecException("encoded key spec not recognised");
   3366              }
   3367 @@ -48,7 +50,9 @@
   3368              {
   3369                  return generatePublic(SubjectPublicKeyInfo.getInstance(((X509EncodedKeySpec)keySpec).getEncoded()));
   3370              }
   3371 -            catch (IOException e)
   3372 +            // BEGIN android-changed
   3373 +            catch (Exception e)
   3374 +            // END android-changed
   3375              {
   3376                  throw new InvalidKeySpecException("encoded key spec not recognised");
   3377              }
   3378 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/x509/PKIXCertPath.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/x509/PKIXCertPath.java
   3379 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/asymmetric/x509/PKIXCertPath.java	2012-03-22 15:11:48.000000000 +0000
   3380 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/asymmetric/x509/PKIXCertPath.java	2012-09-19 21:17:12.000000000 +0000
   3381 @@ -36,7 +36,9 @@
   3382  import org.bouncycastle.asn1.pkcs.SignedData;
   3383  import org.bouncycastle.jce.provider.BouncyCastleProvider;
   3384  import org.bouncycastle.util.io.pem.PemObject;
   3385 -import org.bouncycastle.util.io.pem.PemWriter;
   3386 +// BEGIN android-removed
   3387 +// import org.bouncycastle.util.io.pem.PemWriter;
   3388 +// END android-removed
   3389  
   3390  /**
   3391   * CertPath implementation for X.509 certificates.
   3392 @@ -298,27 +300,29 @@
   3393              return toDEREncoded(new ContentInfo(
   3394                      PKCSObjectIdentifiers.signedData, sd));
   3395          }
   3396 -        else if (encoding.equalsIgnoreCase("PEM"))
   3397 -        {
   3398 -            ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   3399 -            PemWriter pWrt = new PemWriter(new OutputStreamWriter(bOut));
   3400 -
   3401 -            try
   3402 -            {
   3403 -                for (int i = 0; i != certificates.size(); i++)
   3404 -                {
   3405 -                    pWrt.writeObject(new PemObject("CERTIFICATE", ((X509Certificate)certificates.get(i)).getEncoded()));
   3406 -                }
   3407 -            
   3408 -                pWrt.close();
   3409 -            }
   3410 -            catch (Exception e)
   3411 -            {
   3412 -                throw new CertificateEncodingException("can't encode certificate for PEM encoded path");
   3413 -            }
   3414 -
   3415 -            return bOut.toByteArray();
   3416 -        }
   3417 +        // BEGIN android-removed
   3418 +        // else if (encoding.equalsIgnoreCase("PEM"))
   3419 +        // {
   3420 +        //     ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   3421 +        //     PemWriter pWrt = new PemWriter(new OutputStreamWriter(bOut));
   3422 +        //
   3423 +        //     try
   3424 +        //     {
   3425 +        //         for (int i = 0; i != certificates.size(); i++)
   3426 +        //         {
   3427 +        //             pWrt.writeObject(new PemObject("CERTIFICATE", ((X509Certificate)certificates.get(i)).getEncoded()));
   3428 +        //         }
   3429 +        //
   3430 +        //         pWrt.close();
   3431 +        //     }
   3432 +        //     catch (Exception e)
   3433 +        //     {
   3434 +        //         throw new CertificateEncodingException("can't encode certificate for PEM encoded path");
   3435 +        //     }
   3436 +        //
   3437 +        //     return bOut.toByteArray();
   3438 +        // }
   3439 +        // END android-removed
   3440          else
   3441          {
   3442              throw new CertificateEncodingException("unsupported encoding: " + encoding);
   3443 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/AES.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/AES.java
   3444 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/AES.java	2012-03-22 15:11:48.000000000 +0000
   3445 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/AES.java	2012-09-19 21:17:12.000000000 +0000
   3446 @@ -1,31 +1,43 @@
   3447  package org.bouncycastle.jcajce.provider.symmetric;
   3448  
   3449 -import java.security.AlgorithmParameters;
   3450 -import java.security.InvalidAlgorithmParameterException;
   3451 +// BEGIN android-removed
   3452 +// import java.security.AlgorithmParameters;
   3453 +// import java.security.InvalidAlgorithmParameterException;
   3454 +// END android-removed
   3455  import java.security.SecureRandom;
   3456 -import java.security.spec.AlgorithmParameterSpec;
   3457 -
   3458 -import javax.crypto.spec.IvParameterSpec;
   3459 +// BEGIN android-removed
   3460 +// import java.security.spec.AlgorithmParameterSpec;
   3461 +//
   3462 +// import javax.crypto.spec.IvParameterSpec;
   3463 +// END android-removed
   3464  
   3465  import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
   3466  import org.bouncycastle.crypto.BufferedBlockCipher;
   3467  import org.bouncycastle.crypto.CipherKeyGenerator;
   3468  import org.bouncycastle.crypto.engines.AESFastEngine;
   3469  import org.bouncycastle.crypto.engines.AESWrapEngine;
   3470 -import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
   3471 -import org.bouncycastle.crypto.macs.CMac;
   3472 +// BEGIN android-removed
   3473 +// import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
   3474 +// import org.bouncycastle.crypto.macs.CMac;
   3475 +// END android-removed
   3476  import org.bouncycastle.crypto.modes.CBCBlockCipher;
   3477  import org.bouncycastle.crypto.modes.CFBBlockCipher;
   3478  import org.bouncycastle.crypto.modes.OFBBlockCipher;
   3479  import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
   3480 -import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
   3481 +// BEGIN android-removed
   3482 +// import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
   3483 +// END android-removed
   3484  import org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher;
   3485  import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
   3486 -import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
   3487 +// BEGIN android-removed
   3488 +// import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
   3489 +// END android-removed
   3490  import org.bouncycastle.jcajce.provider.symmetric.util.BaseWrapCipher;
   3491  import org.bouncycastle.jcajce.provider.symmetric.util.IvAlgorithmParameters;
   3492  import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
   3493 -import org.bouncycastle.jce.provider.BouncyCastleProvider;
   3494 +// BEGIN android-removed
   3495 +// import org.bouncycastle.jce.provider.BouncyCastleProvider;
   3496 +// END android-removed
   3497  
   3498  public final class AES
   3499  {
   3500 @@ -69,15 +81,17 @@
   3501          }
   3502      }
   3503  
   3504 -    public static class AESCMAC
   3505 -        extends BaseMac
   3506 -    {
   3507 -        public AESCMAC()
   3508 -        {
   3509 -            super(new CMac(new AESFastEngine()));
   3510 -        }
   3511 -    }
   3512 -
   3513 +    // BEGIN android-removed
   3514 +    // public static class AESCMAC
   3515 +    //     extends BaseMac
   3516 +    // {
   3517 +    //     public AESCMAC()
   3518 +    //     {
   3519 +    //         super(new CMac(new AESFastEngine()));
   3520 +    //     }
   3521 +    // }
   3522 +    // END android-removed
   3523 +    
   3524      static public class Wrap
   3525          extends BaseWrapCipher
   3526      {
   3527 @@ -86,15 +100,17 @@
   3528              super(new AESWrapEngine());
   3529          }
   3530      }
   3531 -
   3532 -    public static class RFC3211Wrap
   3533 -        extends BaseWrapCipher
   3534 -    {
   3535 -        public RFC3211Wrap()
   3536 -        {
   3537 -            super(new RFC3211WrapEngine(new AESFastEngine()), 16);
   3538 -        }
   3539 -    }
   3540 +    
   3541 +    // BEGIN android-removed
   3542 +    // public static class RFC3211Wrap
   3543 +    //     extends BaseWrapCipher
   3544 +    // {
   3545 +    //     public RFC3211Wrap()
   3546 +    //     {
   3547 +    //         super(new RFC3211WrapEngine(new AESFastEngine()), 16);
   3548 +    //     }
   3549 +    // }
   3550 +    // END android-removed
   3551  
   3552      public static class KeyGen
   3553          extends BaseKeyGenerator
   3554 @@ -110,70 +126,72 @@
   3555          }
   3556      }
   3557  
   3558 -    public static class KeyGen128
   3559 -        extends KeyGen
   3560 -    {
   3561 -        public KeyGen128()
   3562 -        {
   3563 -            super(128);
   3564 -        }
   3565 -    }
   3566 -
   3567 -    public static class KeyGen192
   3568 -        extends KeyGen
   3569 -    {
   3570 -        public KeyGen192()
   3571 -        {
   3572 -            super(192);
   3573 -        }
   3574 -    }
   3575 -
   3576 -    public static class KeyGen256
   3577 -        extends KeyGen
   3578 -    {
   3579 -        public KeyGen256()
   3580 -        {
   3581 -            super(256);
   3582 -        }
   3583 -    }
   3584 -
   3585 -    public static class AlgParamGen
   3586 -        extends BaseAlgorithmParameterGenerator
   3587 -    {
   3588 -        protected void engineInit(
   3589 -            AlgorithmParameterSpec genParamSpec,
   3590 -            SecureRandom random)
   3591 -            throws InvalidAlgorithmParameterException
   3592 -        {
   3593 -            throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for AES parameter generation.");
   3594 -        }
   3595 -
   3596 -        protected AlgorithmParameters engineGenerateParameters()
   3597 -        {
   3598 -            byte[]  iv = new byte[16];
   3599 -
   3600 -            if (random == null)
   3601 -            {
   3602 -                random = new SecureRandom();
   3603 -            }
   3604 -
   3605 -            random.nextBytes(iv);
   3606 -
   3607 -            AlgorithmParameters params;
   3608 -
   3609 -            try
   3610 -            {
   3611 -                params = AlgorithmParameters.getInstance("AES", BouncyCastleProvider.PROVIDER_NAME);
   3612 -                params.init(new IvParameterSpec(iv));
   3613 -            }
   3614 -            catch (Exception e)
   3615 -            {
   3616 -                throw new RuntimeException(e.getMessage());
   3617 -            }
   3618 -
   3619 -            return params;
   3620 -        }
   3621 -    }
   3622 +    // BEGIN android-removed
   3623 +    // public static class KeyGen128
   3624 +    //     extends KeyGen
   3625 +    // {
   3626 +    //     public KeyGen128()
   3627 +    //     {
   3628 +    //         super(128);
   3629 +    //     }
   3630 +    // }
   3631 +    //
   3632 +    // public static class KeyGen192
   3633 +    //     extends KeyGen
   3634 +    // {
   3635 +    //     public KeyGen192()
   3636 +    //     {
   3637 +    //         super(192);
   3638 +    //     }
   3639 +    // }
   3640 +    //
   3641 +    // public static class KeyGen256
   3642 +    //     extends KeyGen
   3643 +    // {
   3644 +    //     public KeyGen256()
   3645 +    //     {
   3646 +    //         super(256);
   3647 +    //     }
   3648 +    // }
   3649 +    //
   3650 +    // public static class AlgParamGen
   3651 +    //     extends BaseAlgorithmParameterGenerator
   3652 +    // {
   3653 +    //     protected void engineInit(
   3654 +    //         AlgorithmParameterSpec genParamSpec,
   3655 +    //         SecureRandom random)
   3656 +    //         throws InvalidAlgorithmParameterException
   3657 +    //     {
   3658 +    //         throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for AES parameter generation.");
   3659 +    //     }
   3660 +    //
   3661 +    //     protected AlgorithmParameters engineGenerateParameters()
   3662 +    //     {
   3663 +    //         byte[]  iv = new byte[16];
   3664 +    //
   3665 +    //         if (random == null)
   3666 +    //         {
   3667 +    //             random = new SecureRandom();
   3668 +    //         }
   3669 +    //
   3670 +    //         random.nextBytes(iv);
   3671 +    //
   3672 +    //         AlgorithmParameters params;
   3673 +    //
   3674 +    //         try
   3675 +    //         {
   3676 +    //             params = AlgorithmParameters.getInstance("AES", BouncyCastleProvider.PROVIDER_NAME);
   3677 +    //             params.init(new IvParameterSpec(iv));
   3678 +    //         }
   3679 +    //         catch (Exception e)
   3680 +    //         {
   3681 +    //             throw new RuntimeException(e.getMessage());
   3682 +    //         }
   3683 +    //
   3684 +    //         return params;
   3685 +    //     }
   3686 +    // }
   3687 +    // END android-removed
   3688  
   3689      public static class AlgParams
   3690          extends IvAlgorithmParameters
   3691 @@ -212,58 +230,66 @@
   3692              provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes192_CBC, "AES");
   3693              provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes256_CBC, "AES");
   3694  
   3695 -            provider.addAlgorithm("AlgorithmParameterGenerator.AES", PREFIX + "$AlgParamGen");
   3696 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES128, "AES");
   3697 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES192, "AES");
   3698 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES256, "AES");
   3699 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes128_CBC, "AES");
   3700 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes192_CBC, "AES");
   3701 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes256_CBC, "AES");
   3702 +            // BEGIN android-removed
   3703 +            // provider.addAlgorithm("AlgorithmParameterGenerator.AES", PREFIX + "$AlgParamGen");
   3704 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES128, "AES");
   3705 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES192, "AES");
   3706 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES256, "AES");
   3707 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes128_CBC, "AES");
   3708 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes192_CBC, "AES");
   3709 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes256_CBC, "AES");
   3710 +            // END android-removed
   3711  
   3712              provider.addAlgorithm("Cipher.AES", PREFIX + "$ECB");
   3713              provider.addAlgorithm("Alg.Alias.Cipher." + wrongAES128, "AES");
   3714              provider.addAlgorithm("Alg.Alias.Cipher." + wrongAES192, "AES");
   3715              provider.addAlgorithm("Alg.Alias.Cipher." + wrongAES256, "AES");
   3716 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_ECB, PREFIX + "$ECB");
   3717 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_ECB, PREFIX + "$ECB");
   3718 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_ECB, PREFIX + "$ECB");
   3719 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_CBC, PREFIX + "$CBC");
   3720 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_CBC, PREFIX + "$CBC");
   3721 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_CBC, PREFIX + "$CBC");
   3722 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_OFB, PREFIX + "$OFB");
   3723 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_OFB, PREFIX + "$OFB");
   3724 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_OFB, PREFIX + "$OFB");
   3725 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_CFB, PREFIX + "$CFB");
   3726 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_CFB, PREFIX + "$CFB");
   3727 -            provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_CFB, PREFIX + "$CFB");
   3728 +            // BEGIN android-removed
   3729 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_ECB, PREFIX + "$ECB");
   3730 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_ECB, PREFIX + "$ECB");
   3731 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_ECB, PREFIX + "$ECB");
   3732 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_CBC, PREFIX + "$CBC");
   3733 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_CBC, PREFIX + "$CBC");
   3734 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_CBC, PREFIX + "$CBC");
   3735 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_OFB, PREFIX + "$OFB");
   3736 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_OFB, PREFIX + "$OFB");
   3737 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_OFB, PREFIX + "$OFB");
   3738 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes128_CFB, PREFIX + "$CFB");
   3739 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes192_CFB, PREFIX + "$CFB");
   3740 +            // provider.addAlgorithm("Cipher." + NISTObjectIdentifiers.id_aes256_CFB, PREFIX + "$CFB");
   3741 +            // END android-removed
   3742              provider.addAlgorithm("Cipher.AESWRAP", PREFIX + "$Wrap");
   3743              provider.addAlgorithm("Alg.Alias.Cipher." + NISTObjectIdentifiers.id_aes128_wrap, "AESWRAP");
   3744              provider.addAlgorithm("Alg.Alias.Cipher." + NISTObjectIdentifiers.id_aes192_wrap, "AESWRAP");
   3745              provider.addAlgorithm("Alg.Alias.Cipher." + NISTObjectIdentifiers.id_aes256_wrap, "AESWRAP");
   3746 -            provider.addAlgorithm("Cipher.AESRFC3211WRAP", PREFIX + "$RFC3211Wrap");
   3747 +            // BEGIN android-removed
   3748 +            // provider.addAlgorithm("Cipher.AESRFC3211WRAP", PREFIX + "$RFC3211Wrap");
   3749 +            // END android-removed
   3750  
   3751              provider.addAlgorithm("KeyGenerator.AES", PREFIX + "$KeyGen");
   3752 -            provider.addAlgorithm("KeyGenerator." + wrongAES128, PREFIX + "$KeyGen128");
   3753 -            provider.addAlgorithm("KeyGenerator." + wrongAES192, PREFIX + "$KeyGen192");
   3754 -            provider.addAlgorithm("KeyGenerator." + wrongAES256, PREFIX + "$KeyGen256");
   3755 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_ECB, PREFIX + "$KeyGen128");
   3756 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_CBC, PREFIX + "$KeyGen128");
   3757 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_OFB, PREFIX + "$KeyGen128");
   3758 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_CFB, PREFIX + "$KeyGen128");
   3759 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_ECB, PREFIX + "$KeyGen192");
   3760 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_CBC, PREFIX + "$KeyGen192");
   3761 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_OFB, PREFIX + "$KeyGen192");
   3762 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_CFB, PREFIX + "$KeyGen192");
   3763 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_ECB, PREFIX + "$KeyGen256");
   3764 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_CBC, PREFIX + "$KeyGen256");
   3765 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_OFB, PREFIX + "$KeyGen256");
   3766 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_CFB, PREFIX + "$KeyGen256");
   3767 -            provider.addAlgorithm("KeyGenerator.AESWRAP", PREFIX + "$KeyGen");
   3768 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_wrap, PREFIX + "$KeyGen128");
   3769 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_wrap, PREFIX + "$KeyGen192");
   3770 -            provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_wrap, PREFIX + "$KeyGen256");
   3771 -
   3772 -            provider.addAlgorithm("Mac.AESCMAC", PREFIX + "$AESCMAC");
   3773 +            // BEGIN android-removed
   3774 +            // provider.addAlgorithm("KeyGenerator." + wrongAES128, PREFIX + "$KeyGen128");
   3775 +            // provider.addAlgorithm("KeyGenerator." + wrongAES192, PREFIX + "$KeyGen192");
   3776 +            // provider.addAlgorithm("KeyGenerator." + wrongAES256, PREFIX + "$KeyGen256");
   3777 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_ECB, PREFIX + "$KeyGen128");
   3778 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_CBC, PREFIX + "$KeyGen128");
   3779 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_OFB, PREFIX + "$KeyGen128");
   3780 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_CFB, PREFIX + "$KeyGen128");
   3781 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_ECB, PREFIX + "$KeyGen192");
   3782 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_CBC, PREFIX + "$KeyGen192");
   3783 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_OFB, PREFIX + "$KeyGen192");
   3784 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_CFB, PREFIX + "$KeyGen192");
   3785 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_ECB, PREFIX + "$KeyGen256");
   3786 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_CBC, PREFIX + "$KeyGen256");
   3787 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_OFB, PREFIX + "$KeyGen256");
   3788 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_CFB, PREFIX + "$KeyGen256");
   3789 +            // provider.addAlgorithm("KeyGenerator.AESWRAP", PREFIX + "$KeyGen");
   3790 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes128_wrap, PREFIX + "$KeyGen128");
   3791 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes192_wrap, PREFIX + "$KeyGen192");
   3792 +            // provider.addAlgorithm("KeyGenerator." + NISTObjectIdentifiers.id_aes256_wrap, PREFIX + "$KeyGen256");
   3793 +            //
   3794 +            // provider.addAlgorithm("Mac.AESCMAC", PREFIX + "$AESCMAC");
   3795 +            // END android-removed
   3796          }
   3797      }
   3798  }
   3799 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/ARC4.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/ARC4.java
   3800 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/ARC4.java	2012-03-22 15:11:48.000000000 +0000
   3801 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/ARC4.java	2012-09-19 21:17:12.000000000 +0000
   3802 @@ -27,7 +27,9 @@
   3803      {
   3804          public KeyGen()
   3805          {
   3806 -            super("RC4", 128, new CipherKeyGenerator());
   3807 +            // BEGIN android-changed
   3808 +            super("ARC4", 128, new CipherKeyGenerator());
   3809 +            // END android-changed
   3810          }
   3811      }
   3812  
   3813 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/Blowfish.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/Blowfish.java
   3814 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/Blowfish.java	2012-03-22 15:11:48.000000000 +0000
   3815 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/Blowfish.java	2012-09-19 21:17:12.000000000 +0000
   3816 @@ -64,7 +64,9 @@
   3817          {
   3818  
   3819              provider.addAlgorithm("Cipher.BLOWFISH", PREFIX + "$ECB");
   3820 -            provider.addAlgorithm("Cipher.1.3.6.1.4.1.3029.1.2", PREFIX + "$CBC");
   3821 +            // BEGIN android-removed
   3822 +            // provider.addAlgorithm("Cipher.1.3.6.1.4.1.3029.1.2", PREFIX + "$CBC");
   3823 +            // END android-removed
   3824              provider.addAlgorithm("KeyGenerator.BLOWFISH", PREFIX + "$KeyGen");
   3825              provider.addAlgorithm("Alg.Alias.KeyGenerator.1.3.6.1.4.1.3029.1.2", "BLOWFISH");
   3826              provider.addAlgorithm("AlgorithmParameters.BLOWFISH", PREFIX + "$AlgParams");
   3827 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/DES.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/DES.java
   3828 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/DES.java	2012-03-22 15:11:48.000000000 +0000
   3829 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/DES.java	2012-09-19 21:17:12.000000000 +0000
   3830 @@ -16,11 +16,15 @@
   3831  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   3832  import org.bouncycastle.crypto.KeyGenerationParameters;
   3833  import org.bouncycastle.crypto.engines.DESEngine;
   3834 -import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
   3835 +// BEGIN android-removed
   3836 +// import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
   3837 +// END android-removed
   3838  import org.bouncycastle.crypto.generators.DESKeyGenerator;
   3839  import org.bouncycastle.crypto.macs.CBCBlockCipherMac;
   3840 -import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   3841 -import org.bouncycastle.crypto.macs.CMac;
   3842 +// BEGIN android-removed
   3843 +// import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   3844 +// import org.bouncycastle.crypto.macs.CMac;
   3845 +// END android-removed
   3846  import org.bouncycastle.crypto.modes.CBCBlockCipher;
   3847  import org.bouncycastle.crypto.paddings.ISO7816d4Padding;
   3848  import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
   3849 @@ -48,115 +52,117 @@
   3850          }
   3851      }
   3852  
   3853 -    static public class CBC
   3854 -        extends BaseBlockCipher
   3855 -    {
   3856 -        public CBC()
   3857 -        {
   3858 -            super(new CBCBlockCipher(new DESEngine()), 64);
   3859 -        }
   3860 -    }
   3861 -
   3862 -    /**
   3863 -     * DES   CFB8
   3864 -     */
   3865 -    public static class DESCFB8
   3866 -        extends BaseMac
   3867 -    {
   3868 -        public DESCFB8()
   3869 -        {
   3870 -            super(new CFBBlockCipherMac(new DESEngine()));
   3871 -        }
   3872 -    }
   3873 -
   3874 -    /**
   3875 -     * DES64
   3876 -     */
   3877 -    public static class DES64
   3878 -        extends BaseMac
   3879 -    {
   3880 -        public DES64()
   3881 -        {
   3882 -            super(new CBCBlockCipherMac(new DESEngine(), 64));
   3883 -        }
   3884 -    }
   3885 -
   3886 -    /**
   3887 -     * DES64with7816-4Padding
   3888 -     */
   3889 -    public static class DES64with7816d4
   3890 -        extends BaseMac
   3891 -    {
   3892 -        public DES64with7816d4()
   3893 -        {
   3894 -            super(new CBCBlockCipherMac(new DESEngine(), 64, new ISO7816d4Padding()));
   3895 -        }
   3896 -    }
   3897 -    
   3898 -    public static class CBCMAC
   3899 -        extends BaseMac
   3900 -    {
   3901 -        public CBCMAC()
   3902 -        {
   3903 -            super(new CBCBlockCipherMac(new DESEngine()));
   3904 -        }
   3905 -    }
   3906 -
   3907 -    static public class CMAC
   3908 -        extends BaseMac
   3909 -    {
   3910 -        public CMAC()
   3911 -        {
   3912 -            super(new CMac(new DESEngine()));
   3913 -        }
   3914 -    }
   3915 -
   3916 -    public static class RFC3211
   3917 -        extends BaseWrapCipher
   3918 -    {
   3919 -        public RFC3211()
   3920 -        {
   3921 -            super(new RFC3211WrapEngine(new DESEngine()), 8);
   3922 -        }
   3923 -    }
   3924 -
   3925 -    public static class AlgParamGen
   3926 -        extends BaseAlgorithmParameterGenerator
   3927 -    {
   3928 -        protected void engineInit(
   3929 -            AlgorithmParameterSpec genParamSpec,
   3930 -            SecureRandom            random)
   3931 -            throws InvalidAlgorithmParameterException
   3932 -        {
   3933 -            throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for DES parameter generation.");
   3934 -        }
   3935 -
   3936 -        protected AlgorithmParameters engineGenerateParameters()
   3937 -        {
   3938 -            byte[]  iv = new byte[8];
   3939 -
   3940 -            if (random == null)
   3941 -            {
   3942 -                random = new SecureRandom();
   3943 -            }
   3944 -
   3945 -            random.nextBytes(iv);
   3946 -
   3947 -            AlgorithmParameters params;
   3948 -
   3949 -            try
   3950 -            {
   3951 -                params = AlgorithmParameters.getInstance("DES", BouncyCastleProvider.PROVIDER_NAME);
   3952 -                params.init(new IvParameterSpec(iv));
   3953 -            }
   3954 -            catch (Exception e)
   3955 -            {
   3956 -                throw new RuntimeException(e.getMessage());
   3957 -            }
   3958 -
   3959 -            return params;
   3960 -        }
   3961 -    }
   3962 +    // BEGIN android-removed
   3963 +    // static public class CBC
   3964 +    //     extends BaseBlockCipher
   3965 +    // {
   3966 +    //     public CBC()
   3967 +    //     {
   3968 +    //         super(new CBCBlockCipher(new DESEngine()), 64);
   3969 +    //     }
   3970 +    // }
   3971 +    //
   3972 +    // /**
   3973 +    //  * DES   CFB8
   3974 +    //  */
   3975 +    // public static class DESCFB8
   3976 +    //     extends BaseMac
   3977 +    // {
   3978 +    //     public DESCFB8()
   3979 +    //     {
   3980 +    //         super(new CFBBlockCipherMac(new DESEngine()));
   3981 +    //     }
   3982 +    // }
   3983 +    //
   3984 +    // /**
   3985 +    //  * DES64
   3986 +    //  */
   3987 +    // public static class DES64
   3988 +    //     extends BaseMac
   3989 +    // {
   3990 +    //     public DES64()
   3991 +    //     {
   3992 +    //         super(new CBCBlockCipherMac(new DESEngine(), 64));
   3993 +    //     }
   3994 +    // }
   3995 +    //
   3996 +    // /**
   3997 +    //  * DES64with7816-4Padding
   3998 +    //  */
   3999 +    // public static class DES64with7816d4
   4000 +    //     extends BaseMac
   4001 +    // {
   4002 +    //     public DES64with7816d4()
   4003 +    //     {
   4004 +    //         super(new CBCBlockCipherMac(new DESEngine(), 64, new ISO7816d4Padding()));
   4005 +    //     }
   4006 +    // }
   4007 +    //
   4008 +    // public static class CBCMAC
   4009 +    //     extends BaseMac
   4010 +    // {
   4011 +    //     public CBCMAC()
   4012 +    //     {
   4013 +    //         super(new CBCBlockCipherMac(new DESEngine()));
   4014 +    //     }
   4015 +    // }
   4016 +    //
   4017 +    // static public class CMAC
   4018 +    //     extends BaseMac
   4019 +    // {
   4020 +    //     public CMAC()
   4021 +    //     {
   4022 +    //         super(new CMac(new DESEngine()));
   4023 +    //     }
   4024 +    // }
   4025 +    //
   4026 +    // public static class RFC3211
   4027 +    //     extends BaseWrapCipher
   4028 +    // {
   4029 +    //     public RFC3211()
   4030 +    //     {
   4031 +    //         super(new RFC3211WrapEngine(new DESEngine()), 8);
   4032 +    //     }
   4033 +    // }
   4034 +    //
   4035 +    // public static class AlgParamGen
   4036 +    //     extends BaseAlgorithmParameterGenerator
   4037 +    // {
   4038 +    //     protected void engineInit(
   4039 +    //         AlgorithmParameterSpec genParamSpec,
   4040 +    //         SecureRandom            random)
   4041 +    //         throws InvalidAlgorithmParameterException
   4042 +    //     {
   4043 +    //         throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for DES parameter generation.");
   4044 +    //     }
   4045 +    //
   4046 +    //     protected AlgorithmParameters engineGenerateParameters()
   4047 +    //     {
   4048 +    //         byte[]  iv = new byte[8];
   4049 +    //
   4050 +    //         if (random == null)
   4051 +    //         {
   4052 +    //             random = new SecureRandom();
   4053 +    //         }
   4054 +    //
   4055 +    //         random.nextBytes(iv);
   4056 +    //
   4057 +    //         AlgorithmParameters params;
   4058 +    //
   4059 +    //         try
   4060 +    //         {
   4061 +    //             params = AlgorithmParameters.getInstance("DES", BouncyCastleProvider.PROVIDER_NAME);
   4062 +    //             params.init(new IvParameterSpec(iv));
   4063 +    //         }
   4064 +    //         catch (Exception e)
   4065 +    //         {
   4066 +    //             throw new RuntimeException(e.getMessage());
   4067 +    //         }
   4068 +    //
   4069 +    //         return params;
   4070 +    //     }
   4071 +    // }
   4072 +    // END android-removed
   4073  
   4074    /**
   4075       * DES - the default for this is to generate a key in
   4076 @@ -263,36 +269,42 @@
   4077          {
   4078  
   4079              provider.addAlgorithm("Cipher.DES", PREFIX + "$ECB");
   4080 -            provider.addAlgorithm("Cipher." + OIWObjectIdentifiers.desCBC, PREFIX + "$CBC");
   4081 -
   4082 -            addAlias(provider, OIWObjectIdentifiers.desCBC, "DES");
   4083 -
   4084 -            provider.addAlgorithm("Cipher.DESRFC3211WRAP", PREFIX + "$RFC3211");
   4085 +            // BEGIN android-removed
   4086 +            // provider.addAlgorithm("Cipher." + OIWObjectIdentifiers.desCBC, PREFIX + "$CBC");
   4087 +            //
   4088 +            // addAlias(provider, OIWObjectIdentifiers.desCBC, "DES");
   4089 +            //
   4090 +            // provider.addAlgorithm("Cipher.DESRFC3211WRAP", PREFIX + "$RFC3211");
   4091 +            // END android-removed
   4092  
   4093              provider.addAlgorithm("KeyGenerator.DES", PREFIX + "$KeyGenerator");
   4094  
   4095              provider.addAlgorithm("SecretKeyFactory.DES", PREFIX + "$KeyFactory");
   4096  
   4097 -            provider.addAlgorithm("Mac.DESCMAC", PREFIX + "$CMAC");
   4098 -            provider.addAlgorithm("Mac.DESMAC", PREFIX + "$CBCMAC");
   4099 -            provider.addAlgorithm("Alg.Alias.Mac.DES", "DESMAC");
   4100 -
   4101 -            provider.addAlgorithm("Mac.DESMAC/CFB8", PREFIX + "$DESCFB8");
   4102 -            provider.addAlgorithm("Alg.Alias.Mac.DES/CFB8", "DESMAC/CFB8");
   4103 -
   4104 -            provider.addAlgorithm("Mac.DESMAC64", PREFIX + "$DES64");
   4105 -            provider.addAlgorithm("Alg.Alias.Mac.DES64", "DESMAC64");
   4106 -
   4107 -            provider.addAlgorithm("Mac.DESMAC64WITHISO7816-4PADDING", PREFIX + "$DES64with7816d4");
   4108 -            provider.addAlgorithm("Alg.Alias.Mac.DES64WITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
   4109 -            provider.addAlgorithm("Alg.Alias.Mac.DESISO9797ALG1MACWITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
   4110 -            provider.addAlgorithm("Alg.Alias.Mac.DESISO9797ALG1WITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
   4111 +            // BEGIN android-removed
   4112 +            // provider.addAlgorithm("Mac.DESCMAC", PREFIX + "$CMAC");
   4113 +            // provider.addAlgorithm("Mac.DESMAC", PREFIX + "$CBCMAC");
   4114 +            // provider.addAlgorithm("Alg.Alias.Mac.DES", "DESMAC");
   4115 +            //
   4116 +            // provider.addAlgorithm("Mac.DESMAC/CFB8", PREFIX + "$DESCFB8");
   4117 +            // provider.addAlgorithm("Alg.Alias.Mac.DES/CFB8", "DESMAC/CFB8");
   4118 +            //
   4119 +            // provider.addAlgorithm("Mac.DESMAC64", PREFIX + "$DES64");
   4120 +            // provider.addAlgorithm("Alg.Alias.Mac.DES64", "DESMAC64");
   4121 +            //
   4122 +            // provider.addAlgorithm("Mac.DESMAC64WITHISO7816-4PADDING", PREFIX + "$DES64with7816d4");
   4123 +            // provider.addAlgorithm("Alg.Alias.Mac.DES64WITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
   4124 +            // provider.addAlgorithm("Alg.Alias.Mac.DESISO9797ALG1MACWITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
   4125 +            // provider.addAlgorithm("Alg.Alias.Mac.DESISO9797ALG1WITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
   4126 +            // END android-removed
   4127  
   4128              provider.addAlgorithm("AlgorithmParameters.DES", PACKAGE + ".util.IvAlgorithmParameters");
   4129              provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + OIWObjectIdentifiers.desCBC, "DES");
   4130  
   4131 -            provider.addAlgorithm("AlgorithmParameterGenerator.DES",  PREFIX + "$AlgParamGen");
   4132 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + OIWObjectIdentifiers.desCBC, "DES");
   4133 +            // BEGIN android-removed
   4134 +            // provider.addAlgorithm("AlgorithmParameterGenerator.DES",  PREFIX + "$AlgParamGen");
   4135 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + OIWObjectIdentifiers.desCBC, "DES");
   4136 +            // END android-removed
   4137          }
   4138  
   4139          private void addAlias(ConfigurableProvider provider, ASN1ObjectIdentifier oid, String name)
   4140 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/DESede.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/DESede.java
   4141 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/DESede.java	2012-03-22 15:11:48.000000000 +0000
   4142 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/DESede.java	2012-09-19 21:17:12.000000000 +0000
   4143 @@ -1,30 +1,42 @@
   4144  package org.bouncycastle.jcajce.provider.symmetric;
   4145  
   4146 -import java.security.AlgorithmParameters;
   4147 -import java.security.InvalidAlgorithmParameterException;
   4148 +// BEGIN android-removed
   4149 +// import java.security.AlgorithmParameters;
   4150 +// import java.security.InvalidAlgorithmParameterException;
   4151 +// END android-removed
   4152  import java.security.SecureRandom;
   4153 -import java.security.spec.AlgorithmParameterSpec;
   4154 +// BEGIN android-removed
   4155 +// import java.security.spec.AlgorithmParameterSpec;
   4156 +// END android-removed
   4157  import java.security.spec.InvalidKeySpecException;
   4158  import java.security.spec.KeySpec;
   4159  
   4160  import javax.crypto.SecretKey;
   4161  import javax.crypto.spec.DESedeKeySpec;
   4162 -import javax.crypto.spec.IvParameterSpec;
   4163 +// BEGIN android-removed
   4164 +// import javax.crypto.spec.IvParameterSpec;
   4165 +// END android-removed
   4166  import javax.crypto.spec.SecretKeySpec;
   4167  
   4168  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   4169  import org.bouncycastle.crypto.KeyGenerationParameters;
   4170  import org.bouncycastle.crypto.engines.DESedeEngine;
   4171  import org.bouncycastle.crypto.engines.DESedeWrapEngine;
   4172 -import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
   4173 +// BEGIN android-removed
   4174 +// import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
   4175 +// END android-removed
   4176  import org.bouncycastle.crypto.generators.DESedeKeyGenerator;
   4177  import org.bouncycastle.crypto.macs.CBCBlockCipherMac;
   4178 -import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   4179 -import org.bouncycastle.crypto.macs.CMac;
   4180 +// BEGIN android-removed
   4181 +// import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   4182 +// import org.bouncycastle.crypto.macs.CMac;
   4183 +// END android-removed
   4184  import org.bouncycastle.crypto.modes.CBCBlockCipher;
   4185  import org.bouncycastle.crypto.paddings.ISO7816d4Padding;
   4186  import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
   4187 -import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
   4188 +// BEGIN android-removed
   4189 +// import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
   4190 +// END android-removed
   4191  import org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher;
   4192  import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
   4193  import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
   4194 @@ -57,17 +69,19 @@
   4195          }
   4196      }
   4197  
   4198 -    /**
   4199 -     * DESede   CFB8
   4200 -     */
   4201 -    public static class DESedeCFB8
   4202 -        extends BaseMac
   4203 -    {
   4204 -        public DESedeCFB8()
   4205 -        {
   4206 -            super(new CFBBlockCipherMac(new DESedeEngine()));
   4207 -        }
   4208 -    }
   4209 +    // BEGIN android-removed
   4210 +    // /**
   4211 +    //  * DESede   CFB8
   4212 +    //  */
   4213 +    // public static class DESedeCFB8
   4214 +    //     extends BaseMac
   4215 +    // {
   4216 +    //     public DESedeCFB8()
   4217 +    //     {
   4218 +    //         super(new CFBBlockCipherMac(new DESedeEngine()));
   4219 +    //     }
   4220 +    // }
   4221 +    // END android-removed
   4222  
   4223      /**
   4224       * DESede64
   4225 @@ -102,15 +116,17 @@
   4226          }
   4227      }
   4228  
   4229 -    static public class CMAC
   4230 -        extends BaseMac
   4231 -    {
   4232 -        public CMAC()
   4233 -        {
   4234 -            super(new CMac(new DESedeEngine()));
   4235 -        }
   4236 -    }
   4237 -
   4238 +    // BEGIN android-removed
   4239 +    // static public class CMAC
   4240 +    //     extends BaseMac
   4241 +    // {
   4242 +    //     public CMAC()
   4243 +    //     {
   4244 +    //         super(new CMac(new DESedeEngine()));
   4245 +    //     }
   4246 +    // }
   4247 +    // END android-removed
   4248 +    
   4249      public static class Wrap
   4250          extends BaseWrapCipher
   4251      {
   4252 @@ -119,15 +135,17 @@
   4253              super(new DESedeWrapEngine());
   4254          }
   4255      }
   4256 -
   4257 -    public static class RFC3211
   4258 -        extends BaseWrapCipher
   4259 -    {
   4260 -        public RFC3211()
   4261 -        {
   4262 -            super(new RFC3211WrapEngine(new DESedeEngine()), 8);
   4263 -        }
   4264 -    }
   4265 +    
   4266 +    // BEGIN android-removed
   4267 +    // public static class RFC3211
   4268 +    //     extends BaseWrapCipher
   4269 +    // {
   4270 +    //     public RFC3211()
   4271 +    //     {
   4272 +    //         super(new RFC3211WrapEngine(new DESedeEngine()), 8);
   4273 +    //     }
   4274 +    // }
   4275 +    // END android-removed
   4276  
   4277    /**
   4278       * DESede - the default for this is to generate a key in
   4279 @@ -217,43 +235,45 @@
   4280          }
   4281      }
   4282  
   4283 -    public static class AlgParamGen
   4284 -        extends BaseAlgorithmParameterGenerator
   4285 -    {
   4286 -        protected void engineInit(
   4287 -            AlgorithmParameterSpec genParamSpec,
   4288 -            SecureRandom            random)
   4289 -            throws InvalidAlgorithmParameterException
   4290 -        {
   4291 -            throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for DES parameter generation.");
   4292 -        }
   4293 -
   4294 -        protected AlgorithmParameters engineGenerateParameters()
   4295 -        {
   4296 -            byte[]  iv = new byte[8];
   4297 -
   4298 -            if (random == null)
   4299 -            {
   4300 -                random = new SecureRandom();
   4301 -            }
   4302 -
   4303 -            random.nextBytes(iv);
   4304 -
   4305 -            AlgorithmParameters params;
   4306 -
   4307 -            try
   4308 -            {
   4309 -                params = AlgorithmParameters.getInstance("DES", BouncyCastleProvider.PROVIDER_NAME);
   4310 -                params.init(new IvParameterSpec(iv));
   4311 -            }
   4312 -            catch (Exception e)
   4313 -            {
   4314 -                throw new RuntimeException(e.getMessage());
   4315 -            }
   4316 -
   4317 -            return params;
   4318 -        }
   4319 -    }
   4320 +    // BEGIN android-removed
   4321 +    // public static class AlgParamGen
   4322 +    //     extends BaseAlgorithmParameterGenerator
   4323 +    // {
   4324 +    //     protected void engineInit(
   4325 +    //         AlgorithmParameterSpec genParamSpec,
   4326 +    //         SecureRandom            random)
   4327 +    //         throws InvalidAlgorithmParameterException
   4328 +    //     {
   4329 +    //         throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for DES parameter generation.");
   4330 +    //     }
   4331 +    //
   4332 +    //     protected AlgorithmParameters engineGenerateParameters()
   4333 +    //     {
   4334 +    //         byte[]  iv = new byte[8];
   4335 +    //
   4336 +    //         if (random == null)
   4337 +    //         {
   4338 +    //             random = new SecureRandom();
   4339 +    //         }
   4340 +    //
   4341 +    //         random.nextBytes(iv);
   4342 +    //
   4343 +    //         AlgorithmParameters params;
   4344 +    //
   4345 +    //         try
   4346 +    //         {
   4347 +    //             params = AlgorithmParameters.getInstance("DES", BouncyCastleProvider.PROVIDER_NAME);
   4348 +    //             params.init(new IvParameterSpec(iv));
   4349 +    //         }
   4350 +    //         catch (Exception e)
   4351 +    //         {
   4352 +    //             throw new RuntimeException(e.getMessage());
   4353 +    //         }
   4354 +    //
   4355 +    //         return params;
   4356 +    //     }
   4357 +    // }
   4358 +    // END android-removed
   4359  
   4360      static public class KeyFactory
   4361          extends BaseSecretKeyFactory
   4362 @@ -337,18 +357,28 @@
   4363          public void configure(ConfigurableProvider provider)
   4364          {
   4365              provider.addAlgorithm("Cipher.DESEDE", PREFIX + "$ECB");
   4366 -            provider.addAlgorithm("Cipher." + PKCSObjectIdentifiers.des_EDE3_CBC, PREFIX + "$CBC");
   4367 +            // BEGIN android-removed
   4368 +            // provider.addAlgorithm("Cipher." + PKCSObjectIdentifiers.des_EDE3_CBC, PREFIX + "$CBC");
   4369 +            // END android-removed
   4370              provider.addAlgorithm("Cipher.DESEDEWRAP", PREFIX + "$Wrap");
   4371 -            provider.addAlgorithm("Cipher." + PKCSObjectIdentifiers.id_alg_CMS3DESwrap, PREFIX + "$Wrap");
   4372 -            provider.addAlgorithm("Cipher.DESEDERFC3211WRAP", PREFIX + "$RFC3211");
   4373 +            // BEGIN android-changed
   4374 +            provider.addAlgorithm("Alg.Alias.Cipher." + PKCSObjectIdentifiers.id_alg_CMS3DESwrap, "DESEDEWRAP");
   4375 +            // END android-changed
   4376 +            // BEGIN android-removed
   4377 +            // provider.addAlgorithm("Cipher.DESEDERFC3211WRAP", PREFIX + "$RFC3211");
   4378 +            // END android-removed
   4379  
   4380              if (provider.hasAlgorithm("MessageDigest", "SHA-1"))
   4381              {
   4382                  provider.addAlgorithm("Cipher.PBEWITHSHAAND3-KEYTRIPLEDES-CBC", PREFIX + "$PBEWithSHAAndDES3Key");
   4383 -                provider.addAlgorithm("Cipher.BROKENPBEWITHSHAAND3-KEYTRIPLEDES-CBC", PREFIX + "$BrokePBEWithSHAAndDES3Key");
   4384 -                provider.addAlgorithm("Cipher.OLDPBEWITHSHAAND3-KEYTRIPLEDES-CBC", PREFIX + "$OldPBEWithSHAAndDES3Key");
   4385 +                // BEGIN android-removed
   4386 +                // provider.addAlgorithm("Cipher.BROKENPBEWITHSHAAND3-KEYTRIPLEDES-CBC", PREFIX + "$BrokePBEWithSHAAndDES3Key");
   4387 +                // provider.addAlgorithm("Cipher.OLDPBEWITHSHAAND3-KEYTRIPLEDES-CBC", PREFIX + "$OldPBEWithSHAAndDES3Key");
   4388 +                // END android-removed
   4389                  provider.addAlgorithm("Cipher.PBEWITHSHAAND2-KEYTRIPLEDES-CBC", PREFIX + "$PBEWithSHAAndDES2Key");
   4390 -                provider.addAlgorithm("Cipher.BROKENPBEWITHSHAAND2-KEYTRIPLEDES-CBC", PREFIX + "$BrokePBEWithSHAAndDES2Key");
   4391 +                // BEGIN android-removed
   4392 +                // provider.addAlgorithm("Cipher.BROKENPBEWITHSHAAND2-KEYTRIPLEDES-CBC", PREFIX + "$BrokePBEWithSHAAndDES2Key");
   4393 +                // END android-removed
   4394                  provider.addAlgorithm("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC, "PBEWITHSHAAND3-KEYTRIPLEDES-CBC");
   4395                  provider.addAlgorithm("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithSHAAnd2_KeyTripleDES_CBC, "PBEWITHSHAAND2-KEYTRIPLEDES-CBC");
   4396                  provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1ANDDESEDE", "PBEWITHSHAAND3-KEYTRIPLEDES-CBC");
   4397 @@ -357,31 +387,37 @@
   4398              }
   4399  
   4400              provider.addAlgorithm("KeyGenerator.DESEDE", PREFIX + "$KeyGenerator");
   4401 -            provider.addAlgorithm("KeyGenerator." + PKCSObjectIdentifiers.des_EDE3_CBC, PREFIX + "$KeyGenerator3");
   4402 -            provider.addAlgorithm("KeyGenerator.DESEDEWRAP", PREFIX + "$KeyGenerator");
   4403 +            // BEGIN android-removed
   4404 +            // provider.addAlgorithm("KeyGenerator." + PKCSObjectIdentifiers.des_EDE3_CBC, PREFIX + "$KeyGenerator3");
   4405 +            // provider.addAlgorithm("KeyGenerator.DESEDEWRAP", PREFIX + "$KeyGenerator");
   4406 +            // END android-removed
   4407  
   4408              provider.addAlgorithm("SecretKeyFactory.DESEDE", PREFIX + "$KeyFactory");
   4409  
   4410 -            provider.addAlgorithm("Mac.DESEDECMAC", PREFIX + "$CMAC");
   4411 -            provider.addAlgorithm("Mac.DESEDEMAC", PREFIX + "$CBCMAC");
   4412 -            provider.addAlgorithm("Alg.Alias.Mac.DESEDE", "DESEDEMAC");
   4413 -
   4414 -            provider.addAlgorithm("Mac.DESEDEMAC/CFB8", PREFIX + "$DESedeCFB8");
   4415 -            provider.addAlgorithm("Alg.Alias.Mac.DESEDE/CFB8", "DESEDEMAC/CFB8");
   4416 -
   4417 -            provider.addAlgorithm("Mac.DESEDEMAC64", PREFIX + "$DESede64");
   4418 -            provider.addAlgorithm("Alg.Alias.Mac.DESEDE64", "DESEDEMAC64");
   4419 -
   4420 -            provider.addAlgorithm("Mac.DESEDEMAC64WITHISO7816-4PADDING", PREFIX + "$DESede64with7816d4");
   4421 -            provider.addAlgorithm("Alg.Alias.Mac.DESEDE64WITHISO7816-4PADDING", "DESEDEMAC64WITHISO7816-4PADDING");
   4422 -            provider.addAlgorithm("Alg.Alias.Mac.DESEDEISO9797ALG1MACWITHISO7816-4PADDING", "DESEDEMAC64WITHISO7816-4PADDING");
   4423 -            provider.addAlgorithm("Alg.Alias.Mac.DESEDEISO9797ALG1WITHISO7816-4PADDING", "DESEDEMAC64WITHISO7816-4PADDING");
   4424 +            // BEGIN android-removed
   4425 +            // provider.addAlgorithm("Mac.DESEDECMAC", PREFIX + "$CMAC");
   4426 +            // provider.addAlgorithm("Mac.DESEDEMAC", PREFIX + "$CBCMAC");
   4427 +            // provider.addAlgorithm("Alg.Alias.Mac.DESEDE", "DESEDEMAC");
   4428 +            //
   4429 +            // provider.addAlgorithm("Mac.DESEDEMAC/CFB8", PREFIX + "$DESedeCFB8");
   4430 +            // provider.addAlgorithm("Alg.Alias.Mac.DESEDE/CFB8", "DESEDEMAC/CFB8");
   4431 +            //
   4432 +            // provider.addAlgorithm("Mac.DESEDEMAC64", PREFIX + "$DESede64");
   4433 +            // provider.addAlgorithm("Alg.Alias.Mac.DESEDE64", "DESEDEMAC64");
   4434 +            //
   4435 +            // provider.addAlgorithm("Mac.DESEDEMAC64WITHISO7816-4PADDING", PREFIX + "$DESede64with7816d4");
   4436 +            // provider.addAlgorithm("Alg.Alias.Mac.DESEDE64WITHISO7816-4PADDING", "DESEDEMAC64WITHISO7816-4PADDING");
   4437 +            // provider.addAlgorithm("Alg.Alias.Mac.DESEDEISO9797ALG1MACWITHISO7816-4PADDING", "DESEDEMAC64WITHISO7816-4PADDING");
   4438 +            // provider.addAlgorithm("Alg.Alias.Mac.DESEDEISO9797ALG1WITHISO7816-4PADDING", "DESEDEMAC64WITHISO7816-4PADDING");
   4439 +            // END android-removed
   4440  
   4441              provider.addAlgorithm("AlgorithmParameters.DESEDE", PACKAGE + ".util.IvAlgorithmParameters");
   4442              provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + PKCSObjectIdentifiers.des_EDE3_CBC, "DESEDE");
   4443  
   4444 -            provider.addAlgorithm("AlgorithmParameterGenerator.DESEDE",  PREFIX + "$AlgParamGen");
   4445 -            provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + PKCSObjectIdentifiers.des_EDE3_CBC, "DESEDE");
   4446 +            // BEGIN android-removed
   4447 +            // provider.addAlgorithm("AlgorithmParameterGenerator.DESEDE",  PREFIX + "$AlgParamGen");
   4448 +            // provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + PKCSObjectIdentifiers.des_EDE3_CBC, "DESEDE");
   4449 +            // END android-removed
   4450          }
   4451      }
   4452  }
   4453 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseAlgorithmParameters.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseAlgorithmParameters.java
   4454 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseAlgorithmParameters.java	2012-03-22 15:11:48.000000000 +0000
   4455 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseAlgorithmParameters.java	2012-09-19 21:17:12.000000000 +0000
   4456 @@ -7,13 +7,17 @@
   4457  
   4458  import javax.crypto.spec.IvParameterSpec;
   4459  import javax.crypto.spec.PBEParameterSpec;
   4460 -import javax.crypto.spec.RC2ParameterSpec;
   4461 +// BEGIN android-removed
   4462 +// import javax.crypto.spec.RC2ParameterSpec;
   4463 +// END android-removed
   4464  
   4465  import org.bouncycastle.asn1.ASN1Encoding;
   4466  import org.bouncycastle.asn1.ASN1Primitive;
   4467  import org.bouncycastle.asn1.pkcs.PBKDF2Params;
   4468  import org.bouncycastle.asn1.pkcs.PKCS12PBEParams;
   4469 -import org.bouncycastle.asn1.pkcs.RC2CBCParameter;
   4470 +// BEGIN android-removed
   4471 +// import org.bouncycastle.asn1.pkcs.RC2CBCParameter;
   4472 +// END android-removed
   4473  import org.bouncycastle.util.Arrays;
   4474  
   4475  public abstract class BaseAlgorithmParameters
   4476 @@ -39,177 +43,179 @@
   4477      protected abstract AlgorithmParameterSpec localEngineGetParameterSpec(Class paramSpec)
   4478          throws InvalidParameterSpecException;
   4479  
   4480 -    public static class RC2AlgorithmParameters
   4481 -        extends BaseAlgorithmParameters
   4482 -    {
   4483 -        private static final short[] table = {
   4484 -           0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a, 0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
   4485 -           0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b, 0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
   4486 -           0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda, 0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
   4487 -           0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8, 0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
   4488 -           0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17, 0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
   4489 -           0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72, 0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
   4490 -           0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd, 0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
   4491 -           0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b, 0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
   4492 -           0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77, 0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
   4493 -           0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3, 0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
   4494 -           0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e, 0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
   4495 -           0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d, 0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
   4496 -           0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46, 0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
   4497 -           0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97, 0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
   4498 -           0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef, 0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
   4499 -           0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf, 0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab
   4500 -        };
   4501 -
   4502 -        private static final short[] ekb = {
   4503 -           0x5d, 0xbe, 0x9b, 0x8b, 0x11, 0x99, 0x6e, 0x4d, 0x59, 0xf3, 0x85, 0xa6, 0x3f, 0xb7, 0x83, 0xc5,
   4504 -           0xe4, 0x73, 0x6b, 0x3a, 0x68, 0x5a, 0xc0, 0x47, 0xa0, 0x64, 0x34, 0x0c, 0xf1, 0xd0, 0x52, 0xa5,
   4505 -           0xb9, 0x1e, 0x96, 0x43, 0x41, 0xd8, 0xd4, 0x2c, 0xdb, 0xf8, 0x07, 0x77, 0x2a, 0xca, 0xeb, 0xef,
   4506 -           0x10, 0x1c, 0x16, 0x0d, 0x38, 0x72, 0x2f, 0x89, 0xc1, 0xf9, 0x80, 0xc4, 0x6d, 0xae, 0x30, 0x3d,
   4507 -           0xce, 0x20, 0x63, 0xfe, 0xe6, 0x1a, 0xc7, 0xb8, 0x50, 0xe8, 0x24, 0x17, 0xfc, 0x25, 0x6f, 0xbb,
   4508 -           0x6a, 0xa3, 0x44, 0x53, 0xd9, 0xa2, 0x01, 0xab, 0xbc, 0xb6, 0x1f, 0x98, 0xee, 0x9a, 0xa7, 0x2d,
   4509 -           0x4f, 0x9e, 0x8e, 0xac, 0xe0, 0xc6, 0x49, 0x46, 0x29, 0xf4, 0x94, 0x8a, 0xaf, 0xe1, 0x5b, 0xc3,
   4510 -           0xb3, 0x7b, 0x57, 0xd1, 0x7c, 0x9c, 0xed, 0x87, 0x40, 0x8c, 0xe2, 0xcb, 0x93, 0x14, 0xc9, 0x61,
   4511 -           0x2e, 0xe5, 0xcc, 0xf6, 0x5e, 0xa8, 0x5c, 0xd6, 0x75, 0x8d, 0x62, 0x95, 0x58, 0x69, 0x76, 0xa1,
   4512 -           0x4a, 0xb5, 0x55, 0x09, 0x78, 0x33, 0x82, 0xd7, 0xdd, 0x79, 0xf5, 0x1b, 0x0b, 0xde, 0x26, 0x21,
   4513 -           0x28, 0x74, 0x04, 0x97, 0x56, 0xdf, 0x3c, 0xf0, 0x37, 0x39, 0xdc, 0xff, 0x06, 0xa4, 0xea, 0x42,
   4514 -           0x08, 0xda, 0xb4, 0x71, 0xb0, 0xcf, 0x12, 0x7a, 0x4e, 0xfa, 0x6c, 0x1d, 0x84, 0x00, 0xc8, 0x7f,
   4515 -           0x91, 0x45, 0xaa, 0x2b, 0xc2, 0xb1, 0x8f, 0xd5, 0xba, 0xf2, 0xad, 0x19, 0xb2, 0x67, 0x36, 0xf7,
   4516 -           0x0f, 0x0a, 0x92, 0x7d, 0xe3, 0x9d, 0xe9, 0x90, 0x3e, 0x23, 0x27, 0x66, 0x13, 0xec, 0x81, 0x15,
   4517 -           0xbd, 0x22, 0xbf, 0x9f, 0x7e, 0xa9, 0x51, 0x4b, 0x4c, 0xfb, 0x02, 0xd3, 0x70, 0x86, 0x31, 0xe7,
   4518 -           0x3b, 0x05, 0x03, 0x54, 0x60, 0x48, 0x65, 0x18, 0xd2, 0xcd, 0x5f, 0x32, 0x88, 0x0e, 0x35, 0xfd
   4519 -        };
   4520 -
   4521 -        private byte[]  iv;
   4522 -        private int     parameterVersion = 58;
   4523 -
   4524 -        protected byte[] engineGetEncoded() 
   4525 -        {
   4526 -            return Arrays.clone(iv);
   4527 -        }
   4528 -
   4529 -        protected byte[] engineGetEncoded(
   4530 -            String format) 
   4531 -            throws IOException
   4532 -        {
   4533 -            if (this.isASN1FormatString(format))
   4534 -            {
   4535 -                if (parameterVersion == -1)
   4536 -                {
   4537 -                    return new RC2CBCParameter(engineGetEncoded()).getEncoded();
   4538 -                }
   4539 -                else
   4540 -                {
   4541 -                    return new RC2CBCParameter(parameterVersion, engineGetEncoded()).getEncoded();
   4542 -                }
   4543 -            }
   4544 -
   4545 -            if (format.equals("RAW"))
   4546 -            {
   4547 -                return engineGetEncoded();
   4548 -            }
   4549 -
   4550 -            return null;
   4551 -        }
   4552 -
   4553 -        protected AlgorithmParameterSpec localEngineGetParameterSpec(
   4554 -            Class paramSpec) 
   4555 -            throws InvalidParameterSpecException
   4556 -        {
   4557 -            if (paramSpec == RC2ParameterSpec.class)
   4558 -            {
   4559 -                if (parameterVersion != -1)
   4560 -                {
   4561 -                    if (parameterVersion < 256)
   4562 -                    {
   4563 -                        return new RC2ParameterSpec(ekb[parameterVersion], iv);
   4564 -                    }
   4565 -                    else
   4566 -                    {
   4567 -                        return new RC2ParameterSpec(parameterVersion, iv);
   4568 -                    }
   4569 -                }
   4570 -            }
   4571 -
   4572 -            if (paramSpec == IvParameterSpec.class)
   4573 -            {
   4574 -                return new IvParameterSpec(iv);
   4575 -            }
   4576 -
   4577 -            throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object.");
   4578 -        }
   4579 -
   4580 -        protected void engineInit(
   4581 -            AlgorithmParameterSpec paramSpec) 
   4582 -            throws InvalidParameterSpecException
   4583 -        {
   4584 -            if (paramSpec instanceof IvParameterSpec)
   4585 -            {
   4586 -                this.iv = ((IvParameterSpec)paramSpec).getIV();
   4587 -            }
   4588 -            else if (paramSpec instanceof RC2ParameterSpec)
   4589 -            {
   4590 -                int effKeyBits = ((RC2ParameterSpec)paramSpec).getEffectiveKeyBits();
   4591 -                if (effKeyBits != -1)
   4592 -                {
   4593 -                    if (effKeyBits < 256)
   4594 -                    {
   4595 -                        parameterVersion = table[effKeyBits];
   4596 -                    }
   4597 -                    else
   4598 -                    {
   4599 -                        parameterVersion = effKeyBits;
   4600 -                    }
   4601 -                }
   4602 -
   4603 -                this.iv = ((RC2ParameterSpec)paramSpec).getIV();
   4604 -            }
   4605 -            else
   4606 -            {
   4607 -                throw new InvalidParameterSpecException("IvParameterSpec or RC2ParameterSpec required to initialise a RC2 parameters algorithm parameters object");
   4608 -            }
   4609 -        }
   4610 -
   4611 -        protected void engineInit(
   4612 -            byte[] params) 
   4613 -            throws IOException
   4614 -        {
   4615 -            this.iv = Arrays.clone(params);
   4616 -        }
   4617 -
   4618 -        protected void engineInit(
   4619 -            byte[] params,
   4620 -            String format) 
   4621 -            throws IOException
   4622 -        {
   4623 -            if (this.isASN1FormatString(format))
   4624 -            {
   4625 -                RC2CBCParameter p = RC2CBCParameter.getInstance(ASN1Primitive.fromByteArray(params));
   4626 -
   4627 -                if (p.getRC2ParameterVersion() != null)
   4628 -                {
   4629 -                    parameterVersion = p.getRC2ParameterVersion().intValue();
   4630 -                }
   4631 -
   4632 -                iv = p.getIV();
   4633 -
   4634 -                return;
   4635 -            }
   4636 -
   4637 -            if (format.equals("RAW"))
   4638 -            {
   4639 -                engineInit(params);
   4640 -                return;
   4641 -            }
   4642 -
   4643 -            throw new IOException("Unknown parameters format in IV parameters object");
   4644 -        }
   4645 -
   4646 -        protected String engineToString() 
   4647 -        {
   4648 -            return "RC2 Parameters";
   4649 -        }
   4650 -    }
   4651 +    // BEGIN android-removed
   4652 +    // public static class RC2AlgorithmParameters
   4653 +    //     extends BaseAlgorithmParameters
   4654 +    // {
   4655 +    //     private static final short[] table = {
   4656 +    //        0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a, 0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
   4657 +    //        0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b, 0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
   4658 +    //        0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda, 0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
   4659 +    //        0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8, 0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
   4660 +    //        0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17, 0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
   4661 +    //        0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72, 0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
   4662 +    //        0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd, 0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
   4663 +    //        0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b, 0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
   4664 +    //        0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77, 0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
   4665 +    //        0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3, 0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
   4666 +    //        0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e, 0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
   4667 +    //        0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d, 0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
   4668 +    //        0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46, 0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
   4669 +    //        0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97, 0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
   4670 +    //        0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef, 0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
   4671 +    //        0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf, 0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab
   4672 +    //     };
   4673 +    //
   4674 +    //     private static final short[] ekb = {
   4675 +    //        0x5d, 0xbe, 0x9b, 0x8b, 0x11, 0x99, 0x6e, 0x4d, 0x59, 0xf3, 0x85, 0xa6, 0x3f, 0xb7, 0x83, 0xc5,
   4676 +    //        0xe4, 0x73, 0x6b, 0x3a, 0x68, 0x5a, 0xc0, 0x47, 0xa0, 0x64, 0x34, 0x0c, 0xf1, 0xd0, 0x52, 0xa5,
   4677 +    //        0xb9, 0x1e, 0x96, 0x43, 0x41, 0xd8, 0xd4, 0x2c, 0xdb, 0xf8, 0x07, 0x77, 0x2a, 0xca, 0xeb, 0xef,
   4678 +    //        0x10, 0x1c, 0x16, 0x0d, 0x38, 0x72, 0x2f, 0x89, 0xc1, 0xf9, 0x80, 0xc4, 0x6d, 0xae, 0x30, 0x3d,
   4679 +    //        0xce, 0x20, 0x63, 0xfe, 0xe6, 0x1a, 0xc7, 0xb8, 0x50, 0xe8, 0x24, 0x17, 0xfc, 0x25, 0x6f, 0xbb,
   4680 +    //        0x6a, 0xa3, 0x44, 0x53, 0xd9, 0xa2, 0x01, 0xab, 0xbc, 0xb6, 0x1f, 0x98, 0xee, 0x9a, 0xa7, 0x2d,
   4681 +    //        0x4f, 0x9e, 0x8e, 0xac, 0xe0, 0xc6, 0x49, 0x46, 0x29, 0xf4, 0x94, 0x8a, 0xaf, 0xe1, 0x5b, 0xc3,
   4682 +    //        0xb3, 0x7b, 0x57, 0xd1, 0x7c, 0x9c, 0xed, 0x87, 0x40, 0x8c, 0xe2, 0xcb, 0x93, 0x14, 0xc9, 0x61,
   4683 +    //        0x2e, 0xe5, 0xcc, 0xf6, 0x5e, 0xa8, 0x5c, 0xd6, 0x75, 0x8d, 0x62, 0x95, 0x58, 0x69, 0x76, 0xa1,
   4684 +    //        0x4a, 0xb5, 0x55, 0x09, 0x78, 0x33, 0x82, 0xd7, 0xdd, 0x79, 0xf5, 0x1b, 0x0b, 0xde, 0x26, 0x21,
   4685 +    //        0x28, 0x74, 0x04, 0x97, 0x56, 0xdf, 0x3c, 0xf0, 0x37, 0x39, 0xdc, 0xff, 0x06, 0xa4, 0xea, 0x42,
   4686 +    //        0x08, 0xda, 0xb4, 0x71, 0xb0, 0xcf, 0x12, 0x7a, 0x4e, 0xfa, 0x6c, 0x1d, 0x84, 0x00, 0xc8, 0x7f,
   4687 +    //        0x91, 0x45, 0xaa, 0x2b, 0xc2, 0xb1, 0x8f, 0xd5, 0xba, 0xf2, 0xad, 0x19, 0xb2, 0x67, 0x36, 0xf7,
   4688 +    //        0x0f, 0x0a, 0x92, 0x7d, 0xe3, 0x9d, 0xe9, 0x90, 0x3e, 0x23, 0x27, 0x66, 0x13, 0xec, 0x81, 0x15,
   4689 +    //        0xbd, 0x22, 0xbf, 0x9f, 0x7e, 0xa9, 0x51, 0x4b, 0x4c, 0xfb, 0x02, 0xd3, 0x70, 0x86, 0x31, 0xe7,
   4690 +    //        0x3b, 0x05, 0x03, 0x54, 0x60, 0x48, 0x65, 0x18, 0xd2, 0xcd, 0x5f, 0x32, 0x88, 0x0e, 0x35, 0xfd
   4691 +    //     };
   4692 +    //
   4693 +    //     private byte[]  iv;
   4694 +    //     private int     parameterVersion = 58;
   4695 +    //
   4696 +    //     protected byte[] engineGetEncoded() 
   4697 +    //     {
   4698 +    //         return Arrays.clone(iv);
   4699 +    //     }
   4700 +    //
   4701 +    //     protected byte[] engineGetEncoded(
   4702 +    //         String format) 
   4703 +    //         throws IOException
   4704 +    //     {
   4705 +    //         if (this.isASN1FormatString(format))
   4706 +    //         {
   4707 +    //             if (parameterVersion == -1)
   4708 +    //             {
   4709 +    //                 return new RC2CBCParameter(engineGetEncoded()).getEncoded();
   4710 +    //             }
   4711 +    //             else
   4712 +    //             {
   4713 +    //                 return new RC2CBCParameter(parameterVersion, engineGetEncoded()).getEncoded();
   4714 +    //             }
   4715 +    //         }
   4716 +    //
   4717 +    //         if (format.equals("RAW"))
   4718 +    //         {
   4719 +    //             return engineGetEncoded();
   4720 +    //         }
   4721 +    //
   4722 +    //         return null;
   4723 +    //     }
   4724 +    //
   4725 +    //     protected AlgorithmParameterSpec localEngineGetParameterSpec(
   4726 +    //         Class paramSpec) 
   4727 +    //         throws InvalidParameterSpecException
   4728 +    //     {
   4729 +    //         if (paramSpec == RC2ParameterSpec.class)
   4730 +    //         {
   4731 +    //             if (parameterVersion != -1)
   4732 +    //             {
   4733 +    //                 if (parameterVersion < 256)
   4734 +    //                 {
   4735 +    //                     return new RC2ParameterSpec(ekb[parameterVersion], iv);
   4736 +    //                 }
   4737 +    //                 else
   4738 +    //                 {
   4739 +    //                     return new RC2ParameterSpec(parameterVersion, iv);
   4740 +    //                 }
   4741 +    //             }
   4742 +    //         }
   4743 +    //
   4744 +    //         if (paramSpec == IvParameterSpec.class)
   4745 +    //         {
   4746 +    //             return new IvParameterSpec(iv);
   4747 +    //         }
   4748 +    //
   4749 +    //         throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object.");
   4750 +    //     }
   4751 +    //
   4752 +    //     protected void engineInit(
   4753 +    //         AlgorithmParameterSpec paramSpec) 
   4754 +    //         throws InvalidParameterSpecException
   4755 +    //     {
   4756 +    //         if (paramSpec instanceof IvParameterSpec)
   4757 +    //         {
   4758 +    //             this.iv = ((IvParameterSpec)paramSpec).getIV();
   4759 +    //         }
   4760 +    //         else if (paramSpec instanceof RC2ParameterSpec)
   4761 +    //         {
   4762 +    //             int effKeyBits = ((RC2ParameterSpec)paramSpec).getEffectiveKeyBits();
   4763 +    //             if (effKeyBits != -1)
   4764 +    //             {
   4765 +    //                 if (effKeyBits < 256)
   4766 +    //                 {
   4767 +    //                     parameterVersion = table[effKeyBits];
   4768 +    //                 }
   4769 +    //                 else
   4770 +    //                 {
   4771 +    //                     parameterVersion = effKeyBits;
   4772 +    //                 }
   4773 +    //             }
   4774 +    //
   4775 +    //             this.iv = ((RC2ParameterSpec)paramSpec).getIV();
   4776 +    //         }
   4777 +    //         else
   4778 +    //         {
   4779 +    //             throw new InvalidParameterSpecException("IvParameterSpec or RC2ParameterSpec required to initialise a RC2 parameters algorithm parameters object");
   4780 +    //         }
   4781 +    //     }
   4782 +    //
   4783 +    //     protected void engineInit(
   4784 +    //         byte[] params) 
   4785 +    //         throws IOException
   4786 +    //     {
   4787 +    //         this.iv = Arrays.clone(params);
   4788 +    //     }
   4789 +    //
   4790 +    //     protected void engineInit(
   4791 +    //         byte[] params,
   4792 +    //         String format) 
   4793 +    //         throws IOException
   4794 +    //     {
   4795 +    //         if (this.isASN1FormatString(format))
   4796 +    //         {
   4797 +    //             RC2CBCParameter p = RC2CBCParameter.getInstance(ASN1Primitive.fromByteArray(params));
   4798 +    //
   4799 +    //             if (p.getRC2ParameterVersion() != null)
   4800 +    //             {
   4801 +    //                 parameterVersion = p.getRC2ParameterVersion().intValue();
   4802 +    //             }
   4803 +    //
   4804 +    //             iv = p.getIV();
   4805 +    //
   4806 +    //             return;
   4807 +    //         }
   4808 +    //
   4809 +    //         if (format.equals("RAW"))
   4810 +    //         {
   4811 +    //             engineInit(params);
   4812 +    //             return;
   4813 +    //         }
   4814 +    //
   4815 +    //         throw new IOException("Unknown parameters format in IV parameters object");
   4816 +    //     }
   4817 +    //
   4818 +    //     protected String engineToString() 
   4819 +    //     {
   4820 +    //         return "RC2 Parameters";
   4821 +    //     }
   4822 +    // }
   4823 +    // END android-removed
   4824  
   4825      public static class PBKDF2
   4826          extends BaseAlgorithmParameters
   4827 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
   4828 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java	2012-03-22 15:11:48.000000000 +0000
   4829 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java	2012-09-19 21:17:12.000000000 +0000
   4830 @@ -17,8 +17,10 @@
   4831  import javax.crypto.ShortBufferException;
   4832  import javax.crypto.spec.IvParameterSpec;
   4833  import javax.crypto.spec.PBEParameterSpec;
   4834 -import javax.crypto.spec.RC2ParameterSpec;
   4835 -import javax.crypto.spec.RC5ParameterSpec;
   4836 +// BEGIN android-removed
   4837 +// import javax.crypto.spec.RC2ParameterSpec;
   4838 +// import javax.crypto.spec.RC5ParameterSpec;
   4839 +// END android-removed
   4840  
   4841  import org.bouncycastle.crypto.BufferedBlockCipher;
   4842  import org.bouncycastle.crypto.CipherParameters;
   4843 @@ -29,12 +31,18 @@
   4844  import org.bouncycastle.crypto.modes.CCMBlockCipher;
   4845  import org.bouncycastle.crypto.modes.CFBBlockCipher;
   4846  import org.bouncycastle.crypto.modes.CTSBlockCipher;
   4847 -import org.bouncycastle.crypto.modes.EAXBlockCipher;
   4848 +// BEGIN android-removed
   4849 +// import org.bouncycastle.crypto.modes.EAXBlockCipher;
   4850 +// END android-removed
   4851  import org.bouncycastle.crypto.modes.GCMBlockCipher;
   4852 -import org.bouncycastle.crypto.modes.GOFBBlockCipher;
   4853 +// BEGIN android-removed
   4854 +// import org.bouncycastle.crypto.modes.GOFBBlockCipher;
   4855 +// END android-removed
   4856  import org.bouncycastle.crypto.modes.OFBBlockCipher;
   4857 -import org.bouncycastle.crypto.modes.OpenPGPCFBBlockCipher;
   4858 -import org.bouncycastle.crypto.modes.PGPCFBBlockCipher;
   4859 +// BEGIN android-removed
   4860 +// import org.bouncycastle.crypto.modes.OpenPGPCFBBlockCipher;
   4861 +// import org.bouncycastle.crypto.modes.PGPCFBBlockCipher;
   4862 +// END android-removed
   4863  import org.bouncycastle.crypto.modes.SICBlockCipher;
   4864  import org.bouncycastle.crypto.paddings.BlockCipherPadding;
   4865  import org.bouncycastle.crypto.paddings.ISO10126d2Padding;
   4866 @@ -46,11 +54,17 @@
   4867  import org.bouncycastle.crypto.params.KeyParameter;
   4868  import org.bouncycastle.crypto.params.ParametersWithIV;
   4869  import org.bouncycastle.crypto.params.ParametersWithRandom;
   4870 -import org.bouncycastle.crypto.params.ParametersWithSBox;
   4871 +// BEGIN android-removed
   4872 +// import org.bouncycastle.crypto.params.ParametersWithSBox;
   4873 +// END android-removed
   4874  import org.bouncycastle.crypto.params.RC2Parameters;
   4875 -import org.bouncycastle.crypto.params.RC5Parameters;
   4876 +// BEGIN android-removed
   4877 +// import org.bouncycastle.crypto.params.RC5Parameters;
   4878 +// END android-removed
   4879  import org.bouncycastle.jce.provider.BouncyCastleProvider;
   4880 -import org.bouncycastle.jce.spec.GOST28147ParameterSpec;
   4881 +// BEGIN android-removed
   4882 +// import org.bouncycastle.jce.spec.GOST28147ParameterSpec;
   4883 +// END android-removed
   4884  import org.bouncycastle.jce.spec.RepeatedSecretKeySpec;
   4885  import org.bouncycastle.util.Strings;
   4886  
   4887 @@ -63,11 +77,15 @@
   4888      //
   4889      private Class[]                 availableSpecs =
   4890                                      {
   4891 -                                        RC2ParameterSpec.class,
   4892 -                                        RC5ParameterSpec.class,
   4893 +                                        // BEGIN android-removed
   4894 +                                        // RC2ParameterSpec.class,
   4895 +                                        // RC5ParameterSpec.class,
   4896 +                                        // END android-removed
   4897                                          IvParameterSpec.class,
   4898                                          PBEParameterSpec.class,
   4899 -                                        GOST28147ParameterSpec.class
   4900 +                                        // BEGIN android-removed
   4901 +                                        // GOST28147ParameterSpec.class
   4902 +                                        // END android-removed
   4903                                      };
   4904  
   4905      private org.bouncycastle.crypto.BlockCipher baseEngine;
   4906 @@ -222,20 +240,22 @@
   4907                          new CFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
   4908              }
   4909          }
   4910 -        else if (modeName.startsWith("PGP"))
   4911 -        {
   4912 -            boolean inlineIV = modeName.equalsIgnoreCase("PGPCFBwithIV");
   4913 -
   4914 -            ivLength = baseEngine.getBlockSize();
   4915 -            cipher = new BufferedGenericBlockCipher(
   4916 -                new PGPCFBBlockCipher(baseEngine, inlineIV));
   4917 -        }
   4918 -        else if (modeName.equalsIgnoreCase("OpenPGPCFB"))
   4919 -        {
   4920 -            ivLength = 0;
   4921 -            cipher = new BufferedGenericBlockCipher(
   4922 -                new OpenPGPCFBBlockCipher(baseEngine));
   4923 -        }
   4924 +        // BEGIN android-removed
   4925 +        // else if (modeName.startsWith("PGP"))
   4926 +        // {
   4927 +        //     boolean inlineIV = modeName.equalsIgnoreCase("PGPCFBwithIV");
   4928 +
   4929 +        //     ivLength = baseEngine.getBlockSize();
   4930 +        //     cipher = new BufferedGenericBlockCipher(
   4931 +        //         new PGPCFBBlockCipher(baseEngine, inlineIV));
   4932 +        // }
   4933 +        // else if (modeName.equalsIgnoreCase("OpenPGPCFB"))
   4934 +        // {
   4935 +        //     ivLength = 0;
   4936 +        //     cipher = new BufferedGenericBlockCipher(
   4937 +        //         new OpenPGPCFBBlockCipher(baseEngine));
   4938 +        // }
   4939 +        // END android-removed
   4940          else if (modeName.startsWith("SIC"))
   4941          {
   4942              ivLength = baseEngine.getBlockSize();
   4943 @@ -252,12 +272,14 @@
   4944              cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
   4945                          new SICBlockCipher(baseEngine)));
   4946          }
   4947 -        else if (modeName.startsWith("GOFB"))
   4948 -        {
   4949 -            ivLength = baseEngine.getBlockSize();
   4950 -            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
   4951 -                        new GOFBBlockCipher(baseEngine)));
   4952 -        }
   4953 +        // BEGIN android-removed
   4954 +        // else if (modeName.startsWith("GOFB"))
   4955 +        // {
   4956 +        //     ivLength = baseEngine.getBlockSize();
   4957 +        //     cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
   4958 +        //                 new GOFBBlockCipher(baseEngine)));
   4959 +        // }
   4960 +        // END android-removed
   4961          else if (modeName.startsWith("CTS"))
   4962          {
   4963              ivLength = baseEngine.getBlockSize();
   4964 @@ -268,11 +290,13 @@
   4965              ivLength = baseEngine.getBlockSize();
   4966              cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));
   4967          }
   4968 -        else if (modeName.startsWith("EAX"))
   4969 -        {
   4970 -            ivLength = baseEngine.getBlockSize();
   4971 -            cipher = new AEADGenericBlockCipher(new EAXBlockCipher(baseEngine));
   4972 -        }
   4973 +        // BEGIN android-removed
   4974 +        // else if (modeName.startsWith("EAX"))
   4975 +        // {
   4976 +        //     ivLength = baseEngine.getBlockSize();
   4977 +        //     cipher = new AEADGenericBlockCipher(new EAXBlockCipher(baseEngine));
   4978 +        // }
   4979 +        // END android-removed
   4980          else if (modeName.startsWith("GCM"))
   4981          {
   4982              ivLength = baseEngine.getBlockSize();
   4983 @@ -441,63 +465,65 @@
   4984                  param = new KeyParameter(key.getEncoded());
   4985              }
   4986          }
   4987 -        else if (params instanceof GOST28147ParameterSpec)
   4988 -        {
   4989 -            GOST28147ParameterSpec    gost28147Param = (GOST28147ParameterSpec)params;
   4990 -
   4991 -            param = new ParametersWithSBox(
   4992 -                       new KeyParameter(key.getEncoded()), ((GOST28147ParameterSpec)params).getSbox());
   4993 -
   4994 -            if (gost28147Param.getIV() != null && ivLength != 0)
   4995 -            {
   4996 -                param = new ParametersWithIV(param, gost28147Param.getIV());
   4997 -                ivParam = (ParametersWithIV)param;
   4998 -            }
   4999 -        }
   5000 -        else if (params instanceof RC2ParameterSpec)
   5001 -        {
   5002 -            RC2ParameterSpec    rc2Param = (RC2ParameterSpec)params;
   5003 -
   5004 -            param = new RC2Parameters(key.getEncoded(), ((RC2ParameterSpec)params).getEffectiveKeyBits());
   5005 -
   5006 -            if (rc2Param.getIV() != null && ivLength != 0)
   5007 -            {
   5008 -                param = new ParametersWithIV(param, rc2Param.getIV());
   5009 -                ivParam = (ParametersWithIV)param;
   5010 -            }
   5011 -        }
   5012 -        else if (params instanceof RC5ParameterSpec)
   5013 -        {
   5014 -            RC5ParameterSpec    rc5Param = (RC5ParameterSpec)params;
   5015 -
   5016 -            param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
   5017 -            if (baseEngine.getAlgorithmName().startsWith("RC5"))
   5018 -            {
   5019 -                if (baseEngine.getAlgorithmName().equals("RC5-32"))
   5020 -                {
   5021 -                    if (rc5Param.getWordSize() != 32)
   5022 -                    {
   5023 -                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 32 not " + rc5Param.getWordSize() + ".");
   5024 -                    }
   5025 -                }
   5026 -                else if (baseEngine.getAlgorithmName().equals("RC5-64"))
   5027 -                {
   5028 -                    if (rc5Param.getWordSize() != 64)
   5029 -                    {
   5030 -                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 64 not " + rc5Param.getWordSize() + ".");
   5031 -                    }
   5032 -                }
   5033 -            }
   5034 -            else
   5035 -            {
   5036 -                throw new InvalidAlgorithmParameterException("RC5 parameters passed to a cipher that is not RC5.");
   5037 -            }
   5038 -            if ((rc5Param.getIV() != null) && (ivLength != 0))
   5039 -            {
   5040 -                param = new ParametersWithIV(param, rc5Param.getIV());
   5041 -                ivParam = (ParametersWithIV)param;
   5042 -            }
   5043 -        }
   5044 +        // BEGIN android-removed
   5045 +        // else if (params instanceof GOST28147ParameterSpec)
   5046 +        // {
   5047 +        //     GOST28147ParameterSpec    gost28147Param = (GOST28147ParameterSpec)params;
   5048 +        //
   5049 +        //     param = new ParametersWithSBox(
   5050 +        //                new KeyParameter(key.getEncoded()), ((GOST28147ParameterSpec)params).getSbox());
   5051 +        //
   5052 +        //     if (gost28147Param.getIV() != null && ivLength != 0)
   5053 +        //     {
   5054 +        //         param = new ParametersWithIV(param, gost28147Param.getIV());
   5055 +        //         ivParam = (ParametersWithIV)param;
   5056 +        //     }
   5057 +        // }
   5058 +        // else if (params instanceof RC2ParameterSpec)
   5059 +        // {
   5060 +        //     RC2ParameterSpec    rc2Param = (RC2ParameterSpec)params;
   5061 +        //
   5062 +        //     param = new RC2Parameters(key.getEncoded(), ((RC2ParameterSpec)params).getEffectiveKeyBits());
   5063 +        //
   5064 +        //     if (rc2Param.getIV() != null && ivLength != 0)
   5065 +        //     {
   5066 +        //         param = new ParametersWithIV(param, rc2Param.getIV());
   5067 +        //         ivParam = (ParametersWithIV)param;
   5068 +        //     }
   5069 +        // }
   5070 +        // else if (params instanceof RC5ParameterSpec)
   5071 +        // {
   5072 +        //     RC5ParameterSpec    rc5Param = (RC5ParameterSpec)params;
   5073 +        //
   5074 +        //     param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
   5075 +        //     if (baseEngine.getAlgorithmName().startsWith("RC5"))
   5076 +        //     {
   5077 +        //         if (baseEngine.getAlgorithmName().equals("RC5-32"))
   5078 +        //         {
   5079 +        //             if (rc5Param.getWordSize() != 32)
   5080 +        //             {
   5081 +        //                 throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 32 not " + rc5Param.getWordSize() + ".");
   5082 +        //             }
   5083 +        //         }
   5084 +        //         else if (baseEngine.getAlgorithmName().equals("RC5-64"))
   5085 +        //         {
   5086 +        //             if (rc5Param.getWordSize() != 64)
   5087 +        //             {
   5088 +        //                 throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 64 not " + rc5Param.getWordSize() + ".");
   5089 +        //             }
   5090 +        //         }
   5091 +        //     }
   5092 +        //     else
   5093 +        //     {
   5094 +        //         throw new InvalidAlgorithmParameterException("RC5 parameters passed to a cipher that is not RC5.");
   5095 +        //     }
   5096 +        //     if ((rc5Param.getIV() != null) && (ivLength != 0))
   5097 +        //     {
   5098 +        //         param = new ParametersWithIV(param, rc5Param.getIV());
   5099 +        //         ivParam = (ParametersWithIV)param;
   5100 +        //     }
   5101 +        // }
   5102 +        // END android-removed
   5103          else
   5104          {
   5105              throw new InvalidAlgorithmParameterException("unknown parameter type.");
   5106 @@ -701,10 +727,20 @@
   5107          int     inputLen,
   5108          byte[]  output,
   5109          int     outputOffset) 
   5110 -        throws IllegalBlockSizeException, BadPaddingException
   5111 +        throws IllegalBlockSizeException, BadPaddingException, ShortBufferException
   5112      {
   5113 +        // BEGIN android-note
   5114 +        // added ShortBufferException to the throws statement
   5115 +        // END android-note
   5116          int     len = 0;
   5117  
   5118 +        // BEGIN android-added
   5119 +        int outputLen = cipher.getOutputSize(inputLen);
   5120 +
   5121 +        if (outputLen + outputOffset > output.length) {
   5122 +            throw new ShortBufferException("need at least " + outputLen + " bytes");
   5123 +        }
   5124 +        // BEGIN android-added
   5125          if (inputLen != 0)
   5126          {
   5127                  len = cipher.processBytes(input, inputOffset, inputLen, output, outputOffset);
   5128 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseKeyGenerator.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseKeyGenerator.java
   5129 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseKeyGenerator.java	2012-03-22 15:11:48.000000000 +0000
   5130 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseKeyGenerator.java	2012-09-19 21:17:12.000000000 +0000
   5131 @@ -56,6 +56,11 @@
   5132      {
   5133          try
   5134          {
   5135 +            // BEGIN android-added
   5136 +            if (random == null) {
   5137 +                random = new SecureRandom();
   5138 +            }
   5139 +            // END android-added
   5140              engine.init(new KeyGenerationParameters(random, keySize));
   5141              uninitialised = false;
   5142          }
   5143 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseMac.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseMac.java
   5144 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseMac.java	2012-03-22 15:11:48.000000000 +0000
   5145 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseMac.java	2012-09-19 21:17:12.000000000 +0000
   5146 @@ -11,25 +11,34 @@
   5147  
   5148  import org.bouncycastle.crypto.CipherParameters;
   5149  import org.bouncycastle.crypto.Mac;
   5150 -import org.bouncycastle.crypto.digests.MD2Digest;
   5151 -import org.bouncycastle.crypto.digests.MD4Digest;
   5152 -import org.bouncycastle.crypto.digests.MD5Digest;
   5153 -import org.bouncycastle.crypto.digests.RIPEMD128Digest;
   5154 -import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   5155 -import org.bouncycastle.crypto.digests.SHA1Digest;
   5156 -import org.bouncycastle.crypto.digests.SHA224Digest;
   5157 -import org.bouncycastle.crypto.digests.SHA256Digest;
   5158 -import org.bouncycastle.crypto.digests.SHA384Digest;
   5159 -import org.bouncycastle.crypto.digests.SHA512Digest;
   5160 -import org.bouncycastle.crypto.digests.TigerDigest;
   5161 +// BEGIN android-removed
   5162 +// import org.bouncycastle.crypto.digests.MD2Digest;
   5163 +// import org.bouncycastle.crypto.digests.MD4Digest;
   5164 +// import org.bouncycastle.crypto.digests.MD5Digest;
   5165 +// import org.bouncycastle.crypto.digests.RIPEMD128Digest;
   5166 +// import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   5167 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   5168 +// import org.bouncycastle.crypto.digests.SHA224Digest;
   5169 +// import org.bouncycastle.crypto.digests.SHA256Digest;
   5170 +// import org.bouncycastle.crypto.digests.SHA384Digest;
   5171 +// import org.bouncycastle.crypto.digests.SHA512Digest;
   5172 +// import org.bouncycastle.crypto.digests.TigerDigest;
   5173 +// END android-removed
   5174 +// BEGIN android-added
   5175 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   5176 +// END android-added
   5177  import org.bouncycastle.crypto.engines.DESEngine;
   5178  import org.bouncycastle.crypto.engines.RC2Engine;
   5179  import org.bouncycastle.crypto.macs.CBCBlockCipherMac;
   5180 -import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   5181 -import org.bouncycastle.crypto.macs.GOST28147Mac;
   5182 +// BEGIN android-removed
   5183 +// import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   5184 +// import org.bouncycastle.crypto.macs.GOST28147Mac;
   5185 +// END android-removed
   5186  import org.bouncycastle.crypto.macs.HMac;
   5187 -import org.bouncycastle.crypto.macs.ISO9797Alg3Mac;
   5188 -import org.bouncycastle.crypto.macs.OldHMac;
   5189 +// BEGIN android-removed
   5190 +// import org.bouncycastle.crypto.macs.ISO9797Alg3Mac;
   5191 +// import org.bouncycastle.crypto.macs.OldHMac;
   5192 +// END android-removed
   5193  import org.bouncycastle.crypto.paddings.ISO7816d4Padding;
   5194  import org.bouncycastle.crypto.params.KeyParameter;
   5195  import org.bouncycastle.crypto.params.ParametersWithIV;
   5196 @@ -179,91 +188,93 @@
   5197          }
   5198      }
   5199  
   5200 -    /**
   5201 -     * GOST28147
   5202 -     */
   5203 -    public static class GOST28147
   5204 -        extends BaseMac
   5205 -    {
   5206 -        public GOST28147()
   5207 -        {
   5208 -            super(new GOST28147Mac());
   5209 -        }
   5210 -    }
   5211 -
   5212 -    
   5213 -
   5214 -    /**
   5215 -     * DES
   5216 -     */
   5217 -    public static class DESCFB8
   5218 -        extends BaseMac
   5219 -    {
   5220 -        public DESCFB8()
   5221 -        {
   5222 -            super(new CFBBlockCipherMac(new DESEngine()));
   5223 -        }
   5224 -    }
   5225 -
   5226 -    /**
   5227 -     * RC2CFB8
   5228 -     */
   5229 -    public static class RC2CFB8
   5230 -        extends BaseMac
   5231 -    {
   5232 -        public RC2CFB8()
   5233 -        {
   5234 -            super(new CFBBlockCipherMac(new RC2Engine()));
   5235 -        }
   5236 -    }
   5237 -
   5238 -    /**
   5239 -     * DES9797Alg3with7816-4Padding
   5240 -     */
   5241 -    public static class DES9797Alg3with7816d4
   5242 -        extends BaseMac
   5243 -    {
   5244 -        public DES9797Alg3with7816d4()
   5245 -        {
   5246 -            super(new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()));
   5247 -        }
   5248 -    }
   5249 -
   5250 -    /**
   5251 -     * DES9797Alg3
   5252 -     */
   5253 -    public static class DES9797Alg3
   5254 -        extends BaseMac
   5255 -    {
   5256 -        public DES9797Alg3()
   5257 -        {
   5258 -            super(new ISO9797Alg3Mac(new DESEngine()));
   5259 -        }
   5260 -    }
   5261 -
   5262 -    /**
   5263 -     * MD2 HMac
   5264 -     */
   5265 -    public static class MD2
   5266 -        extends BaseMac
   5267 -    {
   5268 -        public MD2()
   5269 -        {
   5270 -            super(new HMac(new MD2Digest()));
   5271 -        }
   5272 -    }
   5273 -
   5274 -    /**
   5275 -     * MD4 HMac
   5276 -     */
   5277 -    public static class MD4
   5278 -        extends BaseMac
   5279 -    {
   5280 -        public MD4()
   5281 -        {
   5282 -            super(new HMac(new MD4Digest()));
   5283 -        }
   5284 -    }
   5285 +    // BEGIN android-removed
   5286 +    // /**
   5287 +    //  * GOST28147
   5288 +    //  */
   5289 +    // public static class GOST28147
   5290 +    //     extends BaseMac
   5291 +    // {
   5292 +    //     public GOST28147()
   5293 +    //     {
   5294 +    //         super(new GOST28147Mac());
   5295 +    //     }
   5296 +    // }
   5297 +    //
   5298 +    //
   5299 +    //
   5300 +    // /**
   5301 +    //  * DES
   5302 +    //  */
   5303 +    // public static class DESCFB8
   5304 +    //     extends BaseMac
   5305 +    // {
   5306 +    //     public DESCFB8()
   5307 +    //     {
   5308 +    //         super(new CFBBlockCipherMac(new DESEngine()));
   5309 +    //     }
   5310 +    // }
   5311 +    //
   5312 +    // /**
   5313 +    //  * RC2CFB8
   5314 +    //  */
   5315 +    // public static class RC2CFB8
   5316 +    //     extends BaseMac
   5317 +    // {
   5318 +    //     public RC2CFB8()
   5319 +    //     {
   5320 +    //         super(new CFBBlockCipherMac(new RC2Engine()));
   5321 +    //     }
   5322 +    // }
   5323 +    //
   5324 +    // /**
   5325 +    //  * DES9797Alg3with7816-4Padding
   5326 +    //  */
   5327 +    // public static class DES9797Alg3with7816d4
   5328 +    //     extends BaseMac
   5329 +    // {
   5330 +    //     public DES9797Alg3with7816d4()
   5331 +    //     {
   5332 +    //         super(new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()));
   5333 +    //     }
   5334 +    // }
   5335 +    //
   5336 +    // /**
   5337 +    //  * DES9797Alg3
   5338 +    //  */
   5339 +    // public static class DES9797Alg3
   5340 +    //     extends BaseMac
   5341 +    // {
   5342 +    //     public DES9797Alg3()
   5343 +    //     {
   5344 +    //         super(new ISO9797Alg3Mac(new DESEngine()));
   5345 +    //     }
   5346 +    // }
   5347 +    //
   5348 +    // /**
   5349 +    //  * MD2 HMac
   5350 +    //  */
   5351 +    // public static class MD2
   5352 +    //     extends BaseMac
   5353 +    // {
   5354 +    //     public MD2()
   5355 +    //     {
   5356 +    //         super(new HMac(new MD2Digest()));
   5357 +    //     }
   5358 +    // }
   5359 +    //
   5360 +    // /**
   5361 +    //  * MD4 HMac
   5362 +    //  */
   5363 +    // public static class MD4
   5364 +    //     extends BaseMac
   5365 +    // {
   5366 +    //     public MD4()
   5367 +    //     {
   5368 +    //         super(new HMac(new MD4Digest()));
   5369 +    //     }
   5370 +    // }
   5371 +    // END android-removed
   5372  
   5373      /**
   5374       * MD5 HMac
   5375 @@ -273,7 +284,9 @@
   5376      {
   5377          public MD5()
   5378          {
   5379 -            super(new HMac(new MD5Digest()));
   5380 +            // BEGIN android-changed
   5381 +            super(new HMac(AndroidDigestFactory.getMD5()));
   5382 +            // END android-changed
   5383          }
   5384      }
   5385  
   5386 @@ -285,21 +298,25 @@
   5387      {
   5388          public SHA1()
   5389          {
   5390 -            super(new HMac(new SHA1Digest()));
   5391 +            // BEGIN android-changed
   5392 +            super(new HMac(AndroidDigestFactory.getSHA1()));
   5393 +            // END android-changed
   5394          }
   5395      }
   5396  
   5397 -    /**
   5398 -     * SHA-224 HMac
   5399 -     */
   5400 -    public static class SHA224
   5401 -        extends BaseMac
   5402 -    {
   5403 -        public SHA224()
   5404 -        {
   5405 -            super(new HMac(new SHA224Digest()));
   5406 -        }
   5407 -    }
   5408 +    // BEGIN android-removed
   5409 +    // /**
   5410 +    //  * SHA-224 HMac
   5411 +    //  */
   5412 +    // public static class SHA224
   5413 +    //     extends BaseMac
   5414 +    // {
   5415 +    //     public SHA224()
   5416 +    //     {
   5417 +    //         super(new HMac(new SHA224Digest()));
   5418 +    //     }
   5419 +    // }
   5420 +    // END android-removed
   5421      
   5422      /**
   5423       * SHA-256 HMac
   5424 @@ -309,7 +326,7 @@
   5425      {
   5426          public SHA256()
   5427          {
   5428 -            super(new HMac(new SHA256Digest()));
   5429 +            super(new HMac(AndroidDigestFactory.getSHA256()));
   5430          }
   5431      }
   5432  
   5433 @@ -321,18 +338,20 @@
   5434      {
   5435          public SHA384()
   5436          {
   5437 -            super(new HMac(new SHA384Digest()));
   5438 +            super(new HMac(AndroidDigestFactory.getSHA384()));
   5439          }
   5440      }
   5441  
   5442 -    public static class OldSHA384
   5443 -        extends BaseMac
   5444 -    {
   5445 -        public OldSHA384()
   5446 -        {
   5447 -            super(new OldHMac(new SHA384Digest()));
   5448 -        }
   5449 -    }
   5450 +    // BEGIN android-removed
   5451 +    // public static class OldSHA384
   5452 +    //     extends BaseMac
   5453 +    // {
   5454 +    //     public OldSHA384()
   5455 +    //     {
   5456 +    //         super(new OldHMac(new SHA384Digest()));
   5457 +    //     }
   5458 +    // }
   5459 +    // END android-removed
   5460      
   5461      /**
   5462       * SHA-512 HMac
   5463 @@ -342,75 +361,77 @@
   5464      {
   5465          public SHA512()
   5466          {
   5467 -            super(new HMac(new SHA512Digest()));
   5468 -        }
   5469 -    }
   5470 -
   5471 -    /**
   5472 -     * SHA-512 HMac
   5473 -     */
   5474 -    public static class OldSHA512
   5475 -        extends BaseMac
   5476 -    {
   5477 -        public OldSHA512()
   5478 -        {
   5479 -            super(new OldHMac(new SHA512Digest()));
   5480 -        }
   5481 -    }
   5482 -    
   5483 -    /**
   5484 -     * RIPEMD128 HMac
   5485 -     */
   5486 -    public static class RIPEMD128
   5487 -        extends BaseMac
   5488 -    {
   5489 -        public RIPEMD128()
   5490 -        {
   5491 -            super(new HMac(new RIPEMD128Digest()));
   5492 -        }
   5493 -    }
   5494 -
   5495 -    /**
   5496 -     * RIPEMD160 HMac
   5497 -     */
   5498 -    public static class RIPEMD160
   5499 -        extends BaseMac
   5500 -    {
   5501 -        public RIPEMD160()
   5502 -        {
   5503 -            super(new HMac(new RIPEMD160Digest()));
   5504 -        }
   5505 -    }
   5506 -
   5507 -    /**
   5508 -     * Tiger HMac
   5509 -     */
   5510 -    public static class Tiger
   5511 -        extends BaseMac
   5512 -    {
   5513 -        public Tiger()
   5514 -        {
   5515 -            super(new HMac(new TigerDigest()));
   5516 +            super(new HMac(AndroidDigestFactory.getSHA512()));
   5517          }
   5518      }
   5519  
   5520 +    // BEGIN android-removed
   5521 +    // /**
   5522 +    //  * SHA-512 HMac
   5523 +    //  */
   5524 +    // public static class OldSHA512
   5525 +    //     extends BaseMac
   5526 +    // {
   5527 +    //     public OldSHA512()
   5528 +    //     {
   5529 +    //         super(new OldHMac(new SHA512Digest()));
   5530 +    //     }
   5531 +    // }
   5532 +    //    
   5533 +    // /**
   5534 +    //  * RIPEMD128 HMac
   5535 +    //  */
   5536 +    // public static class RIPEMD128
   5537 +    //     extends BaseMac
   5538 +    // {
   5539 +    //     public RIPEMD128()
   5540 +    //     {
   5541 +    //         super(new HMac(new RIPEMD128Digest()));
   5542 +    //     }
   5543 +    // }
   5544      //
   5545 -    // PKCS12 states that the same algorithm should be used
   5546 -    // for the key generation as is used in the HMAC, so that
   5547 -    // is what we do here.
   5548 +    // /**
   5549 +    //  * RIPEMD160 HMac
   5550 +    //  */
   5551 +    // public static class RIPEMD160
   5552 +    //     extends BaseMac
   5553 +    // {
   5554 +    //     public RIPEMD160()
   5555 +    //     {
   5556 +    //         super(new HMac(new RIPEMD160Digest()));
   5557 +    //     }
   5558 +    // }
   5559      //
   5560 -
   5561 -    /**
   5562 -     * PBEWithHmacRIPEMD160
   5563 -     */
   5564 -    public static class PBEWithRIPEMD160
   5565 -        extends BaseMac
   5566 -    {
   5567 -        public PBEWithRIPEMD160()
   5568 -        {
   5569 -            super(new HMac(new RIPEMD160Digest()), PKCS12, RIPEMD160, 160);
   5570 -        }
   5571 -    }
   5572 +    // /**
   5573 +    //  * Tiger HMac
   5574 +    //  */
   5575 +    // public static class Tiger
   5576 +    //     extends BaseMac
   5577 +    // {
   5578 +    //     public Tiger()
   5579 +    //     {
   5580 +    //         super(new HMac(new TigerDigest()));
   5581 +    //     }
   5582 +    // }
   5583 +    //
   5584 +    // //
   5585 +    // // PKCS12 states that the same algorithm should be used
   5586 +    // // for the key generation as is used in the HMAC, so that
   5587 +    // // is what we do here.
   5588 +    // //
   5589 +    //
   5590 +    // /**
   5591 +    //  * PBEWithHmacRIPEMD160
   5592 +    //  */
   5593 +    // public static class PBEWithRIPEMD160
   5594 +    //     extends BaseMac
   5595 +    // {
   5596 +    //     public PBEWithRIPEMD160()
   5597 +    //     {
   5598 +    //         super(new HMac(new RIPEMD160Digest()), PKCS12, RIPEMD160, 160);
   5599 +    //     }
   5600 +    // }
   5601 +    // END android-removed
   5602  
   5603      /**
   5604       * PBEWithHmacSHA
   5605 @@ -420,19 +441,23 @@
   5606      {
   5607          public PBEWithSHA()
   5608          {
   5609 -            super(new HMac(new SHA1Digest()), PKCS12, SHA1, 160);
   5610 +            // BEGIN android-changed
   5611 +            super(new HMac(AndroidDigestFactory.getSHA1()), PKCS12, SHA1, 160);
   5612 +            // END android-changed
   5613          }
   5614      }
   5615  
   5616 -    /**
   5617 -     * PBEWithHmacTiger
   5618 -     */
   5619 -    public static class PBEWithTiger
   5620 -        extends BaseMac
   5621 -    {
   5622 -        public PBEWithTiger()
   5623 -        {
   5624 -            super(new HMac(new TigerDigest()), PKCS12, TIGER, 192);
   5625 -        }
   5626 -    }
   5627 +    // BEGIN android-removed
   5628 +    // /**
   5629 +    //  * PBEWithHmacTiger
   5630 +    //  */
   5631 +    // public static class PBEWithTiger
   5632 +    //     extends BaseMac
   5633 +    // {
   5634 +    //     public PBEWithTiger()
   5635 +    //     {
   5636 +    //         super(new HMac(new TigerDigest()), PKCS12, TIGER, 192);
   5637 +    //     }
   5638 +    // }
   5639 +    // END android-removed
   5640  }
   5641 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseStreamCipher.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseStreamCipher.java
   5642 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseStreamCipher.java	2012-03-22 15:11:48.000000000 +0000
   5643 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseStreamCipher.java	2012-09-19 21:17:12.000000000 +0000
   5644 @@ -13,8 +13,10 @@
   5645  import javax.crypto.ShortBufferException;
   5646  import javax.crypto.spec.IvParameterSpec;
   5647  import javax.crypto.spec.PBEParameterSpec;
   5648 -import javax.crypto.spec.RC2ParameterSpec;
   5649 -import javax.crypto.spec.RC5ParameterSpec;
   5650 +// BEGIN android-removed
   5651 +// import javax.crypto.spec.RC2ParameterSpec;
   5652 +// import javax.crypto.spec.RC5ParameterSpec;
   5653 +// END android-removed
   5654  
   5655  import org.bouncycastle.crypto.BlockCipher;
   5656  import org.bouncycastle.crypto.CipherParameters;
   5657 @@ -34,8 +36,10 @@
   5658      //
   5659      private Class[]                 availableSpecs =
   5660                                      {
   5661 -                                        RC2ParameterSpec.class,
   5662 -                                        RC5ParameterSpec.class,
   5663 +                                        // BEGIN android-removed
   5664 +                                        // RC2ParameterSpec.class,
   5665 +                                        // RC5ParameterSpec.class,
   5666 +                                        // END android-removed
   5667                                          IvParameterSpec.class,
   5668                                          PBEParameterSpec.class
   5669                                      };
   5670 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseWrapCipher.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseWrapCipher.java
   5671 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/BaseWrapCipher.java	2012-03-22 15:11:48.000000000 +0000
   5672 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/BaseWrapCipher.java	2012-09-19 21:17:12.000000000 +0000
   5673 @@ -22,8 +22,10 @@
   5674  import javax.crypto.ShortBufferException;
   5675  import javax.crypto.spec.IvParameterSpec;
   5676  import javax.crypto.spec.PBEParameterSpec;
   5677 -import javax.crypto.spec.RC2ParameterSpec;
   5678 -import javax.crypto.spec.RC5ParameterSpec;
   5679 +// BEGIN android-removed
   5680 +// import javax.crypto.spec.RC2ParameterSpec;
   5681 +// import javax.crypto.spec.RC5ParameterSpec;
   5682 +// END android-removed
   5683  import javax.crypto.spec.SecretKeySpec;
   5684  
   5685  import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
   5686 @@ -45,8 +47,10 @@
   5687                                      {
   5688                                          IvParameterSpec.class,
   5689                                          PBEParameterSpec.class,
   5690 -                                        RC2ParameterSpec.class,
   5691 -                                        RC5ParameterSpec.class
   5692 +                                        // BEGIN android-removed
   5693 +                                        // RC2ParameterSpec.class,
   5694 +                                        // RC5ParameterSpec.class
   5695 +                                        // END android-removed
   5696                                      };
   5697  
   5698      protected int                     pbeType = PKCS12;
   5699 @@ -258,16 +262,19 @@
   5700          return null;
   5701      }
   5702  
   5703 +    // BEGIN android-changed
   5704 +    // added ShortBufferException to throws statement
   5705      protected int engineDoFinal(
   5706          byte[]  input,
   5707          int     inputOffset,
   5708          int     inputLen,
   5709          byte[]  output,
   5710          int     outputOffset)
   5711 -        throws IllegalBlockSizeException, BadPaddingException
   5712 +        throws IllegalBlockSizeException, BadPaddingException, ShortBufferException
   5713      {
   5714          return 0;
   5715      }
   5716 +    // END android-changed
   5717  
   5718      protected byte[] engineWrap(
   5719          Key     key)
   5720 @@ -300,7 +307,12 @@
   5721          byte[]  wrappedKey,
   5722          String  wrappedKeyAlgorithm,
   5723          int     wrappedKeyType)
   5724 -    throws InvalidKeyException
   5725 +    // BEGIN android-removed
   5726 +    // throws InvalidKeyException
   5727 +    // END android-removed
   5728 +    // BEGIN android-added
   5729 +    throws InvalidKeyException, NoSuchAlgorithmException
   5730 +    // END android-added
   5731      {
   5732          byte[] encoded;
   5733          try
   5734 @@ -376,10 +388,12 @@
   5735              {
   5736                  throw new InvalidKeyException("Unknown key type " + e.getMessage());
   5737              }
   5738 -            catch (NoSuchAlgorithmException e)
   5739 -            {
   5740 -                throw new InvalidKeyException("Unknown key type " + e.getMessage());
   5741 -            }
   5742 +            // BEGIN android-removed
   5743 +            // catch (NoSuchAlgorithmException e)
   5744 +            // {
   5745 +            //     throw new InvalidKeyException("Unknown key type " + e.getMessage());
   5746 +            // }
   5747 +            // END android-removed
   5748              catch (InvalidKeySpecException e2)
   5749              {
   5750                  throw new InvalidKeyException("Unknown key type " + e2.getMessage());
   5751 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/PBE.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/PBE.java
   5752 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/symmetric/util/PBE.java	2012-03-22 15:11:48.000000000 +0000
   5753 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/symmetric/util/PBE.java	2012-09-19 21:17:12.000000000 +0000
   5754 @@ -7,12 +7,17 @@
   5755  
   5756  import org.bouncycastle.crypto.CipherParameters;
   5757  import org.bouncycastle.crypto.PBEParametersGenerator;
   5758 -import org.bouncycastle.crypto.digests.MD2Digest;
   5759 -import org.bouncycastle.crypto.digests.MD5Digest;
   5760 -import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   5761 -import org.bouncycastle.crypto.digests.SHA1Digest;
   5762 -import org.bouncycastle.crypto.digests.SHA256Digest;
   5763 -import org.bouncycastle.crypto.digests.TigerDigest;
   5764 +// BEGIN android-removed
   5765 +// import org.bouncycastle.crypto.digests.MD2Digest;
   5766 +// import org.bouncycastle.crypto.digests.MD5Digest;
   5767 +// import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   5768 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   5769 +// import org.bouncycastle.crypto.digests.SHA256Digest;
   5770 +// import org.bouncycastle.crypto.digests.TigerDigest;
   5771 +// END android-removed
   5772 +// BEGIN android-added
   5773 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   5774 +// END android-added
   5775  import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator;
   5776  import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
   5777  import org.bouncycastle.crypto.generators.PKCS5S1ParametersGenerator;
   5778 @@ -28,10 +33,14 @@
   5779      //
   5780      static final int        MD5         = 0;
   5781      static final int        SHA1        = 1;
   5782 -    static final int        RIPEMD160   = 2;
   5783 -    static final int        TIGER       = 3;
   5784 +    // BEGIN android-removed
   5785 +    // static final int        RIPEMD160   = 2;
   5786 +    // static final int        TIGER       = 3;
   5787 +    // END android-removed
   5788      static final int        SHA256      = 4;
   5789 -    static final int        MD2         = 5;
   5790 +    // BEGIN android-removed
   5791 +    // static final int        MD2         = 5;
   5792 +    // END android-removed
   5793  
   5794      static final int        PKCS5S1     = 0;
   5795      static final int        PKCS5S2     = 1;
   5796 @@ -53,14 +62,20 @@
   5797              {
   5798                  switch (hash)
   5799                  {
   5800 -                case MD2:
   5801 -                    generator = new PKCS5S1ParametersGenerator(new MD2Digest());
   5802 -                    break;
   5803 +                // BEGIN android-removed
   5804 +                // case MD2:
   5805 +                //     generator = new PKCS5S1ParametersGenerator(new MD2Digest());
   5806 +                //     break;
   5807 +                // END android-removed
   5808                  case MD5:
   5809 -                    generator = new PKCS5S1ParametersGenerator(new MD5Digest());
   5810 +                    // BEGIN android-changed
   5811 +                    generator = new PKCS5S1ParametersGenerator(AndroidDigestFactory.getMD5());
   5812 +                    // END android-changed
   5813                      break;
   5814                  case SHA1:
   5815 -                    generator = new PKCS5S1ParametersGenerator(new SHA1Digest());
   5816 +                    // BEGIN android-changed
   5817 +                    generator = new PKCS5S1ParametersGenerator(AndroidDigestFactory.getSHA1());
   5818 +                    // END android-changed
   5819                      break;
   5820                  default:
   5821                      throw new IllegalStateException("PKCS5 scheme 1 only supports MD2, MD5 and SHA1.");
   5822 @@ -74,23 +89,33 @@
   5823              {
   5824                  switch (hash)
   5825                  {
   5826 -                case MD2:
   5827 -                    generator = new PKCS12ParametersGenerator(new MD2Digest());
   5828 -                    break;
   5829 +                // BEGIN android-removed
   5830 +                // case MD2:
   5831 +                //     generator = new PKCS12ParametersGenerator(new MD2Digest());
   5832 +                //     break;
   5833 +                // END android-removed
   5834                  case MD5:
   5835 -                    generator = new PKCS12ParametersGenerator(new MD5Digest());
   5836 +                    // BEGIN android-changed
   5837 +                    generator = new PKCS12ParametersGenerator(AndroidDigestFactory.getMD5());
   5838 +                    // END android-changed
   5839                      break;
   5840                  case SHA1:
   5841 -                    generator = new PKCS12ParametersGenerator(new SHA1Digest());
   5842 -                    break;
   5843 -                case RIPEMD160:
   5844 -                    generator = new PKCS12ParametersGenerator(new RIPEMD160Digest());
   5845 -                    break;
   5846 -                case TIGER:
   5847 -                    generator = new PKCS12ParametersGenerator(new TigerDigest());
   5848 +                    // BEGIN android-changed
   5849 +                    generator = new PKCS12ParametersGenerator(AndroidDigestFactory.getSHA1());
   5850 +                    // END android-changed
   5851                      break;
   5852 +                // BEGIN android-removed
   5853 +                // case RIPEMD160:
   5854 +                //     generator = new PKCS12ParametersGenerator(new RIPEMD160Digest());
   5855 +                //     break;
   5856 +                // case TIGER:
   5857 +                //     generator = new PKCS12ParametersGenerator(new TigerDigest());
   5858 +                //     break;
   5859 +                // END android-removed
   5860                  case SHA256:
   5861 -                    generator = new PKCS12ParametersGenerator(new SHA256Digest());
   5862 +                    // BEGIN android-changed
   5863 +                    generator = new PKCS12ParametersGenerator(AndroidDigestFactory.getSHA256());
   5864 +                    // END android-changed
   5865                      break;
   5866                  default:
   5867                      throw new IllegalStateException("unknown digest scheme for PBE encryption.");
   5868 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/util/DigestFactory.java bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/util/DigestFactory.java
   5869 --- bcprov-jdk15on-147.orig/org/bouncycastle/jcajce/provider/util/DigestFactory.java	2012-03-22 15:11:48.000000000 +0000
   5870 +++ bcprov-jdk15on-147/org/bouncycastle/jcajce/provider/util/DigestFactory.java	2012-09-19 21:17:12.000000000 +0000
   5871 @@ -10,19 +10,26 @@
   5872  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   5873  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   5874  import org.bouncycastle.crypto.Digest;
   5875 -import org.bouncycastle.crypto.digests.MD5Digest;
   5876 -import org.bouncycastle.crypto.digests.SHA1Digest;
   5877 -import org.bouncycastle.crypto.digests.SHA224Digest;
   5878 -import org.bouncycastle.crypto.digests.SHA256Digest;
   5879 -import org.bouncycastle.crypto.digests.SHA384Digest;
   5880 -import org.bouncycastle.crypto.digests.SHA512Digest;
   5881 +// BEGIN android-removed
   5882 +// import org.bouncycastle.crypto.digests.MD5Digest;
   5883 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   5884 +// import org.bouncycastle.crypto.digests.SHA224Digest;
   5885 +// import org.bouncycastle.crypto.digests.SHA256Digest;
   5886 +// import org.bouncycastle.crypto.digests.SHA384Digest;
   5887 +// import org.bouncycastle.crypto.digests.SHA512Digest;
   5888 +// END android-removed
   5889 +// BEGIN android-added
   5890 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   5891 +// END android-added
   5892  import org.bouncycastle.util.Strings;
   5893  
   5894  public class DigestFactory
   5895  {
   5896      private static Set md5 = new HashSet();
   5897      private static Set sha1 = new HashSet();
   5898 -    private static Set sha224 = new HashSet();
   5899 +    // BEGIN android-removed
   5900 +    // private static Set sha224 = new HashSet();
   5901 +    // END android-removed
   5902      private static Set sha256 = new HashSet();
   5903      private static Set sha384 = new HashSet();
   5904      private static Set sha512 = new HashSet();
   5905 @@ -38,9 +45,11 @@
   5906          sha1.add("SHA-1");
   5907          sha1.add(OIWObjectIdentifiers.idSHA1.getId());
   5908          
   5909 -        sha224.add("SHA224");
   5910 -        sha224.add("SHA-224");
   5911 -        sha224.add(NISTObjectIdentifiers.id_sha224.getId());
   5912 +        // BEGIN android-removed
   5913 +        // sha224.add("SHA224");
   5914 +        // sha224.add("SHA-224");
   5915 +        // sha224.add(NISTObjectIdentifiers.id_sha224.getId());
   5916 +        // END android-removed
   5917          
   5918          sha256.add("SHA256");
   5919          sha256.add("SHA-256");
   5920 @@ -61,9 +70,11 @@
   5921          oids.put("SHA-1", OIWObjectIdentifiers.idSHA1);
   5922          oids.put(OIWObjectIdentifiers.idSHA1.getId(), OIWObjectIdentifiers.idSHA1);
   5923          
   5924 -        oids.put("SHA224", NISTObjectIdentifiers.id_sha224);
   5925 -        oids.put("SHA-224", NISTObjectIdentifiers.id_sha224);
   5926 -        oids.put(NISTObjectIdentifiers.id_sha224.getId(), NISTObjectIdentifiers.id_sha224);
   5927 +        // BEGIN android-removed
   5928 +        // oids.put("SHA224", NISTObjectIdentifiers.id_sha224);
   5929 +        // oids.put("SHA-224", NISTObjectIdentifiers.id_sha224);
   5930 +        // oids.put(NISTObjectIdentifiers.id_sha224.getId(), NISTObjectIdentifiers.id_sha224);
   5931 +        // END android-removed
   5932          
   5933          oids.put("SHA256", NISTObjectIdentifiers.id_sha256);
   5934          oids.put("SHA-256", NISTObjectIdentifiers.id_sha256);
   5935 @@ -85,27 +96,39 @@
   5936          
   5937          if (sha1.contains(digestName))
   5938          {
   5939 -            return new SHA1Digest();
   5940 +            // BEGIN android-changed
   5941 +            return AndroidDigestFactory.getSHA1();
   5942 +            // END android-changed
   5943          }
   5944          if (md5.contains(digestName))
   5945          {
   5946 -            return new MD5Digest();
   5947 -        }
   5948 -        if (sha224.contains(digestName))
   5949 -        {
   5950 -            return new SHA224Digest();
   5951 -        }
   5952 +            // BEGIN android-changed
   5953 +            return AndroidDigestFactory.getMD5();
   5954 +            // END android-changed
   5955 +        }
   5956 +        // BEGIN android-removed
   5957 +        // if (sha224.contains(digestName))
   5958 +        // {
   5959 +        //     return new SHA224Digest();
   5960 +        // }
   5961 +        // END android-removed
   5962          if (sha256.contains(digestName))
   5963          {
   5964 -            return new SHA256Digest();
   5965 +            // BEGIN android-changed
   5966 +            return AndroidDigestFactory.getSHA256();
   5967 +            // END android-changed
   5968          }
   5969          if (sha384.contains(digestName))
   5970          {
   5971 -            return new SHA384Digest();
   5972 +            // BEGIN android-changed
   5973 +            return AndroidDigestFactory.getSHA384();
   5974 +            // END android-changed
   5975          }
   5976          if (sha512.contains(digestName))
   5977          {
   5978 -            return new SHA512Digest();
   5979 +            // BEGIN android-changed
   5980 +            return AndroidDigestFactory.getSHA512();
   5981 +            // END android-changed
   5982          }
   5983          
   5984          return null;
   5985 @@ -116,7 +139,9 @@
   5986          String digest2)
   5987      {
   5988          return (sha1.contains(digest1) && sha1.contains(digest2))
   5989 -            || (sha224.contains(digest1) && sha224.contains(digest2))
   5990 +            // BEGIN android-removed
   5991 +            // || (sha224.contains(digest1) && sha224.contains(digest2))
   5992 +            // END android-removed
   5993              || (sha256.contains(digest1) && sha256.contains(digest2))
   5994              || (sha384.contains(digest1) && sha384.contains(digest2))
   5995              || (sha512.contains(digest1) && sha512.contains(digest2))
   5996 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/ECNamedCurveTable.java bcprov-jdk15on-147/org/bouncycastle/jce/ECNamedCurveTable.java
   5997 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/ECNamedCurveTable.java	2012-03-22 15:11:48.000000000 +0000
   5998 +++ bcprov-jdk15on-147/org/bouncycastle/jce/ECNamedCurveTable.java	2012-09-19 21:17:12.000000000 +0000
   5999 @@ -6,7 +6,9 @@
   6000  import org.bouncycastle.asn1.ASN1ObjectIdentifier;
   6001  import org.bouncycastle.asn1.nist.NISTNamedCurves;
   6002  import org.bouncycastle.asn1.sec.SECNamedCurves;
   6003 -import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   6004 +// BEGIN android-removed
   6005 +// import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
   6006 +// END android-removed
   6007  import org.bouncycastle.asn1.x9.X962NamedCurves;
   6008  import org.bouncycastle.asn1.x9.X9ECParameters;
   6009  import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
   6010 @@ -55,21 +57,23 @@
   6011              }
   6012          }
   6013  
   6014 -        if (ecP == null)
   6015 -        {
   6016 -            ecP = TeleTrusTNamedCurves.getByName(name);
   6017 -            if (ecP == null)
   6018 -            {
   6019 -                try
   6020 -                {
   6021 -                    ecP = TeleTrusTNamedCurves.getByOID(new ASN1ObjectIdentifier(name));
   6022 -                }
   6023 -                catch (IllegalArgumentException e)
   6024 -                {
   6025 -                    // ignore - not an oid
   6026 -                }
   6027 -            }
   6028 -        }
   6029 +        // BEGIN android-removed
   6030 +        // if (ecP == null)
   6031 +        // {
   6032 +        //     ecP = TeleTrusTNamedCurves.getByName(name);
   6033 +        //     if (ecP == null)
   6034 +        //     {
   6035 +        //         try
   6036 +        //         {
   6037 +        //             ecP = TeleTrusTNamedCurves.getByOID(new ASN1ObjectIdentifier(name));
   6038 +        //         }
   6039 +        //         catch (IllegalArgumentException e)
   6040 +        //         {
   6041 +        //             // ignore - not an oid
   6042 +        //         }
   6043 +        //     }
   6044 +        // }
   6045 +        // END android-removed
   6046  
   6047          if (ecP == null)
   6048          {
   6049 @@ -102,7 +106,9 @@
   6050          addEnumeration(v, X962NamedCurves.getNames());
   6051          addEnumeration(v, SECNamedCurves.getNames());
   6052          addEnumeration(v, NISTNamedCurves.getNames());
   6053 -        addEnumeration(v, TeleTrusTNamedCurves.getNames());
   6054 +        // BEGIN android-removed
   6055 +        // addEnumeration(v, TeleTrusTNamedCurves.getNames());
   6056 +        // END android-removed
   6057  
   6058          return v.elements();
   6059      }
   6060 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/PKCS10CertificationRequest.java bcprov-jdk15on-147/org/bouncycastle/jce/PKCS10CertificationRequest.java
   6061 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/PKCS10CertificationRequest.java	2012-03-22 15:11:48.000000000 +0000
   6062 +++ bcprov-jdk15on-147/org/bouncycastle/jce/PKCS10CertificationRequest.java	2012-09-19 21:17:12.000000000 +0000
   6063 @@ -30,14 +30,18 @@
   6064  import org.bouncycastle.asn1.DERBitString;
   6065  import org.bouncycastle.asn1.DERNull;
   6066  import org.bouncycastle.asn1.DERObjectIdentifier;
   6067 -import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   6068 +// BEGIN android-removed
   6069 +// import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   6070 +// END android-removed
   6071  import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
   6072  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   6073  import org.bouncycastle.asn1.pkcs.CertificationRequest;
   6074  import org.bouncycastle.asn1.pkcs.CertificationRequestInfo;
   6075  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   6076  import org.bouncycastle.asn1.pkcs.RSASSAPSSparams;
   6077 -import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   6078 +// BEGIN android-removed
   6079 +// import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   6080 +// END android-removed
   6081  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   6082  import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
   6083  import org.bouncycastle.asn1.x509.X509Name;
   6084 @@ -81,15 +85,20 @@
   6085  
   6086      static
   6087      {
   6088 -        algorithms.put("MD2WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.2"));
   6089 -        algorithms.put("MD2WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.2"));
   6090 +        // BEGIN android-removed
   6091 +        // Dropping MD2
   6092 +        // algorithms.put("MD2WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.2"));
   6093 +        // algorithms.put("MD2WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.2"));
   6094 +        // END android-removed
   6095          algorithms.put("MD5WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.4"));
   6096          algorithms.put("MD5WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.4"));
   6097          algorithms.put("RSAWITHMD5", new DERObjectIdentifier("1.2.840.113549.1.1.4"));
   6098          algorithms.put("SHA1WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.5"));
   6099          algorithms.put("SHA1WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.5"));
   6100 -        algorithms.put("SHA224WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   6101 -        algorithms.put("SHA224WITHRSA", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   6102 +        // BEGIN android-removed
   6103 +        // algorithms.put("SHA224WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   6104 +        // algorithms.put("SHA224WITHRSA", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   6105 +        // END android-removed
   6106          algorithms.put("SHA256WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha256WithRSAEncryption);
   6107          algorithms.put("SHA256WITHRSA", PKCSObjectIdentifiers.sha256WithRSAEncryption);
   6108          algorithms.put("SHA384WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha384WithRSAEncryption);
   6109 @@ -97,57 +106,78 @@
   6110          algorithms.put("SHA512WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha512WithRSAEncryption);
   6111          algorithms.put("SHA512WITHRSA", PKCSObjectIdentifiers.sha512WithRSAEncryption);
   6112          algorithms.put("SHA1WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   6113 -        algorithms.put("SHA224WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   6114 +        // BEGIN android-removed
   6115 +        // algorithms.put("SHA224WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   6116 +        // END android-removed
   6117          algorithms.put("SHA256WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   6118          algorithms.put("SHA384WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   6119          algorithms.put("SHA512WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   6120          algorithms.put("RSAWITHSHA1", new DERObjectIdentifier("1.2.840.113549.1.1.5"));
   6121 -        algorithms.put("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   6122 -        algorithms.put("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   6123 -        algorithms.put("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   6124 -        algorithms.put("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   6125 -        algorithms.put("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   6126 -        algorithms.put("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   6127 +        // BEGIN android-removed
   6128 +        // algorithms.put("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   6129 +        // algorithms.put("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   6130 +        // algorithms.put("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   6131 +        // algorithms.put("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   6132 +        // algorithms.put("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   6133 +        // algorithms.put("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   6134 +        // END android-removed
   6135          algorithms.put("SHA1WITHDSA", new DERObjectIdentifier("1.2.840.10040.4.3"));
   6136          algorithms.put("DSAWITHSHA1", new DERObjectIdentifier("1.2.840.10040.4.3"));
   6137 -        algorithms.put("SHA224WITHDSA", NISTObjectIdentifiers.dsa_with_sha224);
   6138 +        // BEGIN android-removed
   6139 +        // algorithms.put("SHA224WITHDSA", NISTObjectIdentifiers.dsa_with_sha224);
   6140 +        // END android-removed
   6141          algorithms.put("SHA256WITHDSA", NISTObjectIdentifiers.dsa_with_sha256);
   6142          algorithms.put("SHA384WITHDSA", NISTObjectIdentifiers.dsa_with_sha384);
   6143          algorithms.put("SHA512WITHDSA", NISTObjectIdentifiers.dsa_with_sha512);
   6144          algorithms.put("SHA1WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA1);
   6145 -        algorithms.put("SHA224WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA224);
   6146 +        // BEGIN android-removed
   6147 +        // algorithms.put("SHA224WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA224);
   6148 +        // END android-removed
   6149          algorithms.put("SHA256WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA256);
   6150          algorithms.put("SHA384WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA384);
   6151          algorithms.put("SHA512WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA512);
   6152          algorithms.put("ECDSAWITHSHA1", X9ObjectIdentifiers.ecdsa_with_SHA1);
   6153 -        algorithms.put("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   6154 -        algorithms.put("GOST3410WITHGOST3411", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   6155 -        algorithms.put("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6156 -        algorithms.put("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6157 -        algorithms.put("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6158 +        // BEGIN android-removed
   6159 +        // algorithms.put("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   6160 +        // algorithms.put("GOST3410WITHGOST3411", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   6161 +        // algorithms.put("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6162 +        // algorithms.put("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6163 +        // algorithms.put("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6164 +        // END android-removed
   6165  
   6166          //
   6167          // reverse mappings
   6168          //
   6169          oids.put(new DERObjectIdentifier("1.2.840.113549.1.1.5"), "SHA1WITHRSA");
   6170 -        oids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, "SHA224WITHRSA");
   6171 +        // BEGIN android-removed
   6172 +        // oids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, "SHA224WITHRSA");
   6173 +        // END android-removed
   6174          oids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, "SHA256WITHRSA");
   6175          oids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, "SHA384WITHRSA");
   6176          oids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, "SHA512WITHRSA");
   6177 -        oids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, "GOST3411WITHGOST3410");
   6178 -        oids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001, "GOST3411WITHECGOST3410");
   6179 +        // BEGIN android-removed
   6180 +        // oids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, "GOST3411WITHGOST3410");
   6181 +        // oids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001, "GOST3411WITHECGOST3410");
   6182 +        // END android-removed
   6183          
   6184          oids.put(new DERObjectIdentifier("1.2.840.113549.1.1.4"), "MD5WITHRSA");
   6185 -        oids.put(new DERObjectIdentifier("1.2.840.113549.1.1.2"), "MD2WITHRSA");
   6186 +        // BEGIN android-removed
   6187 +        // Dropping MD2
   6188 +        // oids.put(new DERObjectIdentifier("1.2.840.113549.1.1.2"), "MD2WITHRSA");
   6189 +        // END android-removed
   6190          oids.put(new DERObjectIdentifier("1.2.840.10040.4.3"), "SHA1WITHDSA");
   6191          oids.put(X9ObjectIdentifiers.ecdsa_with_SHA1, "SHA1WITHECDSA");
   6192 -        oids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, "SHA224WITHECDSA");
   6193 +        // BEGIN android-removed
   6194 +        // oids.put(X9ObjectIdentifiers.ecdsa_with_SHA224, "SHA224WITHECDSA");
   6195 +        // END android-removed
   6196          oids.put(X9ObjectIdentifiers.ecdsa_with_SHA256, "SHA256WITHECDSA");
   6197          oids.put(X9ObjectIdentifiers.ecdsa_with_SHA384, "SHA384WITHECDSA");
   6198          oids.put(X9ObjectIdentifiers.ecdsa_with_SHA512, "SHA512WITHECDSA");
   6199          oids.put(OIWObjectIdentifiers.sha1WithRSA, "SHA1WITHRSA");
   6200          oids.put(OIWObjectIdentifiers.dsaWithSHA1, "SHA1WITHDSA");
   6201 -        oids.put(NISTObjectIdentifiers.dsa_with_sha224, "SHA224WITHDSA");
   6202 +        // BEGIN android-removed
   6203 +        // oids.put(NISTObjectIdentifiers.dsa_with_sha224, "SHA224WITHDSA");
   6204 +        // END android-removed
   6205          oids.put(NISTObjectIdentifiers.dsa_with_sha256, "SHA256WITHDSA");
   6206          
   6207          //
   6208 @@ -161,35 +191,53 @@
   6209          // The parameters field SHALL be NULL for RSA based signature algorithms.
   6210          //
   6211          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA1);
   6212 -        noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA224);
   6213 +        // BEGIN android-removed
   6214 +        // noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA224);
   6215 +        // END android-removed
   6216          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA256);
   6217          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA384);
   6218          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA512);
   6219          noParams.add(X9ObjectIdentifiers.id_dsa_with_sha1);
   6220 -        noParams.add(NISTObjectIdentifiers.dsa_with_sha224);
   6221 +        // BEGIN android-removed
   6222 +        // noParams.add(NISTObjectIdentifiers.dsa_with_sha224);
   6223 +        // END android-removed
   6224          noParams.add(NISTObjectIdentifiers.dsa_with_sha256);
   6225  
   6226          //
   6227          // RFC 4491
   6228          //
   6229 -        noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   6230 -        noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6231 +        // BEGIN android-removed
   6232 +        // noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   6233 +        // noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   6234 +        // END android-removed
   6235          //
   6236          // explicit params
   6237          //
   6238 -        AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, new DERNull());
   6239 +        // BEGIN android-changed
   6240 +        AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
   6241 +        // END android-changed
   6242          params.put("SHA1WITHRSAANDMGF1", creatPSSParams(sha1AlgId, 20));
   6243  
   6244 -        AlgorithmIdentifier sha224AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha224, new DERNull());
   6245 -        params.put("SHA224WITHRSAANDMGF1", creatPSSParams(sha224AlgId, 28));
   6246 -
   6247 -        AlgorithmIdentifier sha256AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256, new DERNull());
   6248 +        // BEGIN android-removed
   6249 +        // // BEGIN android-changed
   6250 +        // AlgorithmIdentifier sha224AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha224, DERNull.INSTANCE);
   6251 +        // // END android-changed
   6252 +        // params.put("SHA224WITHRSAANDMGF1", creatPSSParams(sha224AlgId, 28));
   6253 +        // END android-removed
   6254 +
   6255 +        // BEGIN android-changed
   6256 +        AlgorithmIdentifier sha256AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256, DERNull.INSTANCE);
   6257 +        // END android-changed
   6258          params.put("SHA256WITHRSAANDMGF1", creatPSSParams(sha256AlgId, 32));
   6259  
   6260 -        AlgorithmIdentifier sha384AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha384, new DERNull());
   6261 +        // BEGIN android-changed
   6262 +        AlgorithmIdentifier sha384AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha384, DERNull.INSTANCE);
   6263 +        // END android-changed
   6264          params.put("SHA384WITHRSAANDMGF1", creatPSSParams(sha384AlgId, 48));
   6265  
   6266 -        AlgorithmIdentifier sha512AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha512, new DERNull());
   6267 +        // BEGIN android-changed
   6268 +        AlgorithmIdentifier sha512AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha512, DERNull.INSTANCE);
   6269 +        // END android-changed
   6270          params.put("SHA512WITHRSAANDMGF1", creatPSSParams(sha512AlgId, 64));
   6271      }
   6272  
   6273 @@ -595,10 +643,12 @@
   6274          {
   6275              return "SHA1";
   6276          }
   6277 -        else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID))
   6278 -        {
   6279 -            return "SHA224";
   6280 -        }
   6281 +        // BEGIN android-removed
   6282 +        // else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID))
   6283 +        // {
   6284 +        //     return "SHA224";
   6285 +        // }
   6286 +        // END android-removed
   6287          else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOID))
   6288          {
   6289              return "SHA256";
   6290 @@ -611,22 +661,24 @@
   6291          {
   6292              return "SHA512";
   6293          }
   6294 -        else if (TeleTrusTObjectIdentifiers.ripemd128.equals(digestAlgOID))
   6295 -        {
   6296 -            return "RIPEMD128";
   6297 -        }
   6298 -        else if (TeleTrusTObjectIdentifiers.ripemd160.equals(digestAlgOID))
   6299 -        {
   6300 -            return "RIPEMD160";
   6301 -        }
   6302 -        else if (TeleTrusTObjectIdentifiers.ripemd256.equals(digestAlgOID))
   6303 -        {
   6304 -            return "RIPEMD256";
   6305 -        }
   6306 -        else if (CryptoProObjectIdentifiers.gostR3411.equals(digestAlgOID))
   6307 -        {
   6308 -            return "GOST3411";
   6309 -        }
   6310 +        // BEGIN android-removed
   6311 +        // else if (TeleTrusTObjectIdentifiers.ripemd128.equals(digestAlgOID))
   6312 +        // {
   6313 +        //     return "RIPEMD128";
   6314 +        // }
   6315 +        // else if (TeleTrusTObjectIdentifiers.ripemd160.equals(digestAlgOID))
   6316 +        // {
   6317 +        //     return "RIPEMD160";
   6318 +        // }
   6319 +        // else if (TeleTrusTObjectIdentifiers.ripemd256.equals(digestAlgOID))
   6320 +        // {
   6321 +        //     return "RIPEMD256";
   6322 +        // }
   6323 +        // else if (CryptoProObjectIdentifiers.gostR3411.equals(digestAlgOID))
   6324 +        // {
   6325 +        //     return "GOST3411";
   6326 +        // }
   6327 +        // END android-removed
   6328          else
   6329          {
   6330              return digestAlgOID.getId();            
   6331 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/BouncyCastleProvider.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/BouncyCastleProvider.java
   6332 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/BouncyCastleProvider.java	2012-03-22 15:11:48.000000000 +0000
   6333 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/BouncyCastleProvider.java	2012-09-19 21:17:12.000000000 +0000
   6334 @@ -48,7 +48,10 @@
   6335  {
   6336      private static String info = "BouncyCastle Security Provider v1.47";
   6337  
   6338 -    public static String PROVIDER_NAME = "BC";
   6339 +    // BEGIN android-changed
   6340 +    //     this constant should be final
   6341 +    public static final String PROVIDER_NAME = "BC";
   6342 +    // END android-changed
   6343  
   6344      public static final ProviderConfiguration CONFIGURATION = new BouncyCastleProviderConfiguration();
   6345  
   6346 @@ -61,8 +64,13 @@
   6347      private static final String SYMMETRIC_CIPHER_PACKAGE = "org.bouncycastle.jcajce.provider.symmetric.";
   6348      private static final String[] SYMMETRIC_CIPHERS =
   6349      {
   6350 -        "AES", "ARC4", "Blowfish", "Camellia", "CAST5", "CAST6", "DES", "DESede", "GOST28147", "Grainv1", "Grain128", "HC128", "HC256", "IDEA",
   6351 -        "Noekeon", "RC2", "RC5", "RC6", "Rijndael", "Salsa20", "SEED", "Serpent", "Skipjack", "TEA", "Twofish", "VMPC", "VMPCKSA3", "XTEA"
   6352 +        // BEGIN android-removed
   6353 +        // "AES", "ARC4", "Blowfish", "Camellia", "CAST5", "CAST6", "DES", "DESede", "GOST28147", "Grainv1", "Grain128", "HC128", "HC256", "IDEA",
   6354 +        // "Noekeon", "RC2", "RC5", "RC6", "Rijndael", "Salsa20", "SEED", "Serpent", "Skipjack", "TEA", "Twofish", "VMPC", "VMPCKSA3", "XTEA"
   6355 +        // END android-removed
   6356 +        // BEGIN android-added
   6357 +        "AES", "ARC4", "Blowfish", "DES", "DESede",
   6358 +        // END android-added
   6359      };
   6360  
   6361       /*
   6362 @@ -79,7 +87,12 @@
   6363  
   6364      private static final String[] ASYMMETRIC_CIPHERS =
   6365      {
   6366 -        "DSA", "DH", "EC", "RSA", "GOST", "ECGOST", "ElGamal"
   6367 +        // BEGIN android-removed
   6368 +        // "DSA", "DH", "EC", "RSA", "GOST", "ECGOST", "ElGamal"
   6369 +        // END android-removed
   6370 +        // BEGIN android-added
   6371 +        "DSA", "DH", "EC", "RSA",
   6372 +        // END android-added
   6373      };
   6374  
   6375      /*
   6376 @@ -88,7 +101,12 @@
   6377      private static final String DIGEST_PACKAGE = "org.bouncycastle.jcajce.provider.digest.";
   6378      private static final String[] DIGESTS =
   6379      {
   6380 -        "GOST3411", "MD2", "MD4", "MD5", "SHA1", "RIPEMD128", "RIPEMD160", "RIPEMD256", "RIPEMD320", "SHA224", "SHA256", "SHA384", "SHA512", "Tiger", "Whirlpool"
   6381 +        // BEGIN android-removed
   6382 +        // "GOST3411", "MD2", "MD4", "MD5", "SHA1", "RIPEMD128", "RIPEMD160", "RIPEMD256", "RIPEMD320", "SHA224", "SHA256", "SHA384", "SHA512", "Tiger", "Whirlpool"
   6383 +        // END android-removed
   6384 +        // BEGIN android-added
   6385 +        "MD5", "SHA1", "SHA256", "SHA384", "SHA512",
   6386 +        // END android-added
   6387      };
   6388  
   6389      /**
   6390 @@ -120,26 +138,28 @@
   6391  
   6392          loadAlgorithms(ASYMMETRIC_CIPHER_PACKAGE, ASYMMETRIC_CIPHERS);
   6393  
   6394 -        //
   6395 -        // X509Store
   6396 -        //
   6397 -        put("X509Store.CERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertCollection");
   6398 -        put("X509Store.ATTRIBUTECERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreAttrCertCollection");
   6399 -        put("X509Store.CRL/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCRLCollection");
   6400 -        put("X509Store.CERTIFICATEPAIR/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertPairCollection");
   6401 -
   6402 -        put("X509Store.CERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCerts");
   6403 -        put("X509Store.CRL/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCRLs");
   6404 -        put("X509Store.ATTRIBUTECERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPAttrCerts");
   6405 -        put("X509Store.CERTIFICATEPAIR/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCertPairs");
   6406 -        
   6407 -        //
   6408 -        // X509StreamParser
   6409 -        //
   6410 -        put("X509StreamParser.CERTIFICATE", "org.bouncycastle.jce.provider.X509CertParser");
   6411 -        put("X509StreamParser.ATTRIBUTECERTIFICATE", "org.bouncycastle.jce.provider.X509AttrCertParser");
   6412 -        put("X509StreamParser.CRL", "org.bouncycastle.jce.provider.X509CRLParser");
   6413 -        put("X509StreamParser.CERTIFICATEPAIR", "org.bouncycastle.jce.provider.X509CertPairParser");
   6414 +        // BEGIN android-removed
   6415 +        // //
   6416 +        // // X509Store
   6417 +        // //
   6418 +        // put("X509Store.CERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertCollection");
   6419 +        // put("X509Store.ATTRIBUTECERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreAttrCertCollection");
   6420 +        // put("X509Store.CRL/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCRLCollection");
   6421 +        // put("X509Store.CERTIFICATEPAIR/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertPairCollection");
   6422 +        //
   6423 +        // put("X509Store.CERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCerts");
   6424 +        // put("X509Store.CRL/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCRLs");
   6425 +        // put("X509Store.ATTRIBUTECERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPAttrCerts");
   6426 +        // put("X509Store.CERTIFICATEPAIR/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCertPairs");
   6427 +        //
   6428 +        // //
   6429 +        // // X509StreamParser
   6430 +        // //
   6431 +        // put("X509StreamParser.CERTIFICATE", "org.bouncycastle.jce.provider.X509CertParser");
   6432 +        // put("X509StreamParser.ATTRIBUTECERTIFICATE", "org.bouncycastle.jce.provider.X509AttrCertParser");
   6433 +        // put("X509StreamParser.CRL", "org.bouncycastle.jce.provider.X509CRLParser");
   6434 +        // put("X509StreamParser.CERTIFICATEPAIR", "org.bouncycastle.jce.provider.X509CertPairParser");
   6435 +        // END android-removed
   6436  
   6437  
   6438          //
   6439 @@ -148,14 +168,24 @@
   6440          put("KeyStore.BKS", "org.bouncycastle.jce.provider.JDKKeyStore");
   6441          put("KeyStore.BouncyCastle", "org.bouncycastle.jce.provider.JDKKeyStore$BouncyCastleStore");
   6442          put("KeyStore.PKCS12", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore");
   6443 -        put("KeyStore.BCPKCS12", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore");
   6444 -        put("KeyStore.PKCS12-DEF", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore");
   6445 -
   6446 -        put("KeyStore.PKCS12-3DES-40RC2", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore");
   6447 -        put("KeyStore.PKCS12-3DES-3DES", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore3DES");
   6448 -
   6449 -        put("KeyStore.PKCS12-DEF-3DES-40RC2", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore");
   6450 -        put("KeyStore.PKCS12-DEF-3DES-3DES", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore3DES");
   6451 +        // BEGIN android-changed
   6452 +        put("Alg.Alias.KeyStore.BCPKCS12", "PKCS12");
   6453 +        // END android-changed
   6454 +        // BEGIN android-removed
   6455 +        // put("KeyStore.PKCS12-DEF", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore");
   6456 +        // END android-removed
   6457 +
   6458 +        // BEGIN android-changed
   6459 +        put("Alg.Alias.KeyStore.PKCS12-3DES-40RC2", "PKCS12");
   6460 +        // END android-changed
   6461 +        // BEGIN android-removed
   6462 +        // put("KeyStore.PKCS12-3DES-3DES", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore3DES");
   6463 +        // END android-removed
   6464 +
   6465 +        // BEGIN android-removed
   6466 +        // put("KeyStore.PKCS12-DEF-3DES-40RC2", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore");
   6467 +        // put("KeyStore.PKCS12-DEF-3DES-3DES", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore3DES");
   6468 +        // END android-removed
   6469  
   6470          put("Alg.Alias.KeyStore.UBER", "BouncyCastle");
   6471          put("Alg.Alias.KeyStore.BOUNCYCASTLE", "BouncyCastle");
   6472 @@ -164,29 +194,41 @@
   6473          //
   6474          // algorithm parameters
   6475          //
   6476 -        put("AlgorithmParameters.IES", "org.bouncycastle.jce.provider.JDKAlgorithmParameters$IES");
   6477 +        // BEGIN android-removed
   6478 +        // put("AlgorithmParameters.IES", "org.bouncycastle.jce.provider.JDKAlgorithmParameters$IES");
   6479 +        // END android-removed
   6480          put("AlgorithmParameters.PKCS12PBE", "org.bouncycastle.jce.provider.JDKAlgorithmParameters$PKCS12PBE");
   6481  
   6482 -        put("AlgorithmParameters." + PKCSObjectIdentifiers.id_PBKDF2, "org.bouncycastle.jce.provider.JDKAlgorithmParameters$PBKDF2");
   6483 +        // BEGIN android-removed
   6484 +        // put("AlgorithmParameters." + PKCSObjectIdentifiers.id_PBKDF2, "org.bouncycastle.jce.provider.JDKAlgorithmParameters$PBKDF2");
   6485 +        // END android-removed
   6486  
   6487  
   6488          put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1ANDRC2", "PKCS12PBE");
   6489 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND3-KEYTRIPLEDES", "PKCS12PBE");
   6490 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND2-KEYTRIPLEDES", "PKCS12PBE");
   6491 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC2", "PKCS12PBE");
   6492 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC4", "PKCS12PBE");
   6493 +        // BEGIN android-removed
   6494 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND3-KEYTRIPLEDES", "PKCS12PBE");
   6495 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND2-KEYTRIPLEDES", "PKCS12PBE");
   6496 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC2", "PKCS12PBE");
   6497 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC4", "PKCS12PBE");
   6498 +        // END android-removed
   6499          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDTWOFISH", "PKCS12PBE");
   6500 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1ANDRC2-CBC", "PKCS12PBE");
   6501 +        // BEGIN android-removed
   6502 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1ANDRC2-CBC", "PKCS12PBE");
   6503 +        // END android-removed
   6504          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PKCS12PBE");
   6505          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND2-KEYTRIPLEDES-CBC", "PKCS12PBE");
   6506 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDDES3KEY-CBC", "PKCS12PBE");
   6507 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDDES2KEY-CBC", "PKCS12PBE");
   6508 +        // BEGIN android-removed
   6509 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDDES3KEY-CBC", "PKCS12PBE");
   6510 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDDES2KEY-CBC", "PKCS12PBE");
   6511 +        // END android-removed
   6512          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND40BITRC2-CBC", "PKCS12PBE");
   6513          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND40BITRC4", "PKCS12PBE");
   6514          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITRC2-CBC", "PKCS12PBE");
   6515          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITRC4", "PKCS12PBE");
   6516          put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDTWOFISH", "PKCS12PBE");
   6517 -        put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDTWOFISH-CBC", "PKCS12PBE");
   6518 +        // BEGIN android-removed
   6519 +        // put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDTWOFISH-CBC", "PKCS12PBE");
   6520 +        // END android-removed
   6521          put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.1", "PKCS12PBE");
   6522          put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.2", "PKCS12PBE");
   6523          put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.3", "PKCS12PBE");
   6524 @@ -217,12 +259,14 @@
   6525          put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND128BITAES-CBC-BC","PKCS12PBE");
   6526          put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND192BITAES-CBC-BC","PKCS12PBE");
   6527          put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND256BITAES-CBC-BC","PKCS12PBE");
   6528 -
   6529 -        put("AlgorithmParameters.SHA1WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6530 -        put("AlgorithmParameters.SHA224WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6531 -        put("AlgorithmParameters.SHA256WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6532 -        put("AlgorithmParameters.SHA384WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6533 -        put("AlgorithmParameters.SHA512WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6534 +        
   6535 +        // BEGIN android-removed
   6536 +        // put("AlgorithmParameters.SHA1WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6537 +        // put("AlgorithmParameters.SHA224WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6538 +        // put("AlgorithmParameters.SHA256WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6539 +        // put("AlgorithmParameters.SHA384WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6540 +        // put("AlgorithmParameters.SHA512WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
   6541 +        // END android-removed
   6542          
   6543          //
   6544          // key agreement
   6545 @@ -235,16 +279,22 @@
   6546          put("Alg.Alias.Cipher.PBEWithSHAAnd3KeyTripleDES",  "PBEWITHSHAAND3-KEYTRIPLEDES-CBC");
   6547          
   6548  
   6549 -        put("Cipher.ECIES", "org.bouncycastle.jce.provider.JCEIESCipher$ECIES");
   6550 -        put("Cipher.BrokenECIES", "org.bouncycastle.jce.provider.JCEIESCipher$BrokenECIES");
   6551 -        put("Cipher.IES", "org.bouncycastle.jce.provider.JCEIESCipher$IES");
   6552 -        put("Cipher.BrokenIES", "org.bouncycastle.jce.provider.JCEIESCipher$BrokenIES");
   6553 +        // BEGIN android-removed
   6554 +        // put("Cipher.ECIES", "org.bouncycastle.jce.provider.JCEIESCipher$ECIES");
   6555 +        // put("Cipher.BrokenECIES", "org.bouncycastle.jce.provider.JCEIESCipher$BrokenECIES");
   6556 +        // put("Cipher.IES", "org.bouncycastle.jce.provider.JCEIESCipher$IES");
   6557 +        // put("Cipher.BrokenIES", "org.bouncycastle.jce.provider.JCEIESCipher$BrokenIES");
   6558 +        // END android-removed
   6559  
   6560          put("Cipher.PBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithMD5AndDES");
   6561 -        put("Cipher.BROKENPBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithMD5AndDES");
   6562 +        // BEGIN android-removed
   6563 +        // put("Cipher.BROKENPBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithMD5AndDES");
   6564 +        // END android-removed
   6565          put("Cipher.PBEWITHMD5ANDRC2", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithMD5AndRC2");
   6566          put("Cipher.PBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHA1AndDES");
   6567 -        put("Cipher.BROKENPBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithSHA1AndDES");
   6568 +        // BEGIN android-removed
   6569 +        // put("Cipher.BROKENPBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithSHA1AndDES");
   6570 +        // END android-removed
   6571          put("Cipher.PBEWITHSHA1ANDRC2", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHA1AndRC2");
   6572  
   6573          put("Cipher.PBEWITHSHAAND128BITRC2-CBC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHAAnd128BitRC2");
   6574 @@ -286,10 +336,12 @@
   6575          put("Cipher.PBEWITHMD5AND256BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
   6576          
   6577          put("Cipher.PBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHAAndTwofish");
   6578 -        put("Cipher.OLDPBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$OldPBEWithSHAAndTwofish");
   6579 -
   6580 -        put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
   6581 -        put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
   6582 +        // BEGIN android-removed
   6583 +        // put("Cipher.OLDPBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$OldPBEWithSHAAndTwofish");
   6584 +        //
   6585 +        // put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
   6586 +        // put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
   6587 +        // END android-removed
   6588          put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, "PBEWITHMD5ANDDES");
   6589          put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDDES");
   6590          put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, "PBEWITHSHA1ANDDES");
   6591 @@ -326,16 +378,20 @@
   6592          //
   6593          // secret key factories.
   6594          //
   6595 -        put("SecretKeyFactory.PBEWITHMD2ANDDES", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD2AndDES");
   6596 -
   6597 -        put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
   6598 -        put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
   6599 +        // BEGIN android-removed
   6600 +        // put("SecretKeyFactory.PBEWITHMD2ANDDES", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD2AndDES");
   6601 +        //
   6602 +        // put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
   6603 +        // put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
   6604 +        // END android-removed
   6605          put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, "PBEWITHMD5ANDDES");
   6606          put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDDES");
   6607          put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, "PBEWITHSHA1ANDDES");
   6608          put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHA1AndRC2_CBC, "PBEWITHSHA1ANDRC2");
   6609  
   6610 -        put("SecretKeyFactory.PBEWITHMD2ANDRC2", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD2AndRC2");
   6611 +        // BEGIN android-removed
   6612 +        // put("SecretKeyFactory.PBEWITHMD2ANDRC2", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD2AndRC2");
   6613 +        // END android-removed
   6614          put("SecretKeyFactory.PBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5AndDES");
   6615          put("SecretKeyFactory.PBEWITHMD5ANDRC2", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5AndRC2");
   6616          put("SecretKeyFactory.PBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA1AndDES");
   6617 @@ -347,31 +403,39 @@
   6618          put("SecretKeyFactory.PBEWITHSHAAND128BITRC2-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd128BitRC2");
   6619          put("SecretKeyFactory.PBEWITHSHAAND40BITRC2-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd40BitRC2");
   6620          put("SecretKeyFactory.PBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAndTwofish");
   6621 -        put("SecretKeyFactory.PBEWITHHMACRIPEMD160", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithRIPEMD160");
   6622 +        // BEGIN android-removed
   6623 +        // put("SecretKeyFactory.PBEWITHHMACRIPEMD160", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithRIPEMD160");
   6624 +        // END android-removed
   6625          put("SecretKeyFactory.PBEWITHHMACSHA1", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA");
   6626 -        put("SecretKeyFactory.PBEWITHHMACTIGER", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithTiger");
   6627 +        // BEGIN android-removed
   6628 +        // put("SecretKeyFactory.PBEWITHHMACTIGER", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithTiger");
   6629 +        // END android-removed
   6630          
   6631          put("SecretKeyFactory.PBEWITHMD5AND128BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5And128BitAESCBCOpenSSL");
   6632          put("SecretKeyFactory.PBEWITHMD5AND192BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5And192BitAESCBCOpenSSL");
   6633          put("SecretKeyFactory.PBEWITHMD5AND256BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5And256BitAESCBCOpenSSL");
   6634  
   6635 -        put("Alg.Alias.SecretKeyFactory.PBE", "PBE/PKCS5");
   6636 -
   6637 -        put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHMD5ANDDES", "PBE/PKCS5");
   6638 -        put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHA1ANDDES", "PBE/PKCS5");
   6639 -        put("Alg.Alias.SecretKeyFactory.OLDPBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PBE/PKCS12");
   6640 -        put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PBE/PKCS12");
   6641 -        put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHAAND2-KEYTRIPLEDES-CBC", "PBE/PKCS12");
   6642 -        put("Alg.Alias.SecretKeyFactory.OLDPBEWITHSHAANDTWOFISH-CBC", "PBE/PKCS12");
   6643 -
   6644 -        put("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDDES-CBC", "PBEWITHMD2ANDDES");
   6645 -        put("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDRC2-CBC", "PBEWITHMD2ANDRC2");
   6646 +        // BEGIN android-removed
   6647 +        // put("Alg.Alias.SecretKeyFactory.PBE", "PBE/PKCS5");
   6648 +        //
   6649 +        // put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHMD5ANDDES", "PBE/PKCS5");
   6650 +        // put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHA1ANDDES", "PBE/PKCS5");
   6651 +        // put("Alg.Alias.SecretKeyFactory.OLDPBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PBE/PKCS12");
   6652 +        // put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PBE/PKCS12");
   6653 +        // put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHAAND2-KEYTRIPLEDES-CBC", "PBE/PKCS12");
   6654 +        // put("Alg.Alias.SecretKeyFactory.OLDPBEWITHSHAANDTWOFISH-CBC", "PBE/PKCS12");
   6655 +        //
   6656 +        // put("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDDES-CBC", "PBEWITHMD2ANDDES");
   6657 +        // put("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDRC2-CBC", "PBEWITHMD2ANDRC2");
   6658 +        // END android-removed
   6659          put("Alg.Alias.SecretKeyFactory.PBEWITHMD5ANDDES-CBC", "PBEWITHMD5ANDDES");
   6660          put("Alg.Alias.SecretKeyFactory.PBEWITHMD5ANDRC2-CBC", "PBEWITHMD5ANDRC2");
   6661          put("Alg.Alias.SecretKeyFactory.PBEWITHSHA1ANDDES-CBC", "PBEWITHSHA1ANDDES");
   6662          put("Alg.Alias.SecretKeyFactory.PBEWITHSHA1ANDRC2-CBC", "PBEWITHSHA1ANDRC2");
   6663 -        put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
   6664 -        put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
   6665 +        // BEGIN android-removed
   6666 +        // put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
   6667 +        // put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
   6668 +        // END android-removed
   6669          put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, "PBEWITHMD5ANDDES");
   6670          put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDRC2");
   6671          put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, "PBEWITHSHA1ANDDES");
   6672 @@ -408,20 +472,31 @@
   6673          put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc.getId(), "PBEWITHSHA256AND128BITAES-CBC-BC");
   6674          put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc.getId(), "PBEWITHSHA256AND192BITAES-CBC-BC");
   6675          put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc.getId(), "PBEWITHSHA256AND256BITAES-CBC-BC");
   6676 +        // BEGIN android-added
   6677 +
   6678 +        put("SecretKeyFactory.PBKDF2WithHmacSHA1", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBKDF2WithHmacSHA1");
   6679 +        // END android-added
   6680  
   6681          addMacAlgorithms();
   6682  
   6683      // Certification Path API
   6684 -        put("CertPathValidator.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathValidatorSpi");
   6685 -        put("CertPathBuilder.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathBuilderSpi");
   6686 -        put("CertPathValidator.RFC3280", "org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi");
   6687 -        put("CertPathBuilder.RFC3280", "org.bouncycastle.jce.provider.PKIXCertPathBuilderSpi");
   6688 +        // BEGIN android-removed
   6689 +        // put("CertPathValidator.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathValidatorSpi");
   6690 +        // put("CertPathBuilder.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathBuilderSpi");
   6691 +        // END android-removed
   6692 +        // BEGIN android-changed
   6693 +        // Use Alg.Alias so RFC3280 doesn't show up when iterating provider services, only PKIX
   6694 +        put("Alg.Alias.CertPathValidator.RFC3280", "PKIX");
   6695 +        put("Alg.Alias.CertPathBuilder.RFC3280", "PKIX");
   6696 +        // END android-changed
   6697          put("CertPathValidator.PKIX", "org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi");
   6698          put("CertPathBuilder.PKIX", "org.bouncycastle.jce.provider.PKIXCertPathBuilderSpi");
   6699          put("CertStore.Collection", "org.bouncycastle.jce.provider.CertStoreCollectionSpi");
   6700 -        put("CertStore.LDAP", "org.bouncycastle.jce.provider.X509LDAPCertStoreSpi");
   6701 -        put("CertStore.Multi", "org.bouncycastle.jce.provider.MultiCertStoreSpi");
   6702 -        put("Alg.Alias.CertStore.X509LDAP", "LDAP");
   6703 +        // BEGIN android-removed
   6704 +        // put("CertStore.LDAP", "org.bouncycastle.jce.provider.X509LDAPCertStoreSpi");
   6705 +        // put("CertStore.Multi", "org.bouncycastle.jce.provider.MultiCertStoreSpi");
   6706 +        // put("Alg.Alias.CertStore.X509LDAP", "LDAP");
   6707 +        // END android-removed
   6708      }
   6709  
   6710      private void loadAlgorithms(String packageName, String[] names)
   6711 @@ -469,21 +544,25 @@
   6712      private void addMacAlgorithms()
   6713      {
   6714  
   6715 -        put("Mac.DESWITHISO9797", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3");
   6716 -        put("Alg.Alias.Mac.DESISO9797MAC", "DESWITHISO9797");
   6717 -
   6718 -        put("Mac.ISO9797ALG3MAC", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3");
   6719 -        put("Alg.Alias.Mac.ISO9797ALG3", "ISO9797ALG3MAC");
   6720 -        put("Mac.ISO9797ALG3WITHISO7816-4PADDING", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3with7816d4");
   6721 -        put("Alg.Alias.Mac.ISO9797ALG3MACWITHISO7816-4PADDING", "ISO9797ALG3WITHISO7816-4PADDING");
   6722 -
   6723 -        put("Mac.OLDHMACSHA384", "org.bouncycastle.jce.provider.JCEMac$OldSHA384");
   6724 -
   6725 -        put("Mac.OLDHMACSHA512", "org.bouncycastle.jce.provider.JCEMac$OldSHA512");
   6726 +        // BEGIN android-removed
   6727 +        // put("Mac.DESWITHISO9797", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3");
   6728 +        // put("Alg.Alias.Mac.DESISO9797MAC", "DESWITHISO9797");
   6729 +        //
   6730 +        // put("Mac.ISO9797ALG3MAC", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3");
   6731 +        // put("Alg.Alias.Mac.ISO9797ALG3", "ISO9797ALG3MAC");
   6732 +        // put("Mac.ISO9797ALG3WITHISO7816-4PADDING", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3with7816d4");
   6733 +        // put("Alg.Alias.Mac.ISO9797ALG3MACWITHISO7816-4PADDING", "ISO9797ALG3WITHISO7816-4PADDING");
   6734 +        //
   6735 +        // put("Mac.OLDHMACSHA384", "org.bouncycastle.jce.provider.JCEMac$OldSHA384");
   6736 +        //
   6737 +        // put("Mac.OLDHMACSHA512", "org.bouncycastle.jce.provider.JCEMac$OldSHA512");
   6738 +        // END android-removed
   6739  
   6740          put("Mac.PBEWITHHMACSHA", "org.bouncycastle.jce.provider.JCEMac$PBEWithSHA");
   6741          put("Mac.PBEWITHHMACSHA1", "org.bouncycastle.jce.provider.JCEMac$PBEWithSHA");
   6742 -        put("Mac.PBEWITHHMACRIPEMD160", "org.bouncycastle.jce.provider.JCEMac$PBEWithRIPEMD160");
   6743 +        // BEGIN android-removed
   6744 +        // put("Mac.PBEWITHHMACRIPEMD160", "org.bouncycastle.jce.provider.JCEMac$PBEWithRIPEMD160");
   6745 +        // END android-removed
   6746          put("Alg.Alias.Mac.1.3.14.3.2.26", "PBEWITHHMACSHA");
   6747      }
   6748  
   6749 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/CertBlacklist.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/CertBlacklist.java
   6750 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/CertBlacklist.java	1970-01-01 00:00:00.000000000 +0000
   6751 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/CertBlacklist.java	2012-09-19 21:17:12.000000000 +0000
   6752 @@ -0,0 +1,216 @@
   6753 +/*
   6754 + * Copyright (C) 2012 The Android Open Source Project
   6755 + *
   6756 + * Licensed under the Apache License, Version 2.0 (the "License");
   6757 + * you may not use this file except in compliance with the License.
   6758 + * You may obtain a copy of the License at
   6759 + *
   6760 + *      http://www.apache.org/licenses/LICENSE-2.0
   6761 + *
   6762 + * Unless required by applicable law or agreed to in writing, software
   6763 + * distributed under the License is distributed on an "AS IS" BASIS,
   6764 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   6765 + * See the License for the specific language governing permissions and
   6766 + * limitations under the License.
   6767 + */
   6768 +
   6769 +package org.bouncycastle.jce.provider;
   6770 +
   6771 +import java.io.Closeable;
   6772 +import java.io.ByteArrayOutputStream;
   6773 +import java.io.FileNotFoundException;
   6774 +import java.io.IOException;
   6775 +import java.io.RandomAccessFile;
   6776 +import java.math.BigInteger;
   6777 +import java.security.PublicKey;
   6778 +import java.util.Arrays;
   6779 +import java.util.Collections;
   6780 +import java.util.HashSet;
   6781 +import java.util.Set;
   6782 +import java.util.logging.Level;
   6783 +import java.util.logging.Logger;
   6784 +import org.bouncycastle.crypto.Digest;
   6785 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   6786 +import org.bouncycastle.util.encoders.Hex;
   6787 +
   6788 +public class CertBlacklist {
   6789 +
   6790 +    private static final String ANDROID_DATA = System.getenv("ANDROID_DATA");
   6791 +    private static final String BLACKLIST_ROOT = ANDROID_DATA + "/misc/keychain/";
   6792 +    public static final String DEFAULT_PUBKEY_BLACKLIST_PATH = BLACKLIST_ROOT + "pubkey_blacklist.txt";
   6793 +    public static final String DEFAULT_SERIAL_BLACKLIST_PATH = BLACKLIST_ROOT + "serial_blacklist.txt";
   6794 +
   6795 +    private static final Logger logger = Logger.getLogger(CertBlacklist.class.getName());
   6796 +
   6797 +    // public for testing
   6798 +    public final Set<BigInteger> serialBlacklist;
   6799 +    public final Set<byte[]> pubkeyBlacklist;
   6800 +
   6801 +    public CertBlacklist() {
   6802 +        this(DEFAULT_PUBKEY_BLACKLIST_PATH, DEFAULT_SERIAL_BLACKLIST_PATH);
   6803 +    }
   6804 +
   6805 +    /** Test only interface, not for public use */
   6806 +    public CertBlacklist(String pubkeyBlacklistPath, String serialBlacklistPath) {
   6807 +        serialBlacklist = readSerialBlackList(serialBlacklistPath);
   6808 +        pubkeyBlacklist = readPublicKeyBlackList(pubkeyBlacklistPath);
   6809 +    }
   6810 +
   6811 +    private static boolean isHex(String value) {
   6812 +        try {
   6813 +            new BigInteger(value, 16);
   6814 +            return true;
   6815 +        } catch (NumberFormatException e) {
   6816 +            logger.log(Level.WARNING, "Could not parse hex value " + value, e);
   6817 +            return false;
   6818 +        }
   6819 +    }
   6820 +
   6821 +    private static boolean isPubkeyHash(String value) {
   6822 +        if (value.length() != 40) {
   6823 +            logger.log(Level.WARNING, "Invalid pubkey hash length: " + value.length());
   6824 +            return false;
   6825 +        }
   6826 +        return isHex(value);
   6827 +    }
   6828 +
   6829 +    private static String readBlacklist(String path) {
   6830 +        try {
   6831 +            return readFileAsString(path);
   6832 +        } catch (FileNotFoundException ignored) {
   6833 +        } catch (IOException e) {
   6834 +            logger.log(Level.WARNING, "Could not read blacklist", e);
   6835 +        }
   6836 +        return "";
   6837 +    }
   6838 +
   6839 +    // From IoUtils.readFileAsString
   6840 +    private static String readFileAsString(String path) throws IOException {
   6841 +        return readFileAsBytes(path).toString("UTF-8");
   6842 +    }
   6843 +
   6844 +    // Based on IoUtils.readFileAsBytes
   6845 +    private static ByteArrayOutputStream readFileAsBytes(String path) throws IOException {
   6846 +        RandomAccessFile f = null;
   6847 +        try {
   6848 +            f = new RandomAccessFile(path, "r");
   6849 +            ByteArrayOutputStream bytes = new ByteArrayOutputStream((int) f.length());
   6850 +            byte[] buffer = new byte[8192];
   6851 +            while (true) {
   6852 +                int byteCount = f.read(buffer);
   6853 +                if (byteCount == -1) {
   6854 +                    return bytes;
   6855 +                }
   6856 +                bytes.write(buffer, 0, byteCount);
   6857 +            }
   6858 +        } finally {
   6859 +            closeQuietly(f);
   6860 +        }
   6861 +    }
   6862 +
   6863 +    // Base on IoUtils.closeQuietly
   6864 +    private static void closeQuietly(Closeable closeable) {
   6865 +        if (closeable != null) {
   6866 +            try {
   6867 +                closeable.close();
   6868 +            } catch (RuntimeException rethrown) {
   6869 +                throw rethrown;
   6870 +            } catch (Exception ignored) {
   6871 +            }
   6872 +        }
   6873 +    }
   6874 +
   6875 +    private static final Set<BigInteger> readSerialBlackList(String path) {
   6876 +
   6877 +        // start out with a base set of known bad values
   6878 +        Set<BigInteger> bl = new HashSet<BigInteger>(Arrays.asList(
   6879 +            // From http://src.chromium.org/viewvc/chrome/trunk/src/net/base/x509_certificate.cc?revision=78748&view=markup
   6880 +            // Not a real certificate. For testing only.
   6881 +            new BigInteger("077a59bcd53459601ca6907267a6dd1c", 16),
   6882 +            new BigInteger("047ecbe9fca55f7bd09eae36e10cae1e", 16),
   6883 +            new BigInteger("d8f35f4eb7872b2dab0692e315382fb0", 16),
   6884 +            new BigInteger("b0b7133ed096f9b56fae91c874bd3ac0", 16),
   6885 +            new BigInteger("9239d5348f40d1695a745470e1f23f43", 16),
   6886 +            new BigInteger("e9028b9578e415dc1a710a2b88154447", 16),
   6887 +            new BigInteger("d7558fdaf5f1105bb213282b707729a3", 16),
   6888 +            new BigInteger("f5c86af36162f13a64f54f6dc9587c06", 16),
   6889 +            new BigInteger("392a434f0e07df1f8aa305de34e0c229", 16),
   6890 +            new BigInteger("3e75ced46b693021218830ae86a82a71", 16)
   6891 +        ));
   6892 +
   6893 +        // attempt to augment it with values taken from gservices
   6894 +        String serialBlacklist = readBlacklist(path);
   6895 +        if (!serialBlacklist.equals("")) {
   6896 +            for(String value : serialBlacklist.split(",")) {
   6897 +                try {
   6898 +                    bl.add(new BigInteger(value, 16));
   6899 +                } catch (NumberFormatException e) {
   6900 +                    logger.log(Level.WARNING, "Tried to blacklist invalid serial number " + value, e);
   6901 +                }
   6902 +            }
   6903 +        }
   6904 +
   6905 +        // whether that succeeds or fails, send it on its merry way
   6906 +        return Collections.unmodifiableSet(bl);
   6907 +    }
   6908 +
   6909 +    private static final Set<byte[]> readPublicKeyBlackList(String path) {
   6910 +
   6911 +        // start out with a base set of known bad values
   6912 +        Set<byte[]> bl = new HashSet<byte[]>(Arrays.asList(
   6913 +            // From http://src.chromium.org/viewvc/chrome/branches/782/src/net/base/x509_certificate.cc?r1=98750&r2=98749&pathrev=98750
   6914 +            // C=NL, O=DigiNotar, CN=DigiNotar Root CA/emailAddress=info (a] diginotar.nl
   6915 +            "410f36363258f30b347d12ce4863e433437806a8".getBytes(),
   6916 +            // Subject: CN=DigiNotar Cyber CA
   6917 +            // Issuer: CN=GTE CyberTrust Global Root
   6918 +            "ba3e7bd38cd7e1e6b9cd4c219962e59d7a2f4e37".getBytes(),
   6919 +            // Subject: CN=DigiNotar Services 1024 CA
   6920 +            // Issuer: CN=Entrust.net
   6921 +            "e23b8d105f87710a68d9248050ebefc627be4ca6".getBytes(),
   6922 +            // Subject: CN=DigiNotar PKIoverheid CA Organisatie - G2
   6923 +            // Issuer: CN=Staat der Nederlanden Organisatie CA - G2
   6924 +            "7b2e16bc39bcd72b456e9f055d1de615b74945db".getBytes(),
   6925 +            // Subject: CN=DigiNotar PKIoverheid CA Overheid en Bedrijven
   6926 +            // Issuer: CN=Staat der Nederlanden Overheid CA
   6927 +            "e8f91200c65cee16e039b9f883841661635f81c5".getBytes(),
   6928 +            // From http://src.chromium.org/viewvc/chrome?view=rev&revision=108479
   6929 +            // Subject: O=Digicert Sdn. Bhd.
   6930 +            // Issuer: CN=GTE CyberTrust Global Root
   6931 +            "0129bcd5b448ae8d2496d1c3e19723919088e152".getBytes()
   6932 +        ));
   6933 +
   6934 +        // attempt to augment it with values taken from gservices
   6935 +        String pubkeyBlacklist = readBlacklist(path);
   6936 +        if (!pubkeyBlacklist.equals("")) {
   6937 +            for (String value : pubkeyBlacklist.split(",")) {
   6938 +                value = value.trim();
   6939 +                if (isPubkeyHash(value)) {
   6940 +                    bl.add(value.getBytes());
   6941 +                } else {
   6942 +                    logger.log(Level.WARNING, "Tried to blacklist invalid pubkey " + value);
   6943 +                }
   6944 +            }
   6945 +        }
   6946 +
   6947 +        return bl;
   6948 +    }
   6949 +
   6950 +    public boolean isPublicKeyBlackListed(PublicKey publicKey) {
   6951 +        byte[] encoded = publicKey.getEncoded();
   6952 +        Digest digest = AndroidDigestFactory.getSHA1();
   6953 +        digest.update(encoded, 0, encoded.length);
   6954 +        byte[] out = new byte[digest.getDigestSize()];
   6955 +        digest.doFinal(out, 0);
   6956 +        for (byte[] blacklisted : pubkeyBlacklist) {
   6957 +            if (Arrays.equals(blacklisted, Hex.encode(out))) {
   6958 +                return true;
   6959 +            }
   6960 +        }
   6961 +        return false;
   6962 +    }
   6963 +
   6964 +    public boolean isSerialNumberBlackListed(BigInteger serial) {
   6965 +        return serialBlacklist.contains(serial);
   6966 +    }
   6967 +
   6968 +}
   6969 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/CertPathValidatorUtilities.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/CertPathValidatorUtilities.java
   6970 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/CertPathValidatorUtilities.java	2012-03-22 15:11:48.000000000 +0000
   6971 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/CertPathValidatorUtilities.java	2012-09-19 21:17:12.000000000 +0000
   6972 @@ -61,13 +61,17 @@
   6973  import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
   6974  import org.bouncycastle.asn1.x509.X509Extension;
   6975  import org.bouncycastle.asn1.x509.X509Extensions;
   6976 -import org.bouncycastle.jce.X509LDAPCertStoreParameters;
   6977 +// BEGIN android-removed
   6978 +// import org.bouncycastle.jce.X509LDAPCertStoreParameters;
   6979 +// END android-removed
   6980  import org.bouncycastle.jce.exception.ExtCertPathValidatorException;
   6981  import org.bouncycastle.util.Selector;
   6982  import org.bouncycastle.util.StoreException;
   6983  import org.bouncycastle.x509.ExtendedPKIXBuilderParameters;
   6984  import org.bouncycastle.x509.ExtendedPKIXParameters;
   6985 -import org.bouncycastle.x509.X509AttributeCertStoreSelector;
   6986 +// BEGIN android-removed
   6987 +// import org.bouncycastle.x509.X509AttributeCertStoreSelector;
   6988 +// END android-removed
   6989  import org.bouncycastle.x509.X509AttributeCertificate;
   6990  import org.bouncycastle.x509.X509CRLStoreSelector;
   6991  import org.bouncycastle.x509.X509CertStoreSelector;
   6992 @@ -247,7 +251,9 @@
   6993              {
   6994                  // look for URI
   6995                  List list = (List)it.next();
   6996 -                if (list.get(0).equals(new Integer(GeneralName.uniformResourceIdentifier)))
   6997 +                // BEGIN android-changed
   6998 +                if (list.get(0).equals(Integer.valueOf(GeneralName.uniformResourceIdentifier)))
   6999 +                // END android-changed
   7000                  {
   7001                      // found
   7002                      String temp = (String)list.get(1);
   7003 @@ -655,38 +661,40 @@
   7004          {
   7005              try
   7006              {
   7007 -                if (location.startsWith("ldap://"))
   7008 -                {
   7009 -                    // ldap://directory.d-trust.net/CN=D-TRUST
   7010 -                    // Qualified CA 2003 1:PN,O=D-Trust GmbH,C=DE
   7011 -                    // skip "ldap://"
   7012 -                    location = location.substring(7);
   7013 -                    // after first / baseDN starts
   7014 -                    String base = null;
   7015 -                    String url = null;
   7016 -                    if (location.indexOf("/") != -1)
   7017 -                    {
   7018 -                        base = location.substring(location.indexOf("/"));
   7019 -                        // URL
   7020 -                        url = "ldap://"
   7021 -                            + location.substring(0, location.indexOf("/"));
   7022 -                    }
   7023 -                    else
   7024 -                    {
   7025 -                        url = "ldap://" + location;
   7026 -                    }
   7027 -                    // use all purpose parameters
   7028 -                    X509LDAPCertStoreParameters params = new X509LDAPCertStoreParameters.Builder(
   7029 -                        url, base).build();
   7030 -                    pkixParams.addAdditionalStore(X509Store.getInstance(
   7031 -                        "CERTIFICATE/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7032 -                    pkixParams.addAdditionalStore(X509Store.getInstance(
   7033 -                        "CRL/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7034 -                    pkixParams.addAdditionalStore(X509Store.getInstance(
   7035 -                        "ATTRIBUTECERTIFICATE/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7036 -                    pkixParams.addAdditionalStore(X509Store.getInstance(
   7037 -                        "CERTIFICATEPAIR/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7038 -                }
   7039 +                // BEGIN android-removed
   7040 +                // if (location.startsWith("ldap://"))
   7041 +                // {
   7042 +                //     // ldap://directory.d-trust.net/CN=D-TRUST
   7043 +                //     // Qualified CA 2003 1:PN,O=D-Trust GmbH,C=DE
   7044 +                //     // skip "ldap://"
   7045 +                //     location = location.substring(7);
   7046 +                //     // after first / baseDN starts
   7047 +                //     String base = null;
   7048 +                //     String url = null;
   7049 +                //     if (location.indexOf("/") != -1)
   7050 +                //     {
   7051 +                //         base = location.substring(location.indexOf("/"));
   7052 +                //         // URL
   7053 +                //         url = "ldap://"
   7054 +                //             + location.substring(0, location.indexOf("/"));
   7055 +                //     }
   7056 +                //     else
   7057 +                //     {
   7058 +                //         url = "ldap://" + location;
   7059 +                //     }
   7060 +                //     // use all purpose parameters
   7061 +                //     X509LDAPCertStoreParameters params = new X509LDAPCertStoreParameters.Builder(
   7062 +                //         url, base).build();
   7063 +                //     pkixParams.addAdditionalStore(X509Store.getInstance(
   7064 +                //         "CERTIFICATE/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7065 +                //     pkixParams.addAdditionalStore(X509Store.getInstance(
   7066 +                //         "CRL/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7067 +                //     pkixParams.addAdditionalStore(X509Store.getInstance(
   7068 +                //         "ATTRIBUTECERTIFICATE/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7069 +                //     pkixParams.addAdditionalStore(X509Store.getInstance(
   7070 +                //         "CERTIFICATEPAIR/LDAP", params, BouncyCastleProvider.PROVIDER_NAME));
   7071 +                // }
   7072 +                // END android-removed
   7073              }
   7074              catch (Exception e)
   7075              {
   7076 @@ -751,33 +759,35 @@
   7077          return certs;
   7078      }
   7079  
   7080 -    protected static Collection findCertificates(X509AttributeCertStoreSelector certSelect,
   7081 -                                                 List certStores)
   7082 -        throws AnnotatedException
   7083 -    {
   7084 -        Set certs = new HashSet();
   7085 -        Iterator iter = certStores.iterator();
   7086 -
   7087 -        while (iter.hasNext())
   7088 -        {
   7089 -            Object obj = iter.next();
   7090 -
   7091 -            if (obj instanceof X509Store)
   7092 -            {
   7093 -                X509Store certStore = (X509Store)obj;
   7094 -                try
   7095 -                {
   7096 -                    certs.addAll(certStore.getMatches(certSelect));
   7097 -                }
   7098 -                catch (StoreException e)
   7099 -                {
   7100 -                    throw new AnnotatedException(
   7101 -                            "Problem while picking certificates from X.509 store.", e);
   7102 -                }
   7103 -            }
   7104 -        }
   7105 -        return certs;
   7106 -    }
   7107 +    // BEGIN android-removed
   7108 +    // protected static Collection findCertificates(X509AttributeCertStoreSelector certSelect,
   7109 +    //                                              List certStores)
   7110 +    //     throws AnnotatedException
   7111 +    // {
   7112 +    //     Set certs = new HashSet();
   7113 +    //     Iterator iter = certStores.iterator();
   7114 +    //
   7115 +    //     while (iter.hasNext())
   7116 +    //     {
   7117 +    //         Object obj = iter.next();
   7118 +    //
   7119 +    //         if (obj instanceof X509Store)
   7120 +    //         {
   7121 +    //             X509Store certStore = (X509Store)obj;
   7122 +    //             try
   7123 +    //             {
   7124 +    //                 certs.addAll(certStore.getMatches(certSelect));
   7125 +    //             }
   7126 +    //             catch (StoreException e)
   7127 +    //             {
   7128 +    //                 throw new AnnotatedException(
   7129 +    //                         "Problem while picking certificates from X.509 store.", e);
   7130 +    //             }
   7131 +    //         }
   7132 +    //     }
   7133 +    //     return certs;
   7134 +    // }
   7135 +    // END android-removed
   7136  
   7137      protected static void addAdditionalStoresFromCRLDistributionPoint(
   7138          CRLDistPoint crldp, ExtendedPKIXParameters pkixParams)
   7139 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEBlockCipher.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEBlockCipher.java
   7140 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEBlockCipher.java	2012-03-22 15:11:48.000000000 +0000
   7141 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEBlockCipher.java	2012-09-19 21:17:12.000000000 +0000
   7142 @@ -18,8 +18,10 @@
   7143  import javax.crypto.ShortBufferException;
   7144  import javax.crypto.spec.IvParameterSpec;
   7145  import javax.crypto.spec.PBEParameterSpec;
   7146 -import javax.crypto.spec.RC2ParameterSpec;
   7147 -import javax.crypto.spec.RC5ParameterSpec;
   7148 +// BEGIN android-removed
   7149 +// import javax.crypto.spec.RC2ParameterSpec;
   7150 +// import javax.crypto.spec.RC5ParameterSpec;
   7151 +// END android-removed
   7152  
   7153  import org.bouncycastle.crypto.BlockCipher;
   7154  import org.bouncycastle.crypto.BufferedBlockCipher;
   7155 @@ -28,7 +30,9 @@
   7156  import org.bouncycastle.crypto.InvalidCipherTextException;
   7157  import org.bouncycastle.crypto.engines.AESFastEngine;
   7158  import org.bouncycastle.crypto.engines.DESEngine;
   7159 -import org.bouncycastle.crypto.engines.GOST28147Engine;
   7160 +// BEGIN android-removed
   7161 +// import org.bouncycastle.crypto.engines.GOST28147Engine;
   7162 +// END android-removed
   7163  import org.bouncycastle.crypto.engines.RC2Engine;
   7164  import org.bouncycastle.crypto.engines.TwofishEngine;
   7165  import org.bouncycastle.crypto.modes.AEADBlockCipher;
   7166 @@ -36,12 +40,18 @@
   7167  import org.bouncycastle.crypto.modes.CCMBlockCipher;
   7168  import org.bouncycastle.crypto.modes.CFBBlockCipher;
   7169  import org.bouncycastle.crypto.modes.CTSBlockCipher;
   7170 -import org.bouncycastle.crypto.modes.EAXBlockCipher;
   7171 +// BEGIN android-removed
   7172 +// import org.bouncycastle.crypto.modes.EAXBlockCipher;
   7173 +// END android-removed
   7174  import org.bouncycastle.crypto.modes.GCMBlockCipher;
   7175 -import org.bouncycastle.crypto.modes.GOFBBlockCipher;
   7176 +// BEGIN android-removed
   7177 +// import org.bouncycastle.crypto.modes.GOFBBlockCipher;
   7178 +// END android-removed
   7179  import org.bouncycastle.crypto.modes.OFBBlockCipher;
   7180 -import org.bouncycastle.crypto.modes.OpenPGPCFBBlockCipher;
   7181 -import org.bouncycastle.crypto.modes.PGPCFBBlockCipher;
   7182 +// BEGIN android-removed
   7183 +// import org.bouncycastle.crypto.modes.OpenPGPCFBBlockCipher;
   7184 +// import org.bouncycastle.crypto.modes.PGPCFBBlockCipher;
   7185 +// END android-removed
   7186  import org.bouncycastle.crypto.modes.SICBlockCipher;
   7187  import org.bouncycastle.crypto.paddings.BlockCipherPadding;
   7188  import org.bouncycastle.crypto.paddings.ISO10126d2Padding;
   7189 @@ -53,12 +63,16 @@
   7190  import org.bouncycastle.crypto.params.KeyParameter;
   7191  import org.bouncycastle.crypto.params.ParametersWithIV;
   7192  import org.bouncycastle.crypto.params.ParametersWithRandom;
   7193 -import org.bouncycastle.crypto.params.ParametersWithSBox;
   7194 -import org.bouncycastle.crypto.params.RC2Parameters;
   7195 -import org.bouncycastle.crypto.params.RC5Parameters;
   7196 +// BEGIN android-removed
   7197 +// import org.bouncycastle.crypto.params.ParametersWithSBox;
   7198 +// import org.bouncycastle.crypto.params.RC2Parameters;
   7199 +// import org.bouncycastle.crypto.params.RC5Parameters;
   7200 +// END android-removed
   7201  import org.bouncycastle.jcajce.provider.symmetric.util.BCPBEKey;
   7202  import org.bouncycastle.jcajce.provider.symmetric.util.PBE;
   7203 -import org.bouncycastle.jce.spec.GOST28147ParameterSpec;
   7204 +// BEGIN android-removed
   7205 +// import org.bouncycastle.jce.spec.GOST28147ParameterSpec;
   7206 +// END android-removed
   7207  import org.bouncycastle.jce.spec.RepeatedSecretKeySpec;
   7208  import org.bouncycastle.util.Strings;
   7209  
   7210 @@ -71,11 +85,15 @@
   7211      //
   7212      private Class[]                 availableSpecs =
   7213                                      {
   7214 -                                        RC2ParameterSpec.class,
   7215 -                                        RC5ParameterSpec.class,
   7216 +                                        // BEGIN android-removed
   7217 +                                        // RC2ParameterSpec.class,
   7218 +                                        // RC5ParameterSpec.class,
   7219 +                                        // END android-removed
   7220                                          IvParameterSpec.class,
   7221                                          PBEParameterSpec.class,
   7222 -                                        GOST28147ParameterSpec.class
   7223 +                                        // BEGIN android-removed
   7224 +                                        // GOST28147ParameterSpec.class
   7225 +                                        // END android-removed
   7226                                      };
   7227   
   7228      private BlockCipher             baseEngine;
   7229 @@ -232,20 +250,22 @@
   7230                          new CFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
   7231              }
   7232          }
   7233 -        else if (modeName.startsWith("PGP"))
   7234 -        {
   7235 -            boolean inlineIV = modeName.equalsIgnoreCase("PGPCFBwithIV");
   7236 -
   7237 -            ivLength = baseEngine.getBlockSize();
   7238 -            cipher = new BufferedGenericBlockCipher(
   7239 -                new PGPCFBBlockCipher(baseEngine, inlineIV));
   7240 -        }
   7241 -        else if (modeName.equalsIgnoreCase("OpenPGPCFB"))
   7242 -        {
   7243 -            ivLength = 0;
   7244 -            cipher = new BufferedGenericBlockCipher(
   7245 -                new OpenPGPCFBBlockCipher(baseEngine));
   7246 -        }
   7247 +        // BEGIN android-removed
   7248 +        // else if (modeName.startsWith("PGP"))
   7249 +        // {
   7250 +        //     boolean inlineIV = modeName.equalsIgnoreCase("PGPCFBwithIV");
   7251 +        //
   7252 +        //     ivLength = baseEngine.getBlockSize();
   7253 +        //     cipher = new BufferedGenericBlockCipher(
   7254 +        //         new PGPCFBBlockCipher(baseEngine, inlineIV));
   7255 +        // }
   7256 +        // else if (modeName.equalsIgnoreCase("OpenPGPCFB"))
   7257 +        // {
   7258 +        //     ivLength = 0;
   7259 +        //     cipher = new BufferedGenericBlockCipher(
   7260 +        //         new OpenPGPCFBBlockCipher(baseEngine));
   7261 +        // }
   7262 +        // END android-removed
   7263          else if (modeName.startsWith("SIC"))
   7264          {
   7265              ivLength = baseEngine.getBlockSize();
   7266 @@ -262,12 +282,14 @@
   7267              cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
   7268                          new SICBlockCipher(baseEngine)));
   7269          }
   7270 -        else if (modeName.startsWith("GOFB"))
   7271 -        {
   7272 -            ivLength = baseEngine.getBlockSize();
   7273 -            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
   7274 -                        new GOFBBlockCipher(baseEngine)));
   7275 -        }
   7276 +        // BEGIN android-removed
   7277 +        // else if (modeName.startsWith("GOFB"))
   7278 +        // {
   7279 +        //     ivLength = baseEngine.getBlockSize();
   7280 +        //     cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
   7281 +        //                 new GOFBBlockCipher(baseEngine)));
   7282 +        // }
   7283 +        // END android-removed
   7284          else if (modeName.startsWith("CTS"))
   7285          {
   7286              ivLength = baseEngine.getBlockSize();
   7287 @@ -278,11 +300,13 @@
   7288              ivLength = baseEngine.getBlockSize();
   7289              cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));
   7290          }
   7291 -        else if (modeName.startsWith("EAX"))
   7292 -        {
   7293 -            ivLength = baseEngine.getBlockSize();
   7294 -            cipher = new AEADGenericBlockCipher(new EAXBlockCipher(baseEngine));
   7295 -        }
   7296 +        // BEGIN android-removed
   7297 +        // else if (modeName.startsWith("EAX"))
   7298 +        // {
   7299 +        //     ivLength = baseEngine.getBlockSize();
   7300 +        //     cipher = new AEADGenericBlockCipher(new EAXBlockCipher(baseEngine));
   7301 +        // }
   7302 +        // END android-removed
   7303          else if (modeName.startsWith("GCM"))
   7304          {
   7305              ivLength = baseEngine.getBlockSize();
   7306 @@ -371,13 +395,15 @@
   7307              throw new InvalidKeyException("Key for algorithm " + key.getAlgorithm() + " not suitable for symmetric enryption.");
   7308          }
   7309          
   7310 -        //
   7311 -        // for RC5-64 we must have some default parameters
   7312 -        //
   7313 -        if (params == null && baseEngine.getAlgorithmName().startsWith("RC5-64"))
   7314 -        {
   7315 -            throw new InvalidAlgorithmParameterException("RC5 requires an RC5ParametersSpec to be passed in.");
   7316 -        }
   7317 +        // BEGIN android-removed
   7318 +        // //
   7319 +        // // for RC5-64 we must have some default parameters
   7320 +        // //
   7321 +        // if (params == null && baseEngine.getAlgorithmName().startsWith("RC5-64"))
   7322 +        // {
   7323 +        //     throw new InvalidAlgorithmParameterException("RC5 requires an RC5ParametersSpec to be passed in.");
   7324 +        // }
   7325 +        // END android-removed
   7326  
   7327          //
   7328          // a note on iv's - if ivLength is zero the IV gets ignored (we don't use it).
   7329 @@ -451,63 +477,65 @@
   7330                  param = new KeyParameter(key.getEncoded());
   7331              }
   7332          }
   7333 -        else if (params instanceof GOST28147ParameterSpec)
   7334 -        {
   7335 -            GOST28147ParameterSpec    gost28147Param = (GOST28147ParameterSpec)params;
   7336 -
   7337 -            param = new ParametersWithSBox(
   7338 -                       new KeyParameter(key.getEncoded()), ((GOST28147ParameterSpec)params).getSbox());
   7339 -
   7340 -            if (gost28147Param.getIV() != null && ivLength != 0)
   7341 -            {
   7342 -                param = new ParametersWithIV(param, gost28147Param.getIV());
   7343 -                ivParam = (ParametersWithIV)param;
   7344 -            }
   7345 -        }
   7346 -        else if (params instanceof RC2ParameterSpec)
   7347 -        {
   7348 -            RC2ParameterSpec    rc2Param = (RC2ParameterSpec)params;
   7349 -
   7350 -            param = new RC2Parameters(key.getEncoded(), ((RC2ParameterSpec)params).getEffectiveKeyBits());
   7351 -
   7352 -            if (rc2Param.getIV() != null && ivLength != 0)
   7353 -            {
   7354 -                param = new ParametersWithIV(param, rc2Param.getIV());
   7355 -                ivParam = (ParametersWithIV)param;
   7356 -            }
   7357 -        }
   7358 -        else if (params instanceof RC5ParameterSpec)
   7359 -        {
   7360 -            RC5ParameterSpec    rc5Param = (RC5ParameterSpec)params;
   7361 -
   7362 -            param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
   7363 -            if (baseEngine.getAlgorithmName().startsWith("RC5"))
   7364 -            {
   7365 -                if (baseEngine.getAlgorithmName().equals("RC5-32"))
   7366 -                {
   7367 -                    if (rc5Param.getWordSize() != 32)
   7368 -                    {
   7369 -                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 32 not " + rc5Param.getWordSize() + ".");
   7370 -                    }
   7371 -                }
   7372 -                else if (baseEngine.getAlgorithmName().equals("RC5-64"))
   7373 -                {
   7374 -                    if (rc5Param.getWordSize() != 64)
   7375 -                    {
   7376 -                        throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 64 not " + rc5Param.getWordSize() + ".");
   7377 -                    }
   7378 -                }
   7379 -            }
   7380 -            else
   7381 -            {
   7382 -                throw new InvalidAlgorithmParameterException("RC5 parameters passed to a cipher that is not RC5.");
   7383 -            }
   7384 -            if ((rc5Param.getIV() != null) && (ivLength != 0))
   7385 -            {
   7386 -                param = new ParametersWithIV(param, rc5Param.getIV());
   7387 -                ivParam = (ParametersWithIV)param;
   7388 -            }
   7389 -        }
   7390 +        // BEGIN android-removed
   7391 +        // else if (params instanceof GOST28147ParameterSpec)
   7392 +        // {
   7393 +        //     GOST28147ParameterSpec    gost28147Param = (GOST28147ParameterSpec)params;
   7394 +        //
   7395 +        //     param = new ParametersWithSBox(
   7396 +        //                new KeyParameter(key.getEncoded()), ((GOST28147ParameterSpec)params).getSbox());
   7397 +        //
   7398 +        //     if (gost28147Param.getIV() != null && ivLength != 0)
   7399 +        //     {
   7400 +        //         param = new ParametersWithIV(param, gost28147Param.getIV());
   7401 +        //         ivParam = (ParametersWithIV)param;
   7402 +        //     }
   7403 +        // }
   7404 +        // else if (params instanceof RC2ParameterSpec)
   7405 +        // {
   7406 +        //     RC2ParameterSpec    rc2Param = (RC2ParameterSpec)params;
   7407 +        //
   7408 +        //     param = new RC2Parameters(key.getEncoded(), ((RC2ParameterSpec)params).getEffectiveKeyBits());
   7409 +        //
   7410 +        //     if (rc2Param.getIV() != null && ivLength != 0)
   7411 +        //     {
   7412 +        //         param = new ParametersWithIV(param, rc2Param.getIV());
   7413 +        //         ivParam = (ParametersWithIV)param;
   7414 +        //     }
   7415 +        // }
   7416 +        // else if (params instanceof RC5ParameterSpec)
   7417 +        // {
   7418 +        //     RC5ParameterSpec    rc5Param = (RC5ParameterSpec)params;
   7419 +        //
   7420 +        //     param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
   7421 +        //     if (baseEngine.getAlgorithmName().startsWith("RC5"))
   7422 +        //     {
   7423 +        //         if (baseEngine.getAlgorithmName().equals("RC5-32"))
   7424 +        //         {
   7425 +        //             if (rc5Param.getWordSize() != 32)
   7426 +        //             {
   7427 +        //                 throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 32 not " + rc5Param.getWordSize() + ".");
   7428 +        //             }
   7429 +        //         }
   7430 +        //         else if (baseEngine.getAlgorithmName().equals("RC5-64"))
   7431 +        //         {
   7432 +        //             if (rc5Param.getWordSize() != 64)
   7433 +        //             {
   7434 +        //                 throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 64 not " + rc5Param.getWordSize() + ".");
   7435 +        //             }
   7436 +        //         }
   7437 +        //     }
   7438 +        //     else
   7439 +        //     {
   7440 +        //         throw new InvalidAlgorithmParameterException("RC5 parameters passed to a cipher that is not RC5.");
   7441 +        //     }
   7442 +        //     if ((rc5Param.getIV() != null) && (ivLength != 0))
   7443 +        //     {
   7444 +        //         param = new ParametersWithIV(param, rc5Param.getIV());
   7445 +        //         ivParam = (ParametersWithIV)param;
   7446 +        //     }
   7447 +        // }
   7448 +        // END android-removed
   7449          else
   7450          {
   7451              throw new InvalidAlgorithmParameterException("unknown parameter type.");
   7452 @@ -711,10 +739,21 @@
   7453          int     inputLen,
   7454          byte[]  output,
   7455          int     outputOffset) 
   7456 -        throws IllegalBlockSizeException, BadPaddingException
   7457 +        throws IllegalBlockSizeException, BadPaddingException, ShortBufferException
   7458      {
   7459 +        // BEGIN android-note
   7460 +        // added ShortBufferException to the throws statement
   7461 +        // END android-note
   7462          int     len = 0;
   7463  
   7464 +        // BEGIN android-added
   7465 +        int outputLen = cipher.getOutputSize(inputLen);
   7466 +
   7467 +        if (outputLen + outputOffset > output.length) {
   7468 +            throw new ShortBufferException("need at least " + outputLen + " bytes");
   7469 +        }
   7470 +        // BEGIN android-added
   7471 +
   7472          if (inputLen != 0)
   7473          {
   7474                  len = cipher.processBytes(input, inputOffset, inputLen, output, outputOffset);
   7475 @@ -756,62 +795,64 @@
   7476          }
   7477      }
   7478  
   7479 -    /**
   7480 -     * DESCBC
   7481 -     */
   7482 -    static public class DESCBC
   7483 -        extends JCEBlockCipher
   7484 -    {
   7485 -        public DESCBC()
   7486 -        {
   7487 -            super(new CBCBlockCipher(new DESEngine()), 64);
   7488 -        }
   7489 -    }
   7490 -
   7491 -    /**
   7492 -     *  GOST28147
   7493 -     */
   7494 -    static public class GOST28147
   7495 -        extends JCEBlockCipher
   7496 -    {
   7497 -        public GOST28147()
   7498 -        {
   7499 -            super(new GOST28147Engine());
   7500 -        }
   7501 -    }
   7502 -    
   7503 -    static public class GOST28147cbc
   7504 -        extends JCEBlockCipher
   7505 -    {
   7506 -        public GOST28147cbc()
   7507 -        {
   7508 -            super(new CBCBlockCipher(new GOST28147Engine()), 64);
   7509 -        }
   7510 -    }
   7511 -
   7512 -    /**
   7513 -     * RC2
   7514 -     */
   7515 -    static public class RC2
   7516 -        extends JCEBlockCipher
   7517 -    {
   7518 -        public RC2()
   7519 -        {
   7520 -            super(new RC2Engine());
   7521 -        }
   7522 -    }
   7523 -
   7524 -    /**
   7525 -     * RC2CBC
   7526 -     */
   7527 -    static public class RC2CBC
   7528 -        extends JCEBlockCipher
   7529 -    {
   7530 -        public RC2CBC()
   7531 -        {
   7532 -            super(new CBCBlockCipher(new RC2Engine()), 64);
   7533 -        }
   7534 -    }
   7535 +    // BEGIN android-removed
   7536 +    // /**
   7537 +    //  * DESCBC
   7538 +    //  */
   7539 +    // static public class DESCBC
   7540 +    //     extends JCEBlockCipher
   7541 +    // {
   7542 +    //     public DESCBC()
   7543 +    //     {
   7544 +    //         super(new CBCBlockCipher(new DESEngine()), 64);
   7545 +    //     }
   7546 +    // }
   7547 +    //
   7548 +    // /**
   7549 +    //  *  GOST28147
   7550 +    //  */
   7551 +    // static public class GOST28147
   7552 +    //     extends JCEBlockCipher
   7553 +    // {
   7554 +    //     public GOST28147()
   7555 +    //     {
   7556 +    //         super(new GOST28147Engine());
   7557 +    //     }
   7558 +    // }
   7559 +    //
   7560 +    // static public class GOST28147cbc
   7561 +    //     extends JCEBlockCipher
   7562 +    // {
   7563 +    //     public GOST28147cbc()
   7564 +    //     {
   7565 +    //         super(new CBCBlockCipher(new GOST28147Engine()), 64);
   7566 +    //     }
   7567 +    // }
   7568 +    //
   7569 +    // /**
   7570 +    //  * RC2
   7571 +    //  */
   7572 +    // static public class RC2
   7573 +    //     extends JCEBlockCipher
   7574 +    // {
   7575 +    //     public RC2()
   7576 +    //     {
   7577 +    //         super(new RC2Engine());
   7578 +    //     }
   7579 +    // }
   7580 +    //
   7581 +    // /**
   7582 +    //  * RC2CBC
   7583 +    //  */
   7584 +    // static public class RC2CBC
   7585 +    //     extends JCEBlockCipher
   7586 +    // {
   7587 +    //     public RC2CBC()
   7588 +    //     {
   7589 +    //         super(new CBCBlockCipher(new RC2Engine()), 64);
   7590 +    //     }
   7591 +    // }
   7592 +    // END android-removed
   7593  
   7594      /**
   7595       * PBEWithMD5AndDES
   7596 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEECPrivateKey.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEECPrivateKey.java
   7597 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEECPrivateKey.java	2012-03-22 15:11:48.000000000 +0000
   7598 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEECPrivateKey.java	2012-09-19 21:17:12.000000000 +0000
   7599 @@ -20,8 +20,10 @@
   7600  import org.bouncycastle.asn1.DERInteger;
   7601  import org.bouncycastle.asn1.DERNull;
   7602  import org.bouncycastle.asn1.DERObjectIdentifier;
   7603 -import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   7604 -import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   7605 +// BEGIN android-removed
   7606 +// import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   7607 +// import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   7608 +// END android-removed
   7609  import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
   7610  import org.bouncycastle.asn1.sec.ECPrivateKeyStructure;
   7611  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   7612 @@ -203,21 +205,23 @@
   7613              ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());
   7614              X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
   7615  
   7616 -            if (ecP == null) // GOST Curve
   7617 -            {
   7618 -                ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
   7619 -                EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
   7620 -
   7621 -                ecSpec = new ECNamedCurveSpec(
   7622 -                        ECGOST3410NamedCurves.getName(oid),
   7623 -                        ellipticCurve,
   7624 -                        new ECPoint(
   7625 -                                gParam.getG().getX().toBigInteger(),
   7626 -                                gParam.getG().getY().toBigInteger()),
   7627 -                        gParam.getN(),
   7628 -                        gParam.getH());
   7629 -            }
   7630 -            else
   7631 +            // BEGIN android-removed
   7632 +            // if (ecP == null) // GOST Curve
   7633 +            // {
   7634 +            //     ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
   7635 +            //     EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
   7636 +            //
   7637 +            //     ecSpec = new ECNamedCurveSpec(
   7638 +            //             ECGOST3410NamedCurves.getName(oid),
   7639 +            //             ellipticCurve,
   7640 +            //             new ECPoint(
   7641 +            //                     gParam.getG().getX().toBigInteger(),
   7642 +            //                     gParam.getG().getY().toBigInteger()),
   7643 +            //             gParam.getN(),
   7644 +            //             gParam.getH());
   7645 +            // }
   7646 +            // else
   7647 +            // END android-removed
   7648              {
   7649                  EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
   7650  
   7651 @@ -331,11 +335,13 @@
   7652  
   7653          try
   7654          {
   7655 -            if (algorithm.equals("ECGOST3410"))
   7656 -            {
   7657 -                info = new PrivateKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params.toASN1Primitive()), keyStructure.toASN1Primitive());
   7658 -            }
   7659 -            else
   7660 +            // BEGIN android-removed
   7661 +            // if (algorithm.equals("ECGOST3410"))
   7662 +            // {
   7663 +            //     info = new PrivateKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params.toASN1Primitive()), keyStructure.toASN1Primitive());
   7664 +            // }
   7665 +            // else
   7666 +            // END android-removed
   7667              {
   7668  
   7669                  info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.toASN1Primitive()), keyStructure.toASN1Primitive());
   7670 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEECPublicKey.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEECPublicKey.java
   7671 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEECPublicKey.java	2012-03-22 15:11:48.000000000 +0000
   7672 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEECPublicKey.java	2012-09-19 21:17:12.000000000 +0000
   7673 @@ -18,9 +18,11 @@
   7674  import org.bouncycastle.asn1.DERBitString;
   7675  import org.bouncycastle.asn1.DERNull;
   7676  import org.bouncycastle.asn1.DEROctetString;
   7677 -import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   7678 -import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   7679 -import org.bouncycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters;
   7680 +// BEGIN android-removed
   7681 +// import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   7682 +// import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
   7683 +// import org.bouncycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters;
   7684 +// END android-removed
   7685  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   7686  import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
   7687  import org.bouncycastle.asn1.x9.X962Parameters;
   7688 @@ -33,9 +35,13 @@
   7689  import org.bouncycastle.jcajce.provider.asymmetric.ec.EC5Util;
   7690  import org.bouncycastle.jcajce.provider.asymmetric.ec.ECUtil;
   7691  import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil;
   7692 -import org.bouncycastle.jce.ECGOST3410NamedCurveTable;
   7693 +// BEGIN android-removed
   7694 +// import org.bouncycastle.jce.ECGOST3410NamedCurveTable;
   7695 +// END android-removed
   7696  import org.bouncycastle.jce.interfaces.ECPointEncoder;
   7697 -import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
   7698 +// BEGIN android-removed
   7699 +// import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
   7700 +// END android-removed
   7701  import org.bouncycastle.jce.spec.ECNamedCurveSpec;
   7702  import org.bouncycastle.math.ec.ECCurve;
   7703  
   7704 @@ -46,7 +52,9 @@
   7705      private org.bouncycastle.math.ec.ECPoint q;
   7706      private ECParameterSpec         ecSpec;
   7707      private boolean                 withCompression;
   7708 -    private GOST3410PublicKeyAlgParameters       gostParams;
   7709 +    // BEGIN android-removed
   7710 +    // private GOST3410PublicKeyAlgParameters       gostParams;
   7711 +    // END android-removed
   7712  
   7713      public JCEECPublicKey(
   7714          String              algorithm,
   7715 @@ -56,7 +64,9 @@
   7716          this.q = key.q;
   7717          this.ecSpec = key.ecSpec;
   7718          this.withCompression = key.withCompression;
   7719 -        this.gostParams = key.gostParams;
   7720 +        // BEGIN android-removed
   7721 +        // this.gostParams = key.gostParams;
   7722 +        // END android-removed
   7723      }
   7724      
   7725      public JCEECPublicKey(
   7726 @@ -179,54 +189,56 @@
   7727  
   7728      private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
   7729      {
   7730 -        if (info.getAlgorithmId().getObjectId().equals(CryptoProObjectIdentifiers.gostR3410_2001))
   7731 -        {
   7732 -            DERBitString bits = info.getPublicKeyData();
   7733 -            ASN1OctetString key;
   7734 -            this.algorithm = "ECGOST3410";
   7735 -
   7736 -            try
   7737 -            {
   7738 -                key = (ASN1OctetString) ASN1Primitive.fromByteArray(bits.getBytes());
   7739 -            }
   7740 -            catch (IOException ex)
   7741 -            {
   7742 -                throw new IllegalArgumentException("error recovering public key");
   7743 -            }
   7744 -
   7745 -            byte[]          keyEnc = key.getOctets();
   7746 -            byte[]          x = new byte[32];
   7747 -            byte[]          y = new byte[32];
   7748 -
   7749 -            for (int i = 0; i != x.length; i++)
   7750 -            {
   7751 -                x[i] = keyEnc[32 - 1 - i];
   7752 -            }
   7753 -
   7754 -            for (int i = 0; i != y.length; i++)
   7755 -            {
   7756 -                y[i] = keyEnc[64 - 1 - i];
   7757 -            }
   7758 -
   7759 -            gostParams = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
   7760 -
   7761 -            ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));
   7762 -
   7763 -            ECCurve curve = spec.getCurve();
   7764 -            EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());
   7765 -
   7766 -            this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y), false);
   7767 -
   7768 -            ecSpec = new ECNamedCurveSpec(
   7769 -                    ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
   7770 -                    ellipticCurve,
   7771 -                    new ECPoint(
   7772 -                            spec.getG().getX().toBigInteger(),
   7773 -                            spec.getG().getY().toBigInteger()),
   7774 -                            spec.getN(), spec.getH());
   7775 -
   7776 -        }
   7777 -        else
   7778 +        // BEGIN android-removed
   7779 +        // if (info.getAlgorithmId().getObjectId().equals(CryptoProObjectIdentifiers.gostR3410_2001))
   7780 +        // {
   7781 +        //     DERBitString bits = info.getPublicKeyData();
   7782 +        //     ASN1OctetString key;
   7783 +        //     this.algorithm = "ECGOST3410";
   7784 +        //
   7785 +        //     try
   7786 +        //     {
   7787 +        //         key = (ASN1OctetString) ASN1Primitive.fromByteArray(bits.getBytes());
   7788 +        //     }
   7789 +        //     catch (IOException ex)
   7790 +        //     {
   7791 +        //         throw new IllegalArgumentException("error recovering public key");
   7792 +        //     }
   7793 +        //
   7794 +        //     byte[]          keyEnc = key.getOctets();
   7795 +        //     byte[]          x = new byte[32];
   7796 +        //     byte[]          y = new byte[32];
   7797 +        //
   7798 +        //     for (int i = 0; i != x.length; i++)
   7799 +        //     {
   7800 +        //         x[i] = keyEnc[32 - 1 - i];
   7801 +        //     }
   7802 +        //
   7803 +        //     for (int i = 0; i != y.length; i++)
   7804 +        //     {
   7805 +        //         y[i] = keyEnc[64 - 1 - i];
   7806 +        //     }
   7807 +        //
   7808 +        //     gostParams = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
   7809 +        //
   7810 +        //     ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));
   7811 +        //
   7812 +        //     ECCurve curve = spec.getCurve();
   7813 +        //     EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());
   7814 +        //
   7815 +        //     this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y), false);
   7816 +        //
   7817 +        //     ecSpec = new ECNamedCurveSpec(
   7818 +        //             ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
   7819 +        //             ellipticCurve,
   7820 +        //             new ECPoint(
   7821 +        //                     spec.getG().getX().toBigInteger(),
   7822 +        //                     spec.getG().getY().toBigInteger()),
   7823 +        //                     spec.getN(), spec.getH());
   7824 +        //
   7825 +        // }
   7826 +        // else
   7827 +        // END android-removed
   7828          {
   7829              X962Parameters params = new X962Parameters((ASN1Primitive)info.getAlgorithmId().getParameters());
   7830              ECCurve                 curve;
   7831 @@ -315,45 +327,47 @@
   7832          ASN1Encodable        params;
   7833          SubjectPublicKeyInfo info;
   7834  
   7835 -        if (algorithm.equals("ECGOST3410"))
   7836 -        {
   7837 -            if (gostParams != null)
   7838 -            {
   7839 -                params = gostParams;
   7840 -            }
   7841 -            else
   7842 -            {
   7843 -                if (ecSpec instanceof ECNamedCurveSpec)
   7844 -                {
   7845 -                    params = new GOST3410PublicKeyAlgParameters(
   7846 -                                   ECGOST3410NamedCurves.getOID(((ECNamedCurveSpec)ecSpec).getName()),
   7847 -                                   CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet);
   7848 -                }
   7849 -                else
   7850 -                {   // strictly speaking this may not be applicable...
   7851 -                    ECCurve curve = EC5Util.convertCurve(ecSpec.getCurve());
   7852 -
   7853 -                    X9ECParameters ecP = new X9ECParameters(
   7854 -                        curve,
   7855 -                        EC5Util.convertPoint(curve, ecSpec.getGenerator(), withCompression),
   7856 -                        ecSpec.getOrder(),
   7857 -                        BigInteger.valueOf(ecSpec.getCofactor()),
   7858 -                        ecSpec.getCurve().getSeed());
   7859 -
   7860 -                    params = new X962Parameters(ecP);
   7861 -                }
   7862 -            }
   7863 -
   7864 -            BigInteger      bX = this.q.getX().toBigInteger();
   7865 -            BigInteger      bY = this.q.getY().toBigInteger();
   7866 -            byte[]          encKey = new byte[64];
   7867 -
   7868 -            extractBytes(encKey, 0, bX);
   7869 -            extractBytes(encKey, 32, bY);
   7870 -
   7871 -            info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params), new DEROctetString(encKey));
   7872 -        }
   7873 -        else
   7874 +        // BEGIN android-removed
   7875 +        // if (algorithm.equals("ECGOST3410"))
   7876 +        // {
   7877 +        //     if (gostParams != null)
   7878 +        //     {
   7879 +        //         params = gostParams;
   7880 +        //     }
   7881 +        //     else
   7882 +        //     {
   7883 +        //         if (ecSpec instanceof ECNamedCurveSpec)
   7884 +        //         {
   7885 +        //             params = new GOST3410PublicKeyAlgParameters(
   7886 +        //                            ECGOST3410NamedCurves.getOID(((ECNamedCurveSpec)ecSpec).getName()),
   7887 +        //                            CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet);
   7888 +        //         }
   7889 +        //         else
   7890 +        //         {   // strictly speaking this may not be applicable...
   7891 +        //             ECCurve curve = EC5Util.convertCurve(ecSpec.getCurve());
   7892 +        //
   7893 +        //             X9ECParameters ecP = new X9ECParameters(
   7894 +        //                 curve,
   7895 +        //                 EC5Util.convertPoint(curve, ecSpec.getGenerator(), withCompression),
   7896 +        //                 ecSpec.getOrder(),
   7897 +        //                 BigInteger.valueOf(ecSpec.getCofactor()),
   7898 +        //                 ecSpec.getCurve().getSeed());
   7899 +        //
   7900 +        //             params = new X962Parameters(ecP);
   7901 +        //         }
   7902 +        //     }
   7903 +        //
   7904 +        //     BigInteger      bX = this.q.getX().toBigInteger();
   7905 +        //     BigInteger      bY = this.q.getY().toBigInteger();
   7906 +        //     byte[]          encKey = new byte[64];
   7907 +        //
   7908 +        //     extractBytes(encKey, 0, bX);
   7909 +        //     extractBytes(encKey, 32, bY);
   7910 +        //
   7911 +        //     info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params), new DEROctetString(encKey));
   7912 +        // }
   7913 +        // else
   7914 +        // END android-removed
   7915          {
   7916              if (ecSpec instanceof ECNamedCurveSpec)
   7917              {
   7918 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEMac.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEMac.java
   7919 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEMac.java	2012-03-22 15:11:48.000000000 +0000
   7920 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEMac.java	2012-09-19 21:17:12.000000000 +0000
   7921 @@ -11,24 +11,35 @@
   7922  
   7923  import org.bouncycastle.crypto.CipherParameters;
   7924  import org.bouncycastle.crypto.Mac;
   7925 -import org.bouncycastle.crypto.digests.MD2Digest;
   7926 -import org.bouncycastle.crypto.digests.MD4Digest;
   7927 -import org.bouncycastle.crypto.digests.MD5Digest;
   7928 -import org.bouncycastle.crypto.digests.RIPEMD128Digest;
   7929 -import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   7930 -import org.bouncycastle.crypto.digests.SHA1Digest;
   7931 -import org.bouncycastle.crypto.digests.SHA224Digest;
   7932 -import org.bouncycastle.crypto.digests.SHA256Digest;
   7933 -import org.bouncycastle.crypto.digests.SHA384Digest;
   7934 -import org.bouncycastle.crypto.digests.SHA512Digest;
   7935 -import org.bouncycastle.crypto.digests.TigerDigest;
   7936 +// BEGIN android-removed
   7937 +// import org.bouncycastle.crypto.digests.MD2Digest;
   7938 +// import org.bouncycastle.crypto.digests.MD4Digest;
   7939 +// import org.bouncycastle.crypto.digests.MD5Digest;
   7940 +// import org.bouncycastle.crypto.digests.RIPEMD128Digest;
   7941 +// import org.bouncycastle.crypto.digests.RIPEMD160Digest;
   7942 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   7943 +// import org.bouncycastle.crypto.digests.SHA224Digest;
   7944 +// import org.bouncycastle.crypto.digests.SHA256Digest;
   7945 +// import org.bouncycastle.crypto.digests.SHA384Digest;
   7946 +// import org.bouncycastle.crypto.digests.SHA512Digest;
   7947 +// import org.bouncycastle.crypto.digests.TigerDigest;
   7948 +// END android-removed
   7949 +// BEGIN android-added
   7950 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   7951 +// END android-added
   7952  import org.bouncycastle.crypto.engines.DESEngine;
   7953 -import org.bouncycastle.crypto.engines.RC2Engine;
   7954 +// BEGIN android-removed
   7955 +// import org.bouncycastle.crypto.engines.RC2Engine;
   7956 +// END android-removed
   7957  import org.bouncycastle.crypto.macs.CBCBlockCipherMac;
   7958 -import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   7959 +// BEGIN android-removed
   7960 +// import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
   7961 +// END android-removed
   7962  import org.bouncycastle.crypto.macs.HMac;
   7963 -import org.bouncycastle.crypto.macs.ISO9797Alg3Mac;
   7964 -import org.bouncycastle.crypto.macs.OldHMac;
   7965 +// BEGIN android-removed
   7966 +// import org.bouncycastle.crypto.macs.ISO9797Alg3Mac;
   7967 +// import org.bouncycastle.crypto.macs.OldHMac;
   7968 +// END android-removed
   7969  import org.bouncycastle.crypto.paddings.ISO7816d4Padding;
   7970  import org.bouncycastle.crypto.params.KeyParameter;
   7971  import org.bouncycastle.crypto.params.ParametersWithIV;
   7972 @@ -144,109 +155,111 @@
   7973       * the classes that extend directly off us.
   7974       */
   7975  
   7976 -    /**
   7977 -     * DES
   7978 -     */
   7979 -    public static class DES
   7980 -        extends JCEMac
   7981 -    {
   7982 -        public DES()
   7983 -        {
   7984 -            super(new CBCBlockCipherMac(new DESEngine()));
   7985 -        }
   7986 -    }
   7987 -
   7988 -    /**
   7989 -     * DES 64 bit MAC
   7990 -     */
   7991 -    public static class DES64
   7992 -        extends JCEMac
   7993 -    {
   7994 -        public DES64()
   7995 -        {
   7996 -            super(new CBCBlockCipherMac(new DESEngine(), 64));
   7997 -        }
   7998 -    }
   7999 -
   8000 -    /**
   8001 -     * RC2
   8002 -     */
   8003 -    public static class RC2
   8004 -        extends JCEMac
   8005 -    {
   8006 -        public RC2()
   8007 -        {
   8008 -            super(new CBCBlockCipherMac(new RC2Engine()));
   8009 -        }
   8010 -    }
   8011 -
   8012 -
   8013 -    
   8014 -
   8015 -    /**
   8016 -     * DES
   8017 -     */
   8018 -    public static class DESCFB8
   8019 -        extends JCEMac
   8020 -    {
   8021 -        public DESCFB8()
   8022 -        {
   8023 -            super(new CFBBlockCipherMac(new DESEngine()));
   8024 -        }
   8025 -    }
   8026 -
   8027 -    /**
   8028 -     * RC2CFB8
   8029 -     */
   8030 -
   8031 -
   8032 -    /**
   8033 -     * DES9797Alg3with7816-4Padding
   8034 -     */
   8035 -    public static class DES9797Alg3with7816d4
   8036 -        extends JCEMac
   8037 -    {
   8038 -        public DES9797Alg3with7816d4()
   8039 -        {
   8040 -            super(new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()));
   8041 -        }
   8042 -    }
   8043 -
   8044 -    /**
   8045 -     * DES9797Alg3
   8046 -     */
   8047 -    public static class DES9797Alg3
   8048 -        extends JCEMac
   8049 -    {
   8050 -        public DES9797Alg3()
   8051 -        {
   8052 -            super(new ISO9797Alg3Mac(new DESEngine()));
   8053 -        }
   8054 -    }
   8055 -
   8056 -    /**
   8057 -     * MD2 HMac
   8058 -     */
   8059 -    public static class MD2
   8060 -        extends JCEMac
   8061 -    {
   8062 -        public MD2()
   8063 -        {
   8064 -            super(new HMac(new MD2Digest()));
   8065 -        }
   8066 -    }
   8067 -
   8068 -    /**
   8069 -     * MD4 HMac
   8070 -     */
   8071 -    public static class MD4
   8072 -        extends JCEMac
   8073 -    {
   8074 -        public MD4()
   8075 -        {
   8076 -            super(new HMac(new MD4Digest()));
   8077 -        }
   8078 -    }
   8079 +    // BEGIN android-removed
   8080 +    // /**
   8081 +    //  * DES
   8082 +    //  */
   8083 +    // public static class DES
   8084 +    //     extends JCEMac
   8085 +    // {
   8086 +    //     public DES()
   8087 +    //     {
   8088 +    //         super(new CBCBlockCipherMac(new DESEngine()));
   8089 +    //     }
   8090 +    // }
   8091 +    //
   8092 +    // /**
   8093 +    //  * DES 64 bit MAC
   8094 +    //  */
   8095 +    // public static class DES64
   8096 +    //     extends JCEMac
   8097 +    // {
   8098 +    //     public DES64()
   8099 +    //     {
   8100 +    //         super(new CBCBlockCipherMac(new DESEngine(), 64));
   8101 +    //     }
   8102 +    // }
   8103 +    //
   8104 +    // /**
   8105 +    //  * RC2
   8106 +    //  */
   8107 +    // public static class RC2
   8108 +    //     extends JCEMac
   8109 +    // {
   8110 +    //     public RC2()
   8111 +    //     {
   8112 +    //         super(new CBCBlockCipherMac(new RC2Engine()));
   8113 +    //     }
   8114 +    // }
   8115 +    //
   8116 +    //
   8117 +    //
   8118 +    //
   8119 +    // /**
   8120 +    //  * DES
   8121 +    //  */
   8122 +    // public static class DESCFB8
   8123 +    //     extends JCEMac
   8124 +    // {
   8125 +    //     public DESCFB8()
   8126 +    //     {
   8127 +    //         super(new CFBBlockCipherMac(new DESEngine()));
   8128 +    //     }
   8129 +    // }
   8130 +    //
   8131 +    // /**
   8132 +    //  * RC2CFB8
   8133 +    //  */
   8134 +    //
   8135 +    //
   8136 +    // /**
   8137 +    //  * DES9797Alg3with7816-4Padding
   8138 +    //  */
   8139 +    // public static class DES9797Alg3with7816d4
   8140 +    //     extends JCEMac
   8141 +    // {
   8142 +    //     public DES9797Alg3with7816d4()
   8143 +    //     {
   8144 +    //         super(new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()));
   8145 +    //     }
   8146 +    // }
   8147 +    //
   8148 +    // /**
   8149 +    //  * DES9797Alg3
   8150 +    //  */
   8151 +    // public static class DES9797Alg3
   8152 +    //     extends JCEMac
   8153 +    // {
   8154 +    //     public DES9797Alg3()
   8155 +    //     {
   8156 +    //         super(new ISO9797Alg3Mac(new DESEngine()));
   8157 +    //     }
   8158 +    // }
   8159 +    //
   8160 +    // /**
   8161 +    //  * MD2 HMac
   8162 +    //  */
   8163 +    // public static class MD2
   8164 +    //     extends JCEMac
   8165 +    // {
   8166 +    //     public MD2()
   8167 +    //     {
   8168 +    //         super(new HMac(new MD2Digest()));
   8169 +    //     }
   8170 +    // }
   8171 +    //
   8172 +    // /**
   8173 +    //  * MD4 HMac
   8174 +    //  */
   8175 +    // public static class MD4
   8176 +    //     extends JCEMac
   8177 +    // {
   8178 +    //     public MD4()
   8179 +    //     {
   8180 +    //         super(new HMac(new MD4Digest()));
   8181 +    //     }
   8182 +    // }
   8183 +    // END android-removed
   8184  
   8185      /**
   8186       * MD5 HMac
   8187 @@ -256,7 +269,9 @@
   8188      {
   8189          public MD5()
   8190          {
   8191 -            super(new HMac(new MD5Digest()));
   8192 +            // BEGIN android-changed
   8193 +            super(new HMac(AndroidDigestFactory.getMD5()));
   8194 +            // END android-changed
   8195          }
   8196      }
   8197  
   8198 @@ -268,21 +283,25 @@
   8199      {
   8200          public SHA1()
   8201          {
   8202 -            super(new HMac(new SHA1Digest()));
   8203 +            // BEGIN android-changed
   8204 +            super(new HMac(AndroidDigestFactory.getSHA1()));
   8205 +            // END android-changed
   8206          }
   8207      }
   8208  
   8209 -    /**
   8210 -     * SHA-224 HMac
   8211 -     */
   8212 -    public static class SHA224
   8213 -        extends JCEMac
   8214 -    {
   8215 -        public SHA224()
   8216 -        {
   8217 -            super(new HMac(new SHA224Digest()));
   8218 -        }
   8219 -    }
   8220 +    // BEGIN android-removed
   8221 +    // /**
   8222 +    //  * SHA-224 HMac
   8223 +    //  */
   8224 +    // public static class SHA224
   8225 +    //     extends JCEMac
   8226 +    // {
   8227 +    //     public SHA224()
   8228 +    //     {
   8229 +    //         super(new HMac(new SHA224Digest()));
   8230 +    //     }
   8231 +    // }
   8232 +    // END android-removed
   8233      
   8234      /**
   8235       * SHA-256 HMac
   8236 @@ -292,7 +311,9 @@
   8237      {
   8238          public SHA256()
   8239          {
   8240 -            super(new HMac(new SHA256Digest()));
   8241 +            // BEGIN android-changed
   8242 +            super(new HMac(AndroidDigestFactory.getSHA256()));
   8243 +            // END android-changed
   8244          }
   8245      }
   8246  
   8247 @@ -304,18 +325,22 @@
   8248      {
   8249          public SHA384()
   8250          {
   8251 -            super(new HMac(new SHA384Digest()));
   8252 +            // BEGIN android-changed
   8253 +            super(new HMac(AndroidDigestFactory.getSHA384()));
   8254 +            // END android-changed
   8255          }
   8256      }
   8257  
   8258 -    public static class OldSHA384
   8259 -        extends JCEMac
   8260 -    {
   8261 -        public OldSHA384()
   8262 -        {
   8263 -            super(new OldHMac(new SHA384Digest()));
   8264 -        }
   8265 -    }
   8266 +    // BEGIN android-removed
   8267 +    // public static class OldSHA384
   8268 +    //     extends JCEMac
   8269 +    // {
   8270 +    //     public OldSHA384()
   8271 +    //     {
   8272 +    //         super(new OldHMac(new SHA384Digest()));
   8273 +    //     }
   8274 +    // }
   8275 +    // END android-removed
   8276      
   8277      /**
   8278       * SHA-512 HMac
   8279 @@ -325,75 +350,80 @@
   8280      {
   8281          public SHA512()
   8282          {
   8283 -            super(new HMac(new SHA512Digest()));
   8284 +            // BEGIN android-changed
   8285 +            super(new HMac(AndroidDigestFactory.getSHA512()));
   8286 +            // END android-changed
   8287          }
   8288      }
   8289  
   8290 -    /**
   8291 -     * SHA-512 HMac
   8292 -     */
   8293 -    public static class OldSHA512
   8294 -        extends JCEMac
   8295 -    {
   8296 -        public OldSHA512()
   8297 -        {
   8298 -            super(new OldHMac(new SHA512Digest()));
   8299 -        }
   8300 -    }
   8301      
   8302 -    /**
   8303 -     * RIPEMD128 HMac
   8304 -     */
   8305 -    public static class RIPEMD128
   8306 -        extends JCEMac
   8307 -    {
   8308 -        public RIPEMD128()
   8309 -        {
   8310 -            super(new HMac(new RIPEMD128Digest()));
   8311 -        }
   8312 -    }
   8313 -
   8314 -    /**
   8315 -     * RIPEMD160 HMac
   8316 -     */
   8317 -    public static class RIPEMD160
   8318 -        extends JCEMac
   8319 -    {
   8320 -        public RIPEMD160()
   8321 -        {
   8322 -            super(new HMac(new RIPEMD160Digest()));
   8323 -        }
   8324 -    }
   8325 -
   8326 -    /**
   8327 -     * Tiger HMac
   8328 -     */
   8329 -    public static class Tiger
   8330 -        extends JCEMac
   8331 -    {
   8332 -        public Tiger()
   8333 -        {
   8334 -            super(new HMac(new TigerDigest()));
   8335 -        }
   8336 -    }
   8337 -
   8338 +    // BEGIN android-removed
   8339 +    // /**
   8340 +    //  * SHA-512 HMac
   8341 +    //  */
   8342 +    // public static class OldSHA512
   8343 +    //     extends JCEMac
   8344 +    // {
   8345 +    //     public OldSHA512()
   8346 +    //     {
   8347 +    //         super(new OldHMac(new SHA512Digest()));
   8348 +    //     }
   8349 +    // }
   8350      //
   8351 -    // PKCS12 states that the same algorithm should be used
   8352 -    // for the key generation as is used in the HMAC, so that
   8353 -    // is what we do here.
   8354 +    // /**
   8355 +    //  * RIPEMD128 HMac
   8356 +    //  */
   8357 +    // public static class RIPEMD128
   8358 +    //     extends JCEMac
   8359 +    // {
   8360 +    //     public RIPEMD128()
   8361 +    //     {
   8362 +    //        super(new HMac(new RIPEMD128Digest()));
   8363 +    //     }
   8364 +    // }
   8365      //
   8366 -
   8367 -    /**
   8368 -     * PBEWithHmacRIPEMD160
   8369 -     */
   8370 -    public static class PBEWithRIPEMD160
   8371 -        extends JCEMac
   8372 -    {
   8373 -        public PBEWithRIPEMD160()
   8374 -        {
   8375 -            super(new HMac(new RIPEMD160Digest()), PKCS12, RIPEMD160, 160);
   8376 -        }
   8377 -    }
   8378 +    // /**
   8379 +    //  * RIPEMD160 HMac
   8380 +    //  */
   8381 +    // public static class RIPEMD160
   8382 +    //     extends JCEMac
   8383 +    // {
   8384 +    //     public RIPEMD160()
   8385 +    //     {
   8386 +    //        super(new HMac(new RIPEMD160Digest()));
   8387 +    //     }
   8388 +    // }
   8389 +    //
   8390 +    // /**
   8391 +    //  * Tiger HMac
   8392 +    //  */
   8393 +    // public static class Tiger
   8394 +    //     extends JCEMac
   8395 +    // {
   8396 +    //     public Tiger()
   8397 +    //     {
   8398 +    //         super(new HMac(new TigerDigest()));
   8399 +    //     }
   8400 +    // }
   8401 +    //
   8402 +    // //
   8403 +    // // PKCS12 states that the same algorithm should be used
   8404 +    // // for the key generation as is used in the HMAC, so that
   8405 +    // // is what we do here.
   8406 +    // //
   8407 +    //
   8408 +    // /**
   8409 +    //  * PBEWithHmacRIPEMD160
   8410 +    //  */
   8411 +    // public static class PBEWithRIPEMD160
   8412 +    //     extends JCEMac
   8413 +    // {
   8414 +    //     public PBEWithRIPEMD160()
   8415 +    //     {
   8416 +    //         super(new HMac(new RIPEMD160Digest()), PKCS12, RIPEMD160, 160);
   8417 +    //     }
   8418 +    // }
   8419 +    // END android-removed
   8420  
   8421      /**
   8422       * PBEWithHmacSHA
   8423 @@ -403,19 +433,23 @@
   8424      {
   8425          public PBEWithSHA()
   8426          {
   8427 -            super(new HMac(new SHA1Digest()), PKCS12, SHA1, 160);
   8428 +            // BEGIN android-changed
   8429 +            super(new HMac(AndroidDigestFactory.getSHA1()), PKCS12, SHA1, 160);
   8430 +            // END android-changed
   8431          }
   8432      }
   8433  
   8434 -    /**
   8435 -     * PBEWithHmacTiger
   8436 -     */
   8437 -    public static class PBEWithTiger
   8438 -        extends JCEMac
   8439 -    {
   8440 -        public PBEWithTiger()
   8441 -        {
   8442 -            super(new HMac(new TigerDigest()), PKCS12, TIGER, 192);
   8443 -        }
   8444 -    }
   8445 +    // BEGIN android-removed
   8446 +    //  /**
   8447 +    //   * PBEWithHmacTiger
   8448 +    //   */
   8449 +    // public static class PBEWithTiger
   8450 +    //     extends JCEMac
   8451 +    // {
   8452 +    //     public PBEWithTiger()
   8453 +    //     {
   8454 +    //         super(new HMac(new TigerDigest()), PKCS12, TIGER, 192);
   8455 +    //     }
   8456 +    // }
   8457 +    // END android-removed
   8458  }
   8459 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCERSAPrivateCrtKey.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCERSAPrivateCrtKey.java
   8460 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCERSAPrivateCrtKey.java	2012-03-22 15:11:48.000000000 +0000
   8461 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCERSAPrivateCrtKey.java	2012-09-19 21:17:12.000000000 +0000
   8462 @@ -127,7 +127,9 @@
   8463       */
   8464      public byte[] getEncoded()
   8465      {
   8466 -        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient()));
   8467 +        // BEGIN android-changed
   8468 +        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient()));
   8469 +        // END android-changed
   8470      }
   8471  
   8472      /**
   8473 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCERSAPrivateKey.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCERSAPrivateKey.java
   8474 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCERSAPrivateKey.java	2012-03-22 15:11:48.000000000 +0000
   8475 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCERSAPrivateKey.java	2012-09-19 21:17:12.000000000 +0000
   8476 @@ -78,7 +78,9 @@
   8477  
   8478      public byte[] getEncoded()
   8479      {
   8480 -        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO));
   8481 +        // BEGIN android-changed
   8482 +        return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.bouncycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO));
   8483 +        // END android-changed
   8484      }
   8485  
   8486      public boolean equals(Object o)
   8487 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCERSAPublicKey.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCERSAPublicKey.java
   8488 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCERSAPublicKey.java	2012-03-22 15:11:48.000000000 +0000
   8489 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCERSAPublicKey.java	2012-09-19 21:17:12.000000000 +0000
   8490 @@ -91,7 +91,9 @@
   8491  
   8492      public byte[] getEncoded()
   8493      {
   8494 -        return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new RSAPublicKeyStructure(getModulus(), getPublicExponent()));
   8495 +        // BEGIN android-changed
   8496 +        return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKeyStructure(getModulus(), getPublicExponent()));
   8497 +        // END android-changed
   8498      }
   8499  
   8500      public int hashCode()
   8501 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCESecretKeyFactory.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCESecretKeyFactory.java
   8502 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCESecretKeyFactory.java	2012-03-22 15:11:48.000000000 +0000
   8503 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCESecretKeyFactory.java	2012-09-19 21:17:12.000000000 +0000
   8504 @@ -252,29 +252,31 @@
   8505          }
   8506      }
   8507  
   8508 -    /**
   8509 -     * PBEWithMD2AndDES
   8510 -     */
   8511 -    static public class PBEWithMD2AndDES
   8512 -        extends DESPBEKeyFactory
   8513 -    {
   8514 -        public PBEWithMD2AndDES()
   8515 -        {
   8516 -            super("PBEwithMD2andDES", PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, true, PKCS5S1, MD2, 64, 64);
   8517 -        }
   8518 -    }
   8519 -
   8520 -    /**
   8521 -     * PBEWithMD2AndRC2
   8522 -     */
   8523 -    static public class PBEWithMD2AndRC2
   8524 -        extends PBEKeyFactory
   8525 -    {
   8526 -        public PBEWithMD2AndRC2()
   8527 -        {
   8528 -            super("PBEwithMD2andRC2", PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, true, PKCS5S1, MD2, 64, 64);
   8529 -        }
   8530 -    }
   8531 +    // BEGIN android-removed
   8532 +    // /**
   8533 +    //  * PBEWithMD2AndDES
   8534 +    //  */
   8535 +    // static public class PBEWithMD2AndDES
   8536 +    //     extends DESPBEKeyFactory
   8537 +    // {
   8538 +    //     public PBEWithMD2AndDES()
   8539 +    //     {
   8540 +    //         super("PBEwithMD2andDES", PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, true, PKCS5S1, MD2, 64, 64);
   8541 +    //     }
   8542 +    // }
   8543 +    //
   8544 +    // /**
   8545 +    //  * PBEWithMD2AndRC2
   8546 +    //  */
   8547 +    // static public class PBEWithMD2AndRC2
   8548 +    //     extends PBEKeyFactory
   8549 +    // {
   8550 +    //     public PBEWithMD2AndRC2()
   8551 +    //     {
   8552 +    //         super("PBEwithMD2andRC2", PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, true, PKCS5S1, MD2, 64, 64);
   8553 +    //     }
   8554 +    // }
   8555 +    // END android-removed
   8556  
   8557     /**
   8558      * PBEWithMD5AndDES
   8559 @@ -408,17 +410,19 @@
   8560         }
   8561     }
   8562     
   8563 -   /**
   8564 -    * PBEWithHmacRIPEMD160
   8565 -    */
   8566 -   public static class PBEWithRIPEMD160
   8567 -       extends PBEKeyFactory
   8568 -   {
   8569 -       public PBEWithRIPEMD160()
   8570 -       {
   8571 -           super("PBEwithHmacRIPEMD160", null, false, PKCS12, RIPEMD160, 160, 0);
   8572 -       }
   8573 -   }
   8574 +   // BEGIN android-removed
   8575 +   // /**
   8576 +   //  * PBEWithHmacRIPEMD160
   8577 +   //  */
   8578 +   // public static class PBEWithRIPEMD160
   8579 +   //     extends PBEKeyFactory
   8580 +   // {
   8581 +   //     public PBEWithRIPEMD160()
   8582 +   //     {
   8583 +   //         super("PBEwithHmacRIPEMD160", null, false, PKCS12, RIPEMD160, 160, 0);
   8584 +   //     }
   8585 +   // }
   8586 +   // END android-removed
   8587  
   8588     /**
   8589      * PBEWithHmacSHA
   8590 @@ -432,17 +436,19 @@
   8591         }
   8592     }
   8593  
   8594 -   /**
   8595 -    * PBEWithHmacTiger
   8596 -    */
   8597 -   public static class PBEWithTiger
   8598 -       extends PBEKeyFactory
   8599 -   {
   8600 -       public PBEWithTiger()
   8601 -       {
   8602 -           super("PBEwithHmacTiger", null, false, PKCS12, TIGER, 192, 0);
   8603 -       }
   8604 -   }
   8605 +   // BEGIN android-removed
   8606 +   // /**
   8607 +   //  * PBEWithHmacTiger
   8608 +   //  */
   8609 +   // public static class PBEWithTiger
   8610 +   //     extends PBEKeyFactory
   8611 +   // {
   8612 +   //     public PBEWithTiger()
   8613 +   //     {
   8614 +   //         super("PBEwithHmacTiger", null, false, PKCS12, TIGER, 192, 0);
   8615 +   //     }
   8616 +   // }
   8617 +   // END android-removed
   8618     
   8619     /**
   8620      * PBEWithSHA1And128BitAES-BC
   8621 @@ -551,4 +557,56 @@
   8622             super("PBEWithMD5And256BitAES-CBC-OpenSSL", null, true, OPENSSL, MD5, 256, 128);
   8623         }
   8624     }
   8625 +    // BEGIN android-added
   8626 +    static public class PBKDF2WithHmacSHA1
   8627 +        extends JCESecretKeyFactory
   8628 +    {
   8629 +        public PBKDF2WithHmacSHA1()
   8630 +        {
   8631 +            super("PBKDF2WithHmacSHA1", PKCSObjectIdentifiers.id_PBKDF2);
   8632 +        }
   8633 +
   8634 +        protected SecretKey engineGenerateSecret(
   8635 +            KeySpec keySpec)
   8636 +            throws InvalidKeySpecException
   8637 +        {
   8638 +            if (keySpec instanceof PBEKeySpec)
   8639 +            {
   8640 +                PBEKeySpec          pbeSpec = (PBEKeySpec)keySpec;
   8641 +                
   8642 +                if (pbeSpec.getSalt() == null)
   8643 +                {
   8644 +                    throw new InvalidKeySpecException("missing required salt");
   8645 +                }
   8646 +
   8647 +                if (pbeSpec.getIterationCount() <= 0)
   8648 +                {
   8649 +                    throw new InvalidKeySpecException("positive iteration count required: "
   8650 +                                                      + pbeSpec.getIterationCount());
   8651 +                }
   8652 +                
   8653 +                if (pbeSpec.getKeyLength() <= 0)
   8654 +                {
   8655 +                    throw new InvalidKeySpecException("positive key length required: "
   8656 +                                                      + pbeSpec.getKeyLength());
   8657 +                }
   8658 +                
   8659 +                if (pbeSpec.getPassword().length == 0)
   8660 +                {
   8661 +                    throw new IllegalArgumentException("password empty");
   8662 +                }
   8663 +
   8664 +                int scheme = PKCS5S2;
   8665 +                int digest = SHA1;
   8666 +                int keySize = pbeSpec.getKeyLength();
   8667 +                int ivSize = -1;
   8668 +                CipherParameters param = Util.makePBEMacParameters(pbeSpec, scheme, digest, keySize);
   8669 +                
   8670 +                return new BCPBEKey(this.algName, this.algOid, scheme, digest, keySize, ivSize, pbeSpec, param);
   8671 +            }
   8672 +            
   8673 +            throw new InvalidKeySpecException("Invalid KeySpec");
   8674 +        }
   8675 +    }
   8676 +    // END android-added
   8677  }
   8678 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEStreamCipher.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEStreamCipher.java
   8679 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JCEStreamCipher.java	2012-03-22 15:11:48.000000000 +0000
   8680 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JCEStreamCipher.java	2012-09-19 21:17:12.000000000 +0000
   8681 @@ -14,20 +14,26 @@
   8682  import javax.crypto.ShortBufferException;
   8683  import javax.crypto.spec.IvParameterSpec;
   8684  import javax.crypto.spec.PBEParameterSpec;
   8685 -import javax.crypto.spec.RC2ParameterSpec;
   8686 -import javax.crypto.spec.RC5ParameterSpec;
   8687 +// BEGIN android-removed
   8688 +// import javax.crypto.spec.RC2ParameterSpec;
   8689 +// import javax.crypto.spec.RC5ParameterSpec;
   8690 +// END android-removed
   8691  
   8692  import org.bouncycastle.crypto.BlockCipher;
   8693  import org.bouncycastle.crypto.CipherParameters;
   8694  import org.bouncycastle.crypto.DataLengthException;
   8695  import org.bouncycastle.crypto.StreamBlockCipher;
   8696  import org.bouncycastle.crypto.StreamCipher;
   8697 -import org.bouncycastle.crypto.engines.BlowfishEngine;
   8698 -import org.bouncycastle.crypto.engines.DESEngine;
   8699 -import org.bouncycastle.crypto.engines.DESedeEngine;
   8700 +// BEGIN android-removed
   8701 +// import org.bouncycastle.crypto.engines.BlowfishEngine;
   8702 +// import org.bouncycastle.crypto.engines.DESEngine;
   8703 +// import org.bouncycastle.crypto.engines.DESedeEngine;
   8704 +// END android-removed
   8705  import org.bouncycastle.crypto.engines.RC4Engine;
   8706 -import org.bouncycastle.crypto.engines.SkipjackEngine;
   8707 -import org.bouncycastle.crypto.engines.TwofishEngine;
   8708 +// BEGIN android-removed
   8709 +// import org.bouncycastle.crypto.engines.SkipjackEngine;
   8710 +// import org.bouncycastle.crypto.engines.TwofishEngine;
   8711 +// END android-removed
   8712  import org.bouncycastle.crypto.modes.CFBBlockCipher;
   8713  import org.bouncycastle.crypto.modes.OFBBlockCipher;
   8714  import org.bouncycastle.crypto.params.KeyParameter;
   8715 @@ -44,8 +50,10 @@
   8716      //
   8717      private Class[]                 availableSpecs =
   8718                                      {
   8719 -                                        RC2ParameterSpec.class,
   8720 -                                        RC5ParameterSpec.class,
   8721 +                                        // BEGIN android-removed
   8722 +                                        // RC2ParameterSpec.class,
   8723 +                                        // RC5ParameterSpec.class,
   8724 +                                        // END android-removed
   8725                                          IvParameterSpec.class,
   8726                                          PBEParameterSpec.class
   8727                                      };
   8728 @@ -376,125 +384,127 @@
   8729       * The ciphers that inherit from us.
   8730       */
   8731  
   8732 -    /**
   8733 -     * DES
   8734 -     */
   8735 -    static public class DES_CFB8
   8736 -        extends JCEStreamCipher
   8737 -    {
   8738 -        public DES_CFB8()
   8739 -        {
   8740 -            super(new CFBBlockCipher(new DESEngine(), 8), 64);
   8741 -        }
   8742 -    }
   8743 -
   8744 -    /**
   8745 -     * DESede
   8746 -     */
   8747 -    static public class DESede_CFB8
   8748 -        extends JCEStreamCipher
   8749 -    {
   8750 -        public DESede_CFB8()
   8751 -        {
   8752 -            super(new CFBBlockCipher(new DESedeEngine(), 8), 64);
   8753 -        }
   8754 -    }
   8755 -
   8756 -    /**
   8757 -     * SKIPJACK
   8758 -     */
   8759 -    static public class Skipjack_CFB8
   8760 -        extends JCEStreamCipher
   8761 -    {
   8762 -        public Skipjack_CFB8()
   8763 -        {
   8764 -            super(new CFBBlockCipher(new SkipjackEngine(), 8), 64);
   8765 -        }
   8766 -    }
   8767 -
   8768 -    /**
   8769 -     * Blowfish
   8770 -     */
   8771 -    static public class Blowfish_CFB8
   8772 -        extends JCEStreamCipher
   8773 -    {
   8774 -        public Blowfish_CFB8()
   8775 -        {
   8776 -            super(new CFBBlockCipher(new BlowfishEngine(), 8), 64);
   8777 -        }
   8778 -    }
   8779 -
   8780 -    /**
   8781 -     * Twofish
   8782 -     */
   8783 -    static public class Twofish_CFB8
   8784 -        extends JCEStreamCipher
   8785 -    {
   8786 -        public Twofish_CFB8()
   8787 -        {
   8788 -            super(new CFBBlockCipher(new TwofishEngine(), 8), 128);
   8789 -        }
   8790 -    }
   8791 -
   8792 -    /**
   8793 -     * DES
   8794 -     */
   8795 -    static public class DES_OFB8
   8796 -        extends JCEStreamCipher
   8797 -    {
   8798 -        public DES_OFB8()
   8799 -        {
   8800 -            super(new OFBBlockCipher(new DESEngine(), 8), 64);
   8801 -        }
   8802 -    }
   8803 -
   8804 -    /**
   8805 -     * DESede
   8806 -     */
   8807 -    static public class DESede_OFB8
   8808 -        extends JCEStreamCipher
   8809 -    {
   8810 -        public DESede_OFB8()
   8811 -        {
   8812 -            super(new OFBBlockCipher(new DESedeEngine(), 8), 64);
   8813 -        }
   8814 -    }
   8815 -
   8816 -    /**
   8817 -     * SKIPJACK
   8818 -     */
   8819 -    static public class Skipjack_OFB8
   8820 -        extends JCEStreamCipher
   8821 -    {
   8822 -        public Skipjack_OFB8()
   8823 -        {
   8824 -            super(new OFBBlockCipher(new SkipjackEngine(), 8), 64);
   8825 -        }
   8826 -    }
   8827 -
   8828 -    /**
   8829 -     * Blowfish
   8830 -     */
   8831 -    static public class Blowfish_OFB8
   8832 -        extends JCEStreamCipher
   8833 -    {
   8834 -        public Blowfish_OFB8()
   8835 -        {
   8836 -            super(new OFBBlockCipher(new BlowfishEngine(), 8), 64);
   8837 -        }
   8838 -    }
   8839 -
   8840 -    /**
   8841 -     * Twofish
   8842 -     */
   8843 -    static public class Twofish_OFB8
   8844 -        extends JCEStreamCipher
   8845 -    {
   8846 -        public Twofish_OFB8()
   8847 -        {
   8848 -            super(new OFBBlockCipher(new TwofishEngine(), 8), 128);
   8849 -        }
   8850 -    }
   8851 +    // BEGIN android-removed
   8852 +    // /**
   8853 +    //  * DES
   8854 +    //  */
   8855 +    // static public class DES_CFB8
   8856 +    //     extends JCEStreamCipher
   8857 +    // {
   8858 +    //     public DES_CFB8()
   8859 +    //     {
   8860 +    //         super(new CFBBlockCipher(new DESEngine(), 8), 64);
   8861 +    //     }
   8862 +    // }
   8863 +    //
   8864 +    // /**
   8865 +    //  * DESede
   8866 +    //  */
   8867 +    // static public class DESede_CFB8
   8868 +    //     extends JCEStreamCipher
   8869 +    // {
   8870 +    //     public DESede_CFB8()
   8871 +    //     {
   8872 +    //         super(new CFBBlockCipher(new DESedeEngine(), 8), 64);
   8873 +    //     }
   8874 +    // }
   8875 +    //
   8876 +    // /**
   8877 +    //  * SKIPJACK
   8878 +    //  */
   8879 +    // static public class Skipjack_CFB8
   8880 +    //     extends JCEStreamCipher
   8881 +    // {
   8882 +    //     public Skipjack_CFB8()
   8883 +    //     {
   8884 +    //         super(new CFBBlockCipher(new SkipjackEngine(), 8), 64);
   8885 +    //     }
   8886 +    // }
   8887 +    //
   8888 +    // /**
   8889 +    //  * Blowfish
   8890 +    //  */
   8891 +    // static public class Blowfish_CFB8
   8892 +    //     extends JCEStreamCipher
   8893 +    // {
   8894 +    //     public Blowfish_CFB8()
   8895 +    //     {
   8896 +    //         super(new CFBBlockCipher(new BlowfishEngine(), 8), 64);
   8897 +    //     }
   8898 +    // }
   8899 +    //
   8900 +    // /**
   8901 +    //  * Twofish
   8902 +    //  */
   8903 +    // static public class Twofish_CFB8
   8904 +    //     extends JCEStreamCipher
   8905 +    // {
   8906 +    //     public Twofish_CFB8()
   8907 +    //     {
   8908 +    //         super(new CFBBlockCipher(new TwofishEngine(), 8), 128);
   8909 +    //     }
   8910 +    // }
   8911 +    //
   8912 +    // /**
   8913 +    //  * DES
   8914 +    //  */
   8915 +    // static public class DES_OFB8
   8916 +    //     extends JCEStreamCipher
   8917 +    // {
   8918 +    //     public DES_OFB8()
   8919 +    //     {
   8920 +    //         super(new OFBBlockCipher(new DESEngine(), 8), 64);
   8921 +    //     }
   8922 +    // }
   8923 +    //
   8924 +    // /**
   8925 +    //  * DESede
   8926 +    //  */
   8927 +    // static public class DESede_OFB8
   8928 +    //     extends JCEStreamCipher
   8929 +    // {
   8930 +    //     public DESede_OFB8()
   8931 +    //     {
   8932 +    //         super(new OFBBlockCipher(new DESedeEngine(), 8), 64);
   8933 +    //     }
   8934 +    // }
   8935 +    //
   8936 +    // /**
   8937 +    //  * SKIPJACK
   8938 +    //  */
   8939 +    // static public class Skipjack_OFB8
   8940 +    //     extends JCEStreamCipher
   8941 +    // {
   8942 +    //     public Skipjack_OFB8()
   8943 +    //     {
   8944 +    //         super(new OFBBlockCipher(new SkipjackEngine(), 8), 64);
   8945 +    //     }
   8946 +    // }
   8947 +    //
   8948 +    // /**
   8949 +    //  * Blowfish
   8950 +    //  */
   8951 +    // static public class Blowfish_OFB8
   8952 +    //     extends JCEStreamCipher
   8953 +    // {
   8954 +    //     public Blowfish_OFB8()
   8955 +    //     {
   8956 +    //         super(new OFBBlockCipher(new BlowfishEngine(), 8), 64);
   8957 +    //     }
   8958 +    // }
   8959 +    //
   8960 +    // /**
   8961 +    //  * Twofish
   8962 +    //  */
   8963 +    // static public class Twofish_OFB8
   8964 +    //     extends JCEStreamCipher
   8965 +    // {
   8966 +    //     public Twofish_OFB8()
   8967 +    //     {
   8968 +    //         super(new OFBBlockCipher(new TwofishEngine(), 8), 128);
   8969 +    //     }
   8970 +    // }
   8971 +    // END android-removed
   8972  
   8973      /**
   8974       * PBEWithSHAAnd128BitRC4
   8975 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JDKAlgorithmParameters.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JDKAlgorithmParameters.java
   8976 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JDKAlgorithmParameters.java	2012-03-22 15:11:48.000000000 +0000
   8977 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JDKAlgorithmParameters.java	2012-09-19 21:17:12.000000000 +0000
   8978 @@ -17,7 +17,9 @@
   8979  import org.bouncycastle.asn1.DERSequence;
   8980  import org.bouncycastle.asn1.pkcs.PBKDF2Params;
   8981  import org.bouncycastle.asn1.pkcs.PKCS12PBEParams;
   8982 -import org.bouncycastle.jce.spec.IESParameterSpec;
   8983 +// BEGIN android-removed
   8984 +// import org.bouncycastle.jce.spec.IESParameterSpec;
   8985 +// END android-removed
   8986  
   8987  public abstract class JDKAlgorithmParameters
   8988      extends AlgorithmParametersSpi
   8989 @@ -208,109 +210,111 @@
   8990          }
   8991      }
   8992  
   8993 -    public static class IES
   8994 -        extends JDKAlgorithmParameters
   8995 -    {
   8996 -        IESParameterSpec     currentSpec;
   8997 -
   8998 -        /**
   8999 -         * in the absence of a standard way of doing it this will do for
   9000 -         * now...
   9001 -         */
   9002 -        protected byte[] engineGetEncoded() 
   9003 -        {
   9004 -            try
   9005 -            {
   9006 -                ASN1EncodableVector v = new ASN1EncodableVector();
   9007 -
   9008 -                v.add(new DEROctetString(currentSpec.getDerivationV()));
   9009 -                v.add(new DEROctetString(currentSpec.getEncodingV()));
   9010 -                v.add(new DERInteger(currentSpec.getMacKeySize()));
   9011 -
   9012 -                return new DERSequence(v).getEncoded(ASN1Encoding.DER);
   9013 -            }
   9014 -            catch (IOException e)
   9015 -            {
   9016 -                throw new RuntimeException("Error encoding IESParameters");
   9017 -            }
   9018 -        }
   9019 -
   9020 -        protected byte[] engineGetEncoded(
   9021 -            String format) 
   9022 -        {
   9023 -            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
   9024 -            {
   9025 -                return engineGetEncoded();
   9026 -            }
   9027 -
   9028 -            return null;
   9029 -        }
   9030 -
   9031 -        protected AlgorithmParameterSpec localEngineGetParameterSpec(
   9032 -            Class paramSpec) 
   9033 -            throws InvalidParameterSpecException
   9034 -        {
   9035 -            if (paramSpec == IESParameterSpec.class)
   9036 -            {
   9037 -                return currentSpec;
   9038 -            }
   9039 -
   9040 -            throw new InvalidParameterSpecException("unknown parameter spec passed to ElGamal parameters object.");
   9041 -        }
   9042 -
   9043 -        protected void engineInit(
   9044 -            AlgorithmParameterSpec paramSpec) 
   9045 -            throws InvalidParameterSpecException
   9046 -        {
   9047 -            if (!(paramSpec instanceof IESParameterSpec))
   9048 -            {
   9049 -                throw new InvalidParameterSpecException("IESParameterSpec required to initialise a IES algorithm parameters object");
   9050 -            }
   9051 -
   9052 -            this.currentSpec = (IESParameterSpec)paramSpec;
   9053 -        }
   9054 -
   9055 -        protected void engineInit(
   9056 -            byte[] params) 
   9057 -            throws IOException
   9058 -        {
   9059 -            try
   9060 -            {
   9061 -                ASN1Sequence s = (ASN1Sequence)ASN1Primitive.fromByteArray(params);
   9062 -
   9063 -                this.currentSpec = new IESParameterSpec(
   9064 -                                        ((ASN1OctetString)s.getObjectAt(0)).getOctets(),
   9065 -                                        ((ASN1OctetString)s.getObjectAt(0)).getOctets(),
   9066 -                                        ((DERInteger)s.getObjectAt(0)).getValue().intValue());
   9067 -            }
   9068 -            catch (ClassCastException e)
   9069 -            {
   9070 -                throw new IOException("Not a valid IES Parameter encoding.");
   9071 -            }
   9072 -            catch (ArrayIndexOutOfBoundsException e)
   9073 -            {
   9074 -                throw new IOException("Not a valid IES Parameter encoding.");
   9075 -            }
   9076 -        }
   9077 -
   9078 -        protected void engineInit(
   9079 -            byte[] params,
   9080 -            String format) 
   9081 -            throws IOException
   9082 -        {
   9083 -            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
   9084 -            {
   9085 -                engineInit(params);
   9086 -            }
   9087 -            else
   9088 -            {
   9089 -                throw new IOException("Unknown parameter format " + format);
   9090 -            }
   9091 -        }
   9092 -
   9093 -        protected String engineToString() 
   9094 -        {
   9095 -            return "IES Parameters";
   9096 -        }
   9097 -    }
   9098 +    // BEGIN android-removed
   9099 +    // public static class IES
   9100 +    //     extends JDKAlgorithmParameters
   9101 +    // {
   9102 +    //     IESParameterSpec     currentSpec;
   9103 +    //
   9104 +    //     /**
   9105 +    //      * in the absence of a standard way of doing it this will do for
   9106 +    //      * now...
   9107 +    //      */
   9108 +    //     protected byte[] engineGetEncoded() 
   9109 +    //     {
   9110 +    //         try
   9111 +    //         {
   9112 +    //             ASN1EncodableVector v = new ASN1EncodableVector();
   9113 +    //
   9114 +    //             v.add(new DEROctetString(currentSpec.getDerivationV()));
   9115 +    //             v.add(new DEROctetString(currentSpec.getEncodingV()));
   9116 +    //             v.add(new DERInteger(currentSpec.getMacKeySize()));
   9117 +    //
   9118 +    //             return new DERSequence(v).getEncoded(ASN1Encoding.DER);
   9119 +    //         }
   9120 +    //         catch (IOException e)
   9121 +    //         {
   9122 +    //             throw new RuntimeException("Error encoding IESParameters");
   9123 +    //         }
   9124 +    //     }
   9125 +    //
   9126 +    //     protected byte[] engineGetEncoded(
   9127 +    //         String format) 
   9128 +    //     {
   9129 +    //         if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
   9130 +    //         {
   9131 +    //             return engineGetEncoded();
   9132 +    //         }
   9133 +    //
   9134 +    //         return null;
   9135 +    //     }
   9136 +    //
   9137 +    //     protected AlgorithmParameterSpec localEngineGetParameterSpec(
   9138 +    //         Class paramSpec) 
   9139 +    //         throws InvalidParameterSpecException
   9140 +    //     {
   9141 +    //         if (paramSpec == IESParameterSpec.class)
   9142 +    //         {
   9143 +    //             return currentSpec;
   9144 +    //         }
   9145 +    //
   9146 +    //         throw new InvalidParameterSpecException("unknown parameter spec passed to ElGamal parameters object.");
   9147 +    //     }
   9148 +    //
   9149 +    //     protected void engineInit(
   9150 +    //         AlgorithmParameterSpec paramSpec) 
   9151 +    //         throws InvalidParameterSpecException
   9152 +    //     {
   9153 +    //         if (!(paramSpec instanceof IESParameterSpec))
   9154 +    //         {
   9155 +    //             throw new InvalidParameterSpecException("IESParameterSpec required to initialise a IES algorithm parameters object");
   9156 +    //         }
   9157 +    //
   9158 +    //         this.currentSpec = (IESParameterSpec)paramSpec;
   9159 +    //     }
   9160 +    //
   9161 +    //     protected void engineInit(
   9162 +    //         byte[] params) 
   9163 +    //         throws IOException
   9164 +    //     {
   9165 +    //         try
   9166 +    //         {
   9167 +    //             ASN1Sequence s = (ASN1Sequence)ASN1Primitive.fromByteArray(params);
   9168 +    //
   9169 +    //             this.currentSpec = new IESParameterSpec(
   9170 +    //                                     ((ASN1OctetString)s.getObjectAt(0)).getOctets(),
   9171 +    //                                     ((ASN1OctetString)s.getObjectAt(0)).getOctets(),
   9172 +    //                                     ((DERInteger)s.getObjectAt(0)).getValue().intValue());
   9173 +    //         }
   9174 +    //         catch (ClassCastException e)
   9175 +    //         {
   9176 +    //             throw new IOException("Not a valid IES Parameter encoding.");
   9177 +    //         }
   9178 +    //         catch (ArrayIndexOutOfBoundsException e)
   9179 +    //         {
   9180 +    //             throw new IOException("Not a valid IES Parameter encoding.");
   9181 +    //         }
   9182 +    //     }
   9183 +    //
   9184 +    //     protected void engineInit(
   9185 +    //         byte[] params,
   9186 +    //         String format) 
   9187 +    //         throws IOException
   9188 +    //     {
   9189 +    //         if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
   9190 +    //         {
   9191 +    //             engineInit(params);
   9192 +    //         }
   9193 +    //         else
   9194 +    //         {
   9195 +    //             throw new IOException("Unknown parameter format " + format);
   9196 +    //         }
   9197 +    //     }
   9198 +    //
   9199 +    //     protected String engineToString() 
   9200 +    //     {
   9201 +    //         return "IES Parameters";
   9202 +    //     }
   9203 +    // }
   9204 +    // END android-removed
   9205  }
   9206 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JDKKeyStore.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JDKKeyStore.java
   9207 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JDKKeyStore.java	2012-03-22 15:11:48.000000000 +0000
   9208 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JDKKeyStore.java	2012-09-19 21:17:12.000000000 +0000
   9209 @@ -39,7 +39,12 @@
   9210  import org.bouncycastle.crypto.CipherParameters;
   9211  import org.bouncycastle.crypto.Digest;
   9212  import org.bouncycastle.crypto.PBEParametersGenerator;
   9213 -import org.bouncycastle.crypto.digests.SHA1Digest;
   9214 +// BEGIN android-added
   9215 +import org.bouncycastle.crypto.digests.AndroidDigestFactory;
   9216 +// END android-added
   9217 +// BEGIN android-removed
   9218 +// import org.bouncycastle.crypto.digests.SHA1Digest;
   9219 +// END android-removed
   9220  import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
   9221  import org.bouncycastle.crypto.io.DigestInputStream;
   9222  import org.bouncycastle.crypto.io.DigestOutputStream;
   9223 @@ -498,7 +503,13 @@
   9224  
   9225          if (entry == null)
   9226          {
   9227 -            throw new KeyStoreException("no such entry as " + alias);
   9228 +            // BEGIN android-removed
   9229 +            // Only throw if there is a problem removing, not if missing
   9230 +            // throw new KeyStoreException("no such entry as " + alias);
   9231 +            // END android-removed
   9232 +            // BEGIN android-added
   9233 +            return;
   9234 +            // END android-added
   9235          }
   9236  
   9237          table.remove(alias);
   9238 @@ -817,12 +828,16 @@
   9239          //
   9240          // we only do an integrity check if the password is provided.
   9241          //
   9242 -        HMac hMac = new HMac(new SHA1Digest());
   9243 +        // BEGIN android-changed
   9244 +        HMac hMac = new HMac(AndroidDigestFactory.getSHA1());
   9245 +        // END android-changed
   9246          if (password != null && password.length != 0)
   9247          {
   9248              byte[] passKey = PBEParametersGenerator.PKCS12PasswordToBytes(password);
   9249  
   9250 -            PBEParametersGenerator pbeGen = new PKCS12ParametersGenerator(new SHA1Digest());
   9251 +            // BEGIN android-changed
   9252 +            PBEParametersGenerator pbeGen = new PKCS12ParametersGenerator(AndroidDigestFactory.getSHA1());
   9253 +            // END android-changed
   9254              pbeGen.init(passKey, salt, iterationCount);
   9255  
   9256              CipherParameters macParams;
   9257 @@ -884,9 +899,11 @@
   9258          dOut.write(salt);
   9259          dOut.writeInt(iterationCount);
   9260  
   9261 -        HMac                    hMac = new HMac(new SHA1Digest());
   9262 +        // BEGIN android-changed
   9263 +        HMac                    hMac = new HMac(AndroidDigestFactory.getSHA1());
   9264          MacOutputStream         mOut = new MacOutputStream(hMac);
   9265 -        PBEParametersGenerator  pbeGen = new PKCS12ParametersGenerator(new SHA1Digest());
   9266 +        PBEParametersGenerator  pbeGen = new PKCS12ParametersGenerator(AndroidDigestFactory.getSHA1());
   9267 +        // END android-changed
   9268          byte[]                  passKey = PBEParametersGenerator.PKCS12PasswordToBytes(password);
   9269  
   9270          pbeGen.init(passKey, salt, iterationCount);
   9271 @@ -974,7 +991,9 @@
   9272              Cipher cipher = this.makePBECipher(cipherAlg, Cipher.DECRYPT_MODE, password, salt, iterationCount);
   9273              CipherInputStream cIn = new CipherInputStream(dIn, cipher);
   9274  
   9275 -            Digest dig = new SHA1Digest();
   9276 +            // BEGIN android-changed
   9277 +            Digest dig = AndroidDigestFactory.getSHA1();
   9278 +            // END android-changed
   9279              DigestInputStream  dgIn = new DigestInputStream(cIn, dig);
   9280      
   9281              this.loadStore(dgIn);
   9282 @@ -1013,7 +1032,9 @@
   9283              cipher = this.makePBECipher(STORE_CIPHER, Cipher.ENCRYPT_MODE, password, salt, iterationCount);
   9284      
   9285              CipherOutputStream  cOut = new CipherOutputStream(dOut, cipher);
   9286 -            DigestOutputStream  dgOut = new DigestOutputStream(new SHA1Digest());
   9287 +            // BEGIN android-changed
   9288 +            DigestOutputStream  dgOut = new DigestOutputStream(AndroidDigestFactory.getSHA1());
   9289 +            // END android-changed
   9290      
   9291              this.saveStore(new TeeOutputStream(cOut, dgOut));
   9292      
   9293 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JDKPKCS12KeyStore.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/JDKPKCS12KeyStore.java
   9294 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/JDKPKCS12KeyStore.java	2012-03-22 15:11:48.000000000 +0000
   9295 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/JDKPKCS12KeyStore.java	2012-09-19 21:17:12.000000000 +0000
   9296 @@ -261,10 +261,13 @@
   9297              }
   9298          }
   9299  
   9300 -        if (c == null && k == null)
   9301 -        {
   9302 -            throw new KeyStoreException("no such entry as " + alias);
   9303 -        }
   9304 +        // BEGIN android-removed
   9305 +        // Only throw if there is a problem removing, not if missing
   9306 +        // if (c == null && k == null)
   9307 +        // {
   9308 +        //     throw new KeyStoreException("no such entry as " + alias);
   9309 +        // }
   9310 +        // END android-removed
   9311      }
   9312  
   9313      /**
   9314 @@ -439,6 +442,14 @@
   9315      
   9316      public Date engineGetCreationDate(String alias) 
   9317      {
   9318 +        // BEGIN android-added
   9319 +        if (alias == null) {
   9320 +            throw new NullPointerException("alias == null");
   9321 +        }
   9322 +        if (keys.get(alias) == null && certs.get(alias) == null) {
   9323 +            return null;
   9324 +        }
   9325 +        // END android-added
   9326          return new Date();
   9327      }
   9328  
   9329 @@ -497,6 +508,11 @@
   9330          Certificate[]   chain) 
   9331          throws KeyStoreException
   9332      {
   9333 +        // BEGIN android-added
   9334 +        if (!(key instanceof PrivateKey)) {
   9335 +            throw new KeyStoreException("PKCS12 does not support non-PrivateKeys");
   9336 +        }
   9337 +        // END android-added
   9338          if ((key instanceof PrivateKey) && (chain == null))
   9339          {
   9340              throw new KeyStoreException("no certificate chain for private key");
   9341 @@ -508,12 +524,18 @@
   9342          }
   9343  
   9344          keys.put(alias, key);
   9345 +        // BEGIN android-added
   9346 +        if (chain != null) {
   9347 +        // END android-added
   9348          certs.put(alias, chain[0]);
   9349  
   9350          for (int i = 0; i != chain.length; i++)
   9351          {
   9352              chainCerts.put(new CertId(chain[i].getPublicKey()), chain[i]);
   9353          }
   9354 +        // BEGIN android-added
   9355 +        }
   9356 +        // END android-added
   9357      }
   9358  
   9359      public int engineSize() 
   9360 @@ -1489,7 +1511,9 @@
   9361          {
   9362              byte[] res = calculatePbeMac(id_SHA1, mSalt, itCount, password, false, data);
   9363  
   9364 -            AlgorithmIdentifier     algId = new AlgorithmIdentifier(id_SHA1, new DERNull());
   9365 +            // BEGIN android-changed
   9366 +            AlgorithmIdentifier     algId = new AlgorithmIdentifier(id_SHA1, DERNull.INSTANCE);
   9367 +            // END android-changed
   9368              DigestInfo              dInfo = new DigestInfo(algId, res);
   9369  
   9370              mData = new MacData(dInfo, mSalt, itCount);
   9371 @@ -1546,32 +1570,34 @@
   9372          }
   9373      }
   9374  
   9375 -    public static class BCPKCS12KeyStore3DES
   9376 -        extends JDKPKCS12KeyStore
   9377 -    {
   9378 -        public BCPKCS12KeyStore3DES()
   9379 -        {
   9380 -            super(bcProvider, pbeWithSHAAnd3_KeyTripleDES_CBC, pbeWithSHAAnd3_KeyTripleDES_CBC);
   9381 -        }
   9382 -    }
   9383 -
   9384 -    public static class DefPKCS12KeyStore
   9385 -        extends JDKPKCS12KeyStore
   9386 -    {
   9387 -        public DefPKCS12KeyStore()
   9388 -        {
   9389 -            super(null, pbeWithSHAAnd3_KeyTripleDES_CBC, pbeWithSHAAnd40BitRC2_CBC);
   9390 -        }
   9391 -    }
   9392 -
   9393 -    public static class DefPKCS12KeyStore3DES
   9394 -        extends JDKPKCS12KeyStore
   9395 -    {
   9396 -        public DefPKCS12KeyStore3DES()
   9397 -        {
   9398 -            super(null, pbeWithSHAAnd3_KeyTripleDES_CBC, pbeWithSHAAnd3_KeyTripleDES_CBC);
   9399 -        }
   9400 -    }
   9401 +    // BEGIN android-removed
   9402 +    // public static class BCPKCS12KeyStore3DES
   9403 +    //     extends JDKPKCS12KeyStore
   9404 +    // {
   9405 +    //     public BCPKCS12KeyStore3DES()
   9406 +    //     {
   9407 +    //         super(bcProvider, pbeWithSHAAnd3_KeyTripleDES_CBC, pbeWithSHAAnd3_KeyTripleDES_CBC);
   9408 +    //     }
   9409 +    // }
   9410 +    //
   9411 +    // public static class DefPKCS12KeyStore
   9412 +    //     extends JDKPKCS12KeyStore
   9413 +    // {
   9414 +    //     public DefPKCS12KeyStore()
   9415 +    //     {
   9416 +    //         super(null, pbeWithSHAAnd3_KeyTripleDES_CBC, pbeWithSHAAnd40BitRC2_CBC);
   9417 +    //     }
   9418 +    // }
   9419 +    //
   9420 +    // public static class DefPKCS12KeyStore3DES
   9421 +    //     extends JDKPKCS12KeyStore
   9422 +    // {
   9423 +    //     public DefPKCS12KeyStore3DES()
   9424 +    //     {
   9425 +    //         super(null, pbeWithSHAAnd3_KeyTripleDES_CBC, pbeWithSHAAnd3_KeyTripleDES_CBC);
   9426 +    //     }
   9427 +    // }
   9428 +    // END android-removed
   9429  
   9430      private static class IgnoresCaseHashtable
   9431      {
   9432 @@ -1580,7 +1606,9 @@
   9433  
   9434          public void put(String key, Object value)
   9435          {
   9436 -            String lower = Strings.toLowerCase(key);
   9437 +            // BEGIN android-changed
   9438 +            String lower = (key == null) ? null : Strings.toLowerCase(key);
   9439 +            // END android-changed
   9440              String k = (String)keys.get(lower);
   9441              if (k != null)
   9442              {
   9443 @@ -1598,7 +1626,9 @@
   9444  
   9445          public Object remove(String alias)
   9446          {
   9447 -            String k = (String)keys.remove(Strings.toLowerCase(alias));
   9448 +            // BEGIN android-changed
   9449 +            String k = (String)keys.remove(alias == null ? null : Strings.toLowerCase(alias));
   9450 +            // END android-changed
   9451              if (k == null)
   9452              {
   9453                  return null;
   9454 @@ -1609,7 +1639,9 @@
   9455  
   9456          public Object get(String alias)
   9457          {
   9458 -            String k = (String)keys.get(Strings.toLowerCase(alias));
   9459 +            // BEGIN android-changed
   9460 +            String k = (String)keys.get(alias == null ? null : Strings.toLowerCase(alias));
   9461 +            // END android-changed
   9462              if (k == null)
   9463              {
   9464                  return null;
   9465 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpi.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpi.java
   9466 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpi.java	2012-03-22 15:11:48.000000000 +0000
   9467 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpi.java	2012-09-19 21:17:12.000000000 +0000
   9468 @@ -1,5 +1,8 @@
   9469  package org.bouncycastle.jce.provider;
   9470  
   9471 +// BEGIN android-added
   9472 +import java.math.BigInteger;
   9473 +// END android-added
   9474  import java.security.InvalidAlgorithmParameterException;
   9475  import java.security.PublicKey;
   9476  import java.security.cert.CertPath;
   9477 @@ -33,6 +36,9 @@
   9478  public class PKIXCertPathValidatorSpi
   9479          extends CertPathValidatorSpi
   9480  {
   9481 +    // BEGIN android-added
   9482 +    private final static CertBlacklist blacklist = new CertBlacklist();
   9483 +    // END android-added
   9484  
   9485      public CertPathValidatorResult engineValidate(
   9486              CertPath certPath,
   9487 @@ -75,6 +81,22 @@
   9488          {
   9489              throw new CertPathValidatorException("Certification path is empty.", null, certPath, 0);
   9490          }
   9491 +        // BEGIN android-added
   9492 +        {
   9493 +            X509Certificate cert = (X509Certificate) certs.get(0);
   9494 +
   9495 +            if (cert != null) {
   9496 +                BigInteger serial = cert.getSerialNumber();
   9497 +                if (blacklist.isSerialNumberBlackListed(serial)) {
   9498 +                    // emulate CRL exception message in RFC3280CertPathUtilities.checkCRLs
   9499 +                    String message = "Certificate revocation of serial 0x" + serial.toString(16);
   9500 +                    System.out.println(message);
   9501 +                    AnnotatedException e = new AnnotatedException(message);
   9502 +                    throw new CertPathValidatorException(e.getMessage(), e, certPath, 0);
   9503 +                }
   9504 +            }
   9505 +        }
   9506 +        // END android-added
   9507  
   9508          //
   9509          // (b)
   9510 @@ -251,6 +273,15 @@
   9511  
   9512          for (index = certs.size() - 1; index >= 0; index--)
   9513          {
   9514 +            // BEGIN android-added
   9515 +            if (blacklist.isPublicKeyBlackListed(workingPublicKey)) {
   9516 +                // emulate CRL exception message in RFC3280CertPathUtilities.checkCRLs
   9517 +                String message = "Certificate revocation of public key " + workingPublicKey;
   9518 +                System.out.println(message);
   9519 +                AnnotatedException e = new AnnotatedException(message);
   9520 +                throw new CertPathValidatorException(e.getMessage(), e, certPath, index);
   9521 +            }
   9522 +            // END android-added
   9523              // try
   9524              // {
   9525              //
   9526 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/PKIXNameConstraintValidator.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/PKIXNameConstraintValidator.java
   9527 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/PKIXNameConstraintValidator.java	2012-03-22 15:11:48.000000000 +0000
   9528 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/PKIXNameConstraintValidator.java	2012-09-19 21:17:12.000000000 +0000
   9529 @@ -1533,7 +1533,9 @@
   9530          for (Enumeration e = permitted.getObjects(); e.hasMoreElements();)
   9531          {
   9532              GeneralSubtree subtree = GeneralSubtree.getInstance(e.nextElement());
   9533 -            Integer tagNo = new Integer(subtree.getBase().getTagNo());
   9534 +            // BEGIN android-changed
   9535 +            Integer tagNo = Integer.valueOf(subtree.getBase().getTagNo());
   9536 +            // END android-changed
   9537              if (subtreesMap.get(tagNo) == null)
   9538              {
   9539                  subtreesMap.put(tagNo, new HashSet());
   9540 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/X509CertificateObject.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/X509CertificateObject.java
   9541 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/X509CertificateObject.java	2012-03-22 15:11:48.000000000 +0000
   9542 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/X509CertificateObject.java	2012-09-19 21:17:12.000000000 +0000
   9543 @@ -544,12 +544,20 @@
   9544          }
   9545      }
   9546  
   9547 +    // BEGIN android-changed
   9548 +    private byte[] encoded;
   9549 +    // END android-changed
   9550      public byte[] getEncoded()
   9551          throws CertificateEncodingException
   9552      {
   9553          try
   9554          {
   9555 -            return c.getEncoded(ASN1Encoding.DER);
   9556 +            // BEGIN android-changed
   9557 +            if (encoded == null) {
   9558 +                encoded = c.getEncoded(ASN1Encoding.DER);
   9559 +            }
   9560 +            return encoded;
   9561 +            // END android-changed
   9562          }
   9563          catch (IOException e)
   9564          {
   9565 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/X509SignatureUtil.java bcprov-jdk15on-147/org/bouncycastle/jce/provider/X509SignatureUtil.java
   9566 --- bcprov-jdk15on-147.orig/org/bouncycastle/jce/provider/X509SignatureUtil.java	2012-03-22 15:11:48.000000000 +0000
   9567 +++ bcprov-jdk15on-147/org/bouncycastle/jce/provider/X509SignatureUtil.java	2012-09-19 21:17:12.000000000 +0000
   9568 @@ -14,7 +14,9 @@
   9569  import org.bouncycastle.asn1.ASN1Sequence;
   9570  import org.bouncycastle.asn1.DERNull;
   9571  import org.bouncycastle.asn1.DERObjectIdentifier;
   9572 -import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   9573 +// BEGIN android-removed
   9574 +// import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   9575 +// END android-removed
   9576  import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
   9577  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   9578  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   9579 @@ -25,7 +27,9 @@
   9580  
   9581  class X509SignatureUtil
   9582  {
   9583 -    private static final ASN1Null       derNull = new DERNull();
   9584 +    // BEGIN android-changed
   9585 +    private static final ASN1Null       derNull = DERNull.INSTANCE;
   9586 +    // END android-changed
   9587      
   9588      static void setSignatureParameters(
   9589          Signature signature,
   9590 @@ -66,12 +70,14 @@
   9591          
   9592          if (params != null && !derNull.equals(params))
   9593          {
   9594 -            if (sigAlgId.getObjectId().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
   9595 -            {
   9596 -                RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
   9597 -                
   9598 -                return getDigestAlgName(rsaParams.getHashAlgorithm().getObjectId()) + "withRSAandMGF1";
   9599 -            }
   9600 +            // BEGIN android-removed
   9601 +            // if (sigAlgId.getObjectId().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
   9602 +            // {
   9603 +            //     RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
   9604 +            //
   9605 +            //     return getDigestAlgName(rsaParams.getHashAlgorithm().getObjectId()) + "withRSAandMGF1";
   9606 +            // }
   9607 +            // END android-removed
   9608              if (sigAlgId.getObjectId().equals(X9ObjectIdentifiers.ecdsa_with_SHA2))
   9609              {
   9610                  ASN1Sequence ecDsaParams = ASN1Sequence.getInstance(params);
   9611 @@ -98,10 +104,12 @@
   9612          {
   9613              return "SHA1";
   9614          }
   9615 -        else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID))
   9616 -        {
   9617 -            return "SHA224";
   9618 -        }
   9619 +        // BEGIN android-removed
   9620 +        // else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID))
   9621 +        // {
   9622 +        //     return "SHA224";
   9623 +        // }
   9624 +        // END android-removed
   9625          else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOID))
   9626          {
   9627              return "SHA256";
   9628 @@ -114,22 +122,24 @@
   9629          {
   9630              return "SHA512";
   9631          }
   9632 -        else if (TeleTrusTObjectIdentifiers.ripemd128.equals(digestAlgOID))
   9633 -        {
   9634 -            return "RIPEMD128";
   9635 -        }
   9636 -        else if (TeleTrusTObjectIdentifiers.ripemd160.equals(digestAlgOID))
   9637 -        {
   9638 -            return "RIPEMD160";
   9639 -        }
   9640 -        else if (TeleTrusTObjectIdentifiers.ripemd256.equals(digestAlgOID))
   9641 -        {
   9642 -            return "RIPEMD256";
   9643 -        }
   9644 -        else if (CryptoProObjectIdentifiers.gostR3411.equals(digestAlgOID))
   9645 -        {
   9646 -            return "GOST3411";
   9647 -        }
   9648 +        // BEGIN android-removed
   9649 +        // else if (TeleTrusTObjectIdentifiers.ripemd128.equals(digestAlgOID))
   9650 +        // {
   9651 +        //     return "RIPEMD128";
   9652 +        // }
   9653 +        // else if (TeleTrusTObjectIdentifiers.ripemd160.equals(digestAlgOID))
   9654 +        // {
   9655 +        //     return "RIPEMD160";
   9656 +        // }
   9657 +        // else if (TeleTrusTObjectIdentifiers.ripemd256.equals(digestAlgOID))
   9658 +        // {
   9659 +        //     return "RIPEMD256";
   9660 +        // }
   9661 +        // else if (CryptoProObjectIdentifiers.gostR3411.equals(digestAlgOID))
   9662 +        // {
   9663 +        //     return "GOST3411";
   9664 +        // }
   9665 +        // END android-removed
   9666          else
   9667          {
   9668              return digestAlgOID.getId();            
   9669 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/x509/X509Util.java bcprov-jdk15on-147/org/bouncycastle/x509/X509Util.java
   9670 --- bcprov-jdk15on-147.orig/org/bouncycastle/x509/X509Util.java	2012-03-22 15:11:48.000000000 +0000
   9671 +++ bcprov-jdk15on-147/org/bouncycastle/x509/X509Util.java	2012-09-19 21:17:12.000000000 +0000
   9672 @@ -25,12 +25,16 @@
   9673  import org.bouncycastle.asn1.ASN1Integer;
   9674  import org.bouncycastle.asn1.DERNull;
   9675  import org.bouncycastle.asn1.DERObjectIdentifier;
   9676 -import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   9677 +// BEGIN android-removed
   9678 +// import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
   9679 +// END android-removed
   9680  import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
   9681  import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
   9682  import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
   9683  import org.bouncycastle.asn1.pkcs.RSASSAPSSparams;
   9684 -import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   9685 +// BEGIN android-removed
   9686 +// import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
   9687 +// END android-removed
   9688  import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
   9689  import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
   9690  import org.bouncycastle.jce.X509Principal;
   9691 @@ -44,14 +48,18 @@
   9692      
   9693      static
   9694      {   
   9695 -        algorithms.put("MD2WITHRSAENCRYPTION", PKCSObjectIdentifiers.md2WithRSAEncryption);
   9696 -        algorithms.put("MD2WITHRSA", PKCSObjectIdentifiers.md2WithRSAEncryption);
   9697 +        // BEGIN android-removed
   9698 +        // algorithms.put("MD2WITHRSAENCRYPTION", PKCSObjectIdentifiers.md2WithRSAEncryption);
   9699 +        // algorithms.put("MD2WITHRSA", PKCSObjectIdentifiers.md2WithRSAEncryption);
   9700 +        // END android-removed
   9701          algorithms.put("MD5WITHRSAENCRYPTION", PKCSObjectIdentifiers.md5WithRSAEncryption);
   9702          algorithms.put("MD5WITHRSA", PKCSObjectIdentifiers.md5WithRSAEncryption);
   9703          algorithms.put("SHA1WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha1WithRSAEncryption);
   9704          algorithms.put("SHA1WITHRSA", PKCSObjectIdentifiers.sha1WithRSAEncryption);
   9705 -        algorithms.put("SHA224WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   9706 -        algorithms.put("SHA224WITHRSA", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   9707 +        // BEGIN android-removed
   9708 +        // algorithms.put("SHA224WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   9709 +        // algorithms.put("SHA224WITHRSA", PKCSObjectIdentifiers.sha224WithRSAEncryption);
   9710 +        // END android-removed
   9711          algorithms.put("SHA256WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha256WithRSAEncryption);
   9712          algorithms.put("SHA256WITHRSA", PKCSObjectIdentifiers.sha256WithRSAEncryption);
   9713          algorithms.put("SHA384WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha384WithRSAEncryption);
   9714 @@ -59,45 +67,59 @@
   9715          algorithms.put("SHA512WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha512WithRSAEncryption);
   9716          algorithms.put("SHA512WITHRSA", PKCSObjectIdentifiers.sha512WithRSAEncryption);
   9717          algorithms.put("SHA1WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   9718 -        algorithms.put("SHA224WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   9719 +        // BEGIN android-removed
   9720 +        // algorithms.put("SHA224WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   9721 +        // END android-removed
   9722          algorithms.put("SHA256WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   9723          algorithms.put("SHA384WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   9724          algorithms.put("SHA512WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
   9725 -        algorithms.put("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   9726 -        algorithms.put("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   9727 -        algorithms.put("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   9728 -        algorithms.put("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   9729 -        algorithms.put("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   9730 -        algorithms.put("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   9731 +        // BEGIN android-removed
   9732 +        // algorithms.put("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   9733 +        // algorithms.put("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
   9734 +        // algorithms.put("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   9735 +        // algorithms.put("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
   9736 +        // algorithms.put("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   9737 +        // algorithms.put("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
   9738 +        // END android-removed
   9739          algorithms.put("SHA1WITHDSA", X9ObjectIdentifiers.id_dsa_with_sha1);
   9740          algorithms.put("DSAWITHSHA1", X9ObjectIdentifiers.id_dsa_with_sha1);
   9741 -        algorithms.put("SHA224WITHDSA", NISTObjectIdentifiers.dsa_with_sha224);
   9742 +        // BEGIN android-removed
   9743 +        // algorithms.put("SHA224WITHDSA", NISTObjectIdentifiers.dsa_with_sha224);
   9744 +        // END android-removed
   9745          algorithms.put("SHA256WITHDSA", NISTObjectIdentifiers.dsa_with_sha256);
   9746          algorithms.put("SHA384WITHDSA", NISTObjectIdentifiers.dsa_with_sha384);
   9747          algorithms.put("SHA512WITHDSA", NISTObjectIdentifiers.dsa_with_sha512);
   9748          algorithms.put("SHA1WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA1);
   9749          algorithms.put("ECDSAWITHSHA1", X9ObjectIdentifiers.ecdsa_with_SHA1);
   9750 -        algorithms.put("SHA224WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA224);
   9751 +        // BEGIN android-removed
   9752 +        // algorithms.put("SHA224WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA224);
   9753 +        // END android-removed
   9754          algorithms.put("SHA256WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA256);
   9755          algorithms.put("SHA384WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA384);
   9756          algorithms.put("SHA512WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA512);
   9757 -        algorithms.put("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   9758 -        algorithms.put("GOST3411WITHGOST3410-94", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   9759 -        algorithms.put("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9760 -        algorithms.put("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9761 -        algorithms.put("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9762 +        // BEGIN android-removed
   9763 +        // algorithms.put("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   9764 +        // algorithms.put("GOST3411WITHGOST3410-94", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   9765 +        // algorithms.put("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9766 +        // algorithms.put("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9767 +        // algorithms.put("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9768 +        // END android-removed
   9769  
   9770          //
   9771          // According to RFC 3279, the ASN.1 encoding SHALL (id-dsa-with-sha1) or MUST (ecdsa-with-SHA*) omit the parameters field. 
   9772          // The parameters field SHALL be NULL for RSA based signature algorithms.
   9773          //
   9774          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA1);
   9775 -        noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA224);
   9776 +        // BEGIN android-removed
   9777 +        // noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA224);
   9778 +        // END android-removed
   9779          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA256);
   9780          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA384);
   9781          noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA512);
   9782          noParams.add(X9ObjectIdentifiers.id_dsa_with_sha1);
   9783 -        noParams.add(NISTObjectIdentifiers.dsa_with_sha224);
   9784 +        // BEGIN android-removed
   9785 +        // noParams.add(NISTObjectIdentifiers.dsa_with_sha224);
   9786 +        // END android-removed
   9787          noParams.add(NISTObjectIdentifiers.dsa_with_sha256);
   9788          noParams.add(NISTObjectIdentifiers.dsa_with_sha384);
   9789          noParams.add(NISTObjectIdentifiers.dsa_with_sha512);
   9790 @@ -105,25 +127,39 @@
   9791          //
   9792          // RFC 4491
   9793          //
   9794 -        noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   9795 -        noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9796 +        // BEGIN android-removed
   9797 +        // noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
   9798 +        // noParams.add(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
   9799 +        // END android-removed
   9800  
   9801          //
   9802          // explicit params
   9803          //
   9804 -        AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, new DERNull());
   9805 +        // BEGIN android-changed
   9806 +        AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
   9807 +        // END android-changed
   9808          params.put("SHA1WITHRSAANDMGF1", creatPSSParams(sha1AlgId, 20));
   9809  
   9810 -        AlgorithmIdentifier sha224AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha224, new DERNull());
   9811 -        params.put("SHA224WITHRSAANDMGF1", creatPSSParams(sha224AlgId, 28));
   9812 -
   9813 -        AlgorithmIdentifier sha256AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256, new DERNull());
   9814 +        // BEGIN android-removed
   9815 +        // // BEGIN android-changed
   9816 +        // AlgorithmIdentifier sha224AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha224, DERNull.INSTANCE);
   9817 +        // // END android-changed
   9818 +        // params.put("SHA224WITHRSAANDMGF1", creatPSSParams(sha224AlgId, 28));
   9819 +        // END android-removed
   9820 +
   9821 +        // BEGIN android-changed
   9822 +        AlgorithmIdentifier sha256AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256, DERNull.INSTANCE);
   9823 +        // END android-changed
   9824          params.put("SHA256WITHRSAANDMGF1", creatPSSParams(sha256AlgId, 32));
   9825  
   9826 -        AlgorithmIdentifier sha384AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha384, new DERNull());
   9827 +        // BEGIN android-changed
   9828 +        AlgorithmIdentifier sha384AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha384, DERNull.INSTANCE);
   9829 +        // END android-changed
   9830          params.put("SHA384WITHRSAANDMGF1", creatPSSParams(sha384AlgId, 48));
   9831  
   9832 -        AlgorithmIdentifier sha512AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha512, new DERNull());
   9833 +        // BEGIN android-changed
   9834 +        AlgorithmIdentifier sha512AlgId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha512, DERNull.INSTANCE);
   9835 +        // END android-changed
   9836          params.put("SHA512WITHRSAANDMGF1", creatPSSParams(sha512AlgId, 64));
   9837      }
   9838  
   9839 @@ -166,7 +202,9 @@
   9840          }
   9841          else
   9842          {
   9843 -            return new AlgorithmIdentifier(sigOid, new DERNull());
   9844 +            // BEGIN android-changed
   9845 +            return new AlgorithmIdentifier(sigOid, DERNull.INSTANCE);
   9846 +            // END android-changed
   9847          }
   9848      }
   9849      
   9850 diff -Naur bcprov-jdk15on-147.orig/org/bouncycastle/x509/extension/X509ExtensionUtil.java bcprov-jdk15on-147/org/bouncycastle/x509/extension/X509ExtensionUtil.java
   9851 --- bcprov-jdk15on-147.orig/org/bouncycastle/x509/extension/X509ExtensionUtil.java	2012-03-22 15:11:48.000000000 +0000
   9852 +++ bcprov-jdk15on-147/org/bouncycastle/x509/extension/X509ExtensionUtil.java	2012-09-19 21:17:12.000000000 +0000
   9853 @@ -62,7 +62,9 @@
   9854              {
   9855                  GeneralName genName = GeneralName.getInstance(it.nextElement());
   9856                  List list = new ArrayList();
   9857 -                list.add(new Integer(genName.getTagNo()));
   9858 +                // BEGIN android-changed
   9859 +                list.add(Integer.valueOf(genName.getTagNo()));
   9860 +                // END android-changed
   9861                  switch (genName.getTagNo())
   9862                  {
   9863                  case GeneralName.ediPartyName:
   9864