jdk/src/share/classes/sun/security/x509/AlgorithmId.java
changeset 12685 8a448b5b9006
parent 10336 0bb1999251f8
child 13361 bda5c2354fc6
equal deleted inserted replaced
12676:3b7fae360d04 12685:8a448b5b9006
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   173 
   173 
   174             // Several AlgorithmId should omit the whole parameter part when
   174             // Several AlgorithmId should omit the whole parameter part when
   175             // it's NULL. They are ---
   175             // it's NULL. They are ---
   176             // rfc3370 2.1: Implementations SHOULD generate SHA-1
   176             // rfc3370 2.1: Implementations SHOULD generate SHA-1
   177             // AlgorithmIdentifiers with absent parameters.
   177             // AlgorithmIdentifiers with absent parameters.
   178             // rfc3447 C1: When id-sha1, id-sha256, id-sha384 and id-sha512
   178             // rfc3447 C1: When id-sha1, id-sha224, id-sha256, id-sha384 and
   179             // are used in an AlgorithmIdentifier the parameters (which are
   179             // id-sha512 are used in an AlgorithmIdentifier the parameters
   180             // optional) SHOULD be omitted.
   180             // (which are optional) SHOULD be omitted.
   181             // rfc3279 2.3.2: The id-dsa algorithm syntax includes optional
   181             // rfc3279 2.3.2: The id-dsa algorithm syntax includes optional
   182             // domain parameters... When omitted, the parameters component
   182             // domain parameters... When omitted, the parameters component
   183             // MUST be omitted entirely
   183             // MUST be omitted entirely
   184             // rfc3370 3.1: When the id-dsa-with-sha1 algorithm identifier
   184             // rfc3370 3.1: When the id-dsa-with-sha1 algorithm identifier
   185             // is used, the AlgorithmIdentifier parameters field MUST be absent.
   185             // is used, the AlgorithmIdentifier parameters field MUST be absent.
   186             /*if (
   186             /*if (
   187                 algid.equals((Object)SHA_oid) ||
   187                 algid.equals((Object)SHA_oid) ||
       
   188                 algid.equals((Object)SHA224_oid) ||
   188                 algid.equals((Object)SHA256_oid) ||
   189                 algid.equals((Object)SHA256_oid) ||
   189                 algid.equals((Object)SHA384_oid) ||
   190                 algid.equals((Object)SHA384_oid) ||
   190                 algid.equals((Object)SHA512_oid) ||
   191                 algid.equals((Object)SHA512_oid) ||
   191                 algid.equals((Object)DSA_oid) ||
   192                 algid.equals((Object)DSA_oid) ||
   192                 algid.equals((Object)sha1WithDSA_oid)) {
   193                 algid.equals((Object)sha1WithDSA_oid)) {
   486         }
   487         }
   487         if (name.equalsIgnoreCase("SHA-512") ||
   488         if (name.equalsIgnoreCase("SHA-512") ||
   488             name.equalsIgnoreCase("SHA512")) {
   489             name.equalsIgnoreCase("SHA512")) {
   489             return AlgorithmId.SHA512_oid;
   490             return AlgorithmId.SHA512_oid;
   490         }
   491         }
   491 
   492         if (name.equalsIgnoreCase("SHA-224") ||
       
   493             name.equalsIgnoreCase("SHA224")) {
       
   494             return AlgorithmId.SHA224_oid;
       
   495         }
   492 
   496 
   493         // Various public key algorithms
   497         // Various public key algorithms
   494         if (name.equalsIgnoreCase("RSA")) {
   498         if (name.equalsIgnoreCase("RSA")) {
   495             return AlgorithmId.RSAEncryption_oid;
   499             return AlgorithmId.RSAEncryption_oid;
   496         }
   500         }
   623      * OID = 1.3.14.3.2.26. Old SHA-0 OID: 1.3.14.3.2.18.
   627      * OID = 1.3.14.3.2.26. Old SHA-0 OID: 1.3.14.3.2.18.
   624      */
   628      */
   625     public static final ObjectIdentifier SHA_oid =
   629     public static final ObjectIdentifier SHA_oid =
   626     ObjectIdentifier.newInternal(new int[] {1, 3, 14, 3, 2, 26});
   630     ObjectIdentifier.newInternal(new int[] {1, 3, 14, 3, 2, 26});
   627 
   631 
       
   632     public static final ObjectIdentifier SHA224_oid =
       
   633     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 4});
       
   634 
   628     public static final ObjectIdentifier SHA256_oid =
   635     public static final ObjectIdentifier SHA256_oid =
   629     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 1});
   636     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 1});
   630 
   637 
   631     public static final ObjectIdentifier SHA384_oid =
   638     public static final ObjectIdentifier SHA384_oid =
   632     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 2});
   639     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 2});
   662                                        { 1, 2, 840, 113549, 1, 1, 4 };
   669                                        { 1, 2, 840, 113549, 1, 1, 4 };
   663     private static final int sha1WithRSAEncryption_data[] =
   670     private static final int sha1WithRSAEncryption_data[] =
   664                                        { 1, 2, 840, 113549, 1, 1, 5 };
   671                                        { 1, 2, 840, 113549, 1, 1, 5 };
   665     private static final int sha1WithRSAEncryption_OIW_data[] =
   672     private static final int sha1WithRSAEncryption_OIW_data[] =
   666                                        { 1, 3, 14, 3, 2, 29 };
   673                                        { 1, 3, 14, 3, 2, 29 };
       
   674     private static final int sha224WithRSAEncryption_data[] =
       
   675                                        { 1, 2, 840, 113549, 1, 1, 14 };
   667     private static final int sha256WithRSAEncryption_data[] =
   676     private static final int sha256WithRSAEncryption_data[] =
   668                                        { 1, 2, 840, 113549, 1, 1, 11 };
   677                                        { 1, 2, 840, 113549, 1, 1, 11 };
   669     private static final int sha384WithRSAEncryption_data[] =
   678     private static final int sha384WithRSAEncryption_data[] =
   670                                        { 1, 2, 840, 113549, 1, 1, 12 };
   679                                        { 1, 2, 840, 113549, 1, 1, 12 };
   671     private static final int sha512WithRSAEncryption_data[] =
   680     private static final int sha512WithRSAEncryption_data[] =
   679 
   688 
   680     public static final ObjectIdentifier md2WithRSAEncryption_oid;
   689     public static final ObjectIdentifier md2WithRSAEncryption_oid;
   681     public static final ObjectIdentifier md5WithRSAEncryption_oid;
   690     public static final ObjectIdentifier md5WithRSAEncryption_oid;
   682     public static final ObjectIdentifier sha1WithRSAEncryption_oid;
   691     public static final ObjectIdentifier sha1WithRSAEncryption_oid;
   683     public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid;
   692     public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid;
       
   693     public static final ObjectIdentifier sha224WithRSAEncryption_oid;
   684     public static final ObjectIdentifier sha256WithRSAEncryption_oid;
   694     public static final ObjectIdentifier sha256WithRSAEncryption_oid;
   685     public static final ObjectIdentifier sha384WithRSAEncryption_oid;
   695     public static final ObjectIdentifier sha384WithRSAEncryption_oid;
   686     public static final ObjectIdentifier sha512WithRSAEncryption_oid;
   696     public static final ObjectIdentifier sha512WithRSAEncryption_oid;
   687     public static final ObjectIdentifier shaWithDSA_OIW_oid;
   697     public static final ObjectIdentifier shaWithDSA_OIW_oid;
   688     public static final ObjectIdentifier sha1WithDSA_OIW_oid;
   698     public static final ObjectIdentifier sha1WithDSA_OIW_oid;
   808      */
   818      */
   809         sha1WithRSAEncryption_OIW_oid =
   819         sha1WithRSAEncryption_OIW_oid =
   810             ObjectIdentifier.newInternal(sha1WithRSAEncryption_OIW_data);
   820             ObjectIdentifier.newInternal(sha1WithRSAEncryption_OIW_data);
   811 
   821 
   812     /**
   822     /**
       
   823      * Identifies a signing algorithm where a SHA224 digest is
       
   824      * encrypted using an RSA private key; defined by PKCS #1.
       
   825      * OID = 1.2.840.113549.1.1.14
       
   826      */
       
   827         sha224WithRSAEncryption_oid =
       
   828             ObjectIdentifier.newInternal(sha224WithRSAEncryption_data);
       
   829 
       
   830     /**
   813      * Identifies a signing algorithm where a SHA256 digest is
   831      * Identifies a signing algorithm where a SHA256 digest is
   814      * encrypted using an RSA private key; defined by PKCS #1.
   832      * encrypted using an RSA private key; defined by PKCS #1.
   815      * OID = 1.2.840.113549.1.1.11
   833      * OID = 1.2.840.113549.1.1.11
   816      */
   834      */
   817         sha256WithRSAEncryption_oid =
   835         sha256WithRSAEncryption_oid =
   857 
   875 
   858         nameTable = new HashMap<ObjectIdentifier,String>();
   876         nameTable = new HashMap<ObjectIdentifier,String>();
   859         nameTable.put(MD5_oid, "MD5");
   877         nameTable.put(MD5_oid, "MD5");
   860         nameTable.put(MD2_oid, "MD2");
   878         nameTable.put(MD2_oid, "MD2");
   861         nameTable.put(SHA_oid, "SHA");
   879         nameTable.put(SHA_oid, "SHA");
       
   880         nameTable.put(SHA224_oid, "SHA224");
   862         nameTable.put(SHA256_oid, "SHA256");
   881         nameTable.put(SHA256_oid, "SHA256");
   863         nameTable.put(SHA384_oid, "SHA384");
   882         nameTable.put(SHA384_oid, "SHA384");
   864         nameTable.put(SHA512_oid, "SHA512");
   883         nameTable.put(SHA512_oid, "SHA512");
   865         nameTable.put(RSAEncryption_oid, "RSA");
   884         nameTable.put(RSAEncryption_oid, "RSA");
   866         nameTable.put(RSA_oid, "RSA");
   885         nameTable.put(RSA_oid, "RSA");
   879         nameTable.put(sha1WithDSA_oid, "SHA1withDSA");
   898         nameTable.put(sha1WithDSA_oid, "SHA1withDSA");
   880         nameTable.put(sha1WithDSA_OIW_oid, "SHA1withDSA");
   899         nameTable.put(sha1WithDSA_OIW_oid, "SHA1withDSA");
   881         nameTable.put(shaWithDSA_OIW_oid, "SHA1withDSA");
   900         nameTable.put(shaWithDSA_OIW_oid, "SHA1withDSA");
   882         nameTable.put(sha1WithRSAEncryption_oid, "SHA1withRSA");
   901         nameTable.put(sha1WithRSAEncryption_oid, "SHA1withRSA");
   883         nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA");
   902         nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA");
       
   903         nameTable.put(sha224WithRSAEncryption_oid, "SHA224withRSA");
   884         nameTable.put(sha256WithRSAEncryption_oid, "SHA256withRSA");
   904         nameTable.put(sha256WithRSAEncryption_oid, "SHA256withRSA");
   885         nameTable.put(sha384WithRSAEncryption_oid, "SHA384withRSA");
   905         nameTable.put(sha384WithRSAEncryption_oid, "SHA384withRSA");
   886         nameTable.put(sha512WithRSAEncryption_oid, "SHA512withRSA");
   906         nameTable.put(sha512WithRSAEncryption_oid, "SHA512withRSA");
   887         nameTable.put(pbeWithMD5AndDES_oid, "PBEWithMD5AndDES");
   907         nameTable.put(pbeWithMD5AndDES_oid, "PBEWithMD5AndDES");
   888         nameTable.put(pbeWithMD5AndRC2_oid, "PBEWithMD5AndRC2");
   908         nameTable.put(pbeWithMD5AndRC2_oid, "PBEWithMD5AndRC2");