001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.security.provider.crypto;
019:
020: import java.security.Provider;
021: import java.security.AccessController;
022:
023: import org.apache.harmony.security.provider.crypto.RandomBitsSupplier;
024:
025: /**
026: * Implementation of Provider for SecureRandom, MessageDigest and Signature
027: * using a Secure Hash Algorithm, SHA-1;
028: * see SECURE HASH STANDARD, FIPS PUB 180-1 (http://www.itl.nist.gov/fipspubs/fip180-1.htm) <BR>
029: * <BR>
030: * The implementation supports "SHA1PRNG", "SHA-1" and "SHA1withDSA" algorithms described in
031: * JavaTM Cryptography Architecture, API Specification & Reference
032: */
033:
034: public final class CryptoProvider extends Provider {
035:
036: private static final long serialVersionUID = 7991202868423459598L;
037:
038: /**
039: * Creates a Provider and puts parameters
040: */
041: public CryptoProvider() {
042:
043: super ("Crypto", 1.0, //$NON-NLS-1$
044: "HARMONY (SHA1 digest; SecureRandom; SHA1withDSA signature)"); //$NON-NLS-1$
045:
046: // names of classes implementing services
047: final String MD_NAME = "org.apache.harmony.security.provider.crypto.SHA1_MessageDigestImpl"; //$NON-NLS-1$
048: final String SR_NAME = "org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl"; //$NON-NLS-1$
049:
050: final String SIGN_NAME = "org.apache.harmony.security.provider.crypto.SHA1withDSA_SignatureImpl"; //$NON-NLS-1$
051:
052: final String SIGN_ALIAS = "SHA1withDSA"; //$NON-NLS-1$
053:
054: final String KEYF_NAME = "org.apache.harmony.security.provider.crypto.DSAKeyFactoryImpl"; //$NON-NLS-1$
055:
056: AccessController
057: .doPrivileged(new java.security.PrivilegedAction<Void>() {
058:
059: public Void run() {
060:
061: put("MessageDigest.SHA-1", MD_NAME); //$NON-NLS-1$
062: put(
063: "MessageDigest.SHA-1 ImplementedIn", "Software"); //$NON-NLS-1$ //$NON-NLS-2$
064: put("Alg.Alias.MessageDigest.SHA1", "SHA-1"); //$NON-NLS-1$ //$NON-NLS-2$
065: put("Alg.Alias.MessageDigest.SHA", "SHA-1"); //$NON-NLS-1$ //$NON-NLS-2$
066:
067: if (RandomBitsSupplier.isServiceAvailable()) {
068: put("SecureRandom.SHA1PRNG", SR_NAME); //$NON-NLS-1$
069: put(
070: "SecureRandom.SHA1PRNG ImplementedIn", "Software"); //$NON-NLS-1$ //$NON-NLS-2$
071: }
072:
073: put("Signature.SHA1withDSA", SIGN_NAME); //$NON-NLS-1$
074: put(
075: "Signature.SHA1withDSA ImplementedIn", "Software"); //$NON-NLS-1$ //$NON-NLS-2$
076: put(
077: "Alg.Alias.Signature.SHAwithDSA", SIGN_ALIAS); //$NON-NLS-1$
078: put(
079: "Alg.Alias.Signature.DSAwithSHA1", SIGN_ALIAS); //$NON-NLS-1$
080: put("Alg.Alias.Signature.SHA1/DSA", SIGN_ALIAS); //$NON-NLS-1$
081: put("Alg.Alias.Signature.SHA/DSA", SIGN_ALIAS); //$NON-NLS-1$
082: put("Alg.Alias.Signature.SHA-1/DSA", SIGN_ALIAS); //$NON-NLS-1$
083: put("Alg.Alias.Signature.DSA", SIGN_ALIAS); //$NON-NLS-1$
084: put("Alg.Alias.Signature.DSS", SIGN_ALIAS); //$NON-NLS-1$
085:
086: put(
087: "Alg.Alias.Signature.OID.1.2.840.10040.4.3", SIGN_ALIAS); //$NON-NLS-1$
088: put(
089: "Alg.Alias.Signature.1.2.840.10040.4.3", SIGN_ALIAS); //$NON-NLS-1$
090: put(
091: "Alg.Alias.Signature.1.3.14.3.2.13", SIGN_ALIAS); //$NON-NLS-1$
092: put(
093: "Alg.Alias.Signature.1.3.14.3.2.27", SIGN_ALIAS); //$NON-NLS-1$
094:
095: put("KeyFactory.DSA", KEYF_NAME); //$NON-NLS-1$
096: put("KeyFactory.DSA ImplementedIn", "Software"); //$NON-NLS-1$ //$NON-NLS-2$
097: put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSA"); //$NON-NLS-1$ //$NON-NLS-2$
098: put(
099: "Alg.Alias.KeyFactory.1.2.840.10040.4.1", "DSA"); //$NON-NLS-1$ //$NON-NLS-2$
100:
101: return null;
102: }
103: });
104: }
105: }
|