Search in sources :

Example 6 with SHA256Digest

use of com.github.zhenwei.core.crypto.digests.SHA256Digest in project LinLong-Java by zhenwei1108.

the class EnvelopedDataHelper method createTable.

private static Map createTable() {
    Map table = new HashMap();
    table.put(PKCSObjectIdentifiers.id_hmacWithSHA1, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA1Digest();
        }
    });
    table.put(PKCSObjectIdentifiers.id_hmacWithSHA224, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA224Digest();
        }
    });
    table.put(PKCSObjectIdentifiers.id_hmacWithSHA256, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA256Digest();
        }
    });
    table.put(PKCSObjectIdentifiers.id_hmacWithSHA384, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA384Digest();
        }
    });
    table.put(PKCSObjectIdentifiers.id_hmacWithSHA512, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA512Digest();
        }
    });
    return Collections.unmodifiableMap(table);
}
Also used : ExtendedDigest(com.github.zhenwei.core.crypto.ExtendedDigest) SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) SHA224Digest(com.github.zhenwei.core.crypto.digests.SHA224Digest) HashMap(java.util.HashMap) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) SHA1Digest(com.github.zhenwei.core.crypto.digests.SHA1Digest) BcDigestProvider(com.github.zhenwei.pkix.operator.bc.BcDigestProvider) HashMap(java.util.HashMap) Map(java.util.Map) SHA384Digest(com.github.zhenwei.core.crypto.digests.SHA384Digest) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 7 with SHA256Digest

use of com.github.zhenwei.core.crypto.digests.SHA256Digest in project LinLong-Java by zhenwei1108.

the class XMSSKeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof XMSSParameterSpec)) {
        throw new InvalidAlgorithmParameterException("parameter object not a XMSSParameterSpec");
    }
    XMSSParameterSpec xmssParams = (XMSSParameterSpec) params;
    if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHA256)) {
        treeDigest = NISTObjectIdentifiers.id_sha256;
        param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHA256Digest()), random);
    } else if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHA512)) {
        treeDigest = NISTObjectIdentifiers.id_sha512;
        param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHA512Digest()), random);
    } else if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHAKE128)) {
        treeDigest = NISTObjectIdentifiers.id_shake128;
        param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHAKEDigest(128)), random);
    } else if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHAKE256)) {
        treeDigest = NISTObjectIdentifiers.id_shake256;
        param = new XMSSKeyGenerationParameters(new XMSSParameters(xmssParams.getHeight(), new SHAKEDigest(256)), random);
    }
    engine.init(param);
    initialised = true;
}
Also used : SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) XMSSParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSParameters) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) XMSSKeyGenerationParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSKeyGenerationParameters) XMSSParameterSpec(com.github.zhenwei.provider.jcajce.spec.XMSSParameterSpec) SHAKEDigest(com.github.zhenwei.core.crypto.digests.SHAKEDigest)

Example 8 with SHA256Digest

use of com.github.zhenwei.core.crypto.digests.SHA256Digest in project LinLong-Java by zhenwei1108.

the class BcDefaultDigestProvider method createTable.

private static Map createTable() {
    Map table = new HashMap();
    table.put(OIWObjectIdentifiers.idSHA1, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA1Digest();
        }
    });
    table.put(NISTObjectIdentifiers.id_sha224, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA224Digest();
        }
    });
    table.put(NISTObjectIdentifiers.id_sha256, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA256Digest();
        }
    });
    table.put(NISTObjectIdentifiers.id_sha384, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA384Digest();
        }
    });
    table.put(NISTObjectIdentifiers.id_sha512, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA512Digest();
        }
    });
    table.put(NISTObjectIdentifiers.id_sha3_224, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA3Digest(224);
        }
    });
    table.put(NISTObjectIdentifiers.id_sha3_256, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA3Digest(256);
        }
    });
    table.put(NISTObjectIdentifiers.id_sha3_384, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA3Digest(384);
        }
    });
    table.put(NISTObjectIdentifiers.id_sha3_512, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHA3Digest(512);
        }
    });
    table.put(NISTObjectIdentifiers.id_shake128, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHAKEDigest(128);
        }
    });
    table.put(NISTObjectIdentifiers.id_shake256, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SHAKEDigest(256);
        }
    });
    table.put(NISTObjectIdentifiers.id_shake128_len, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new AdjustedXof(new SHAKEDigest(128), ASN1Integer.getInstance(digestAlgorithmIdentifier.getParameters()).intValueExact());
        }
    });
    table.put(NISTObjectIdentifiers.id_shake256_len, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new AdjustedXof(new SHAKEDigest(256), ASN1Integer.getInstance(digestAlgorithmIdentifier.getParameters()).intValueExact());
        }
    });
    table.put(PKCSObjectIdentifiers.md5, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new MD5Digest();
        }
    });
    table.put(PKCSObjectIdentifiers.md4, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new MD4Digest();
        }
    });
    table.put(PKCSObjectIdentifiers.md2, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new MD2Digest();
        }
    });
    table.put(CryptoProObjectIdentifiers.gostR3411, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new GOST3411Digest();
        }
    });
    table.put(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new GOST3411_2012_256Digest();
        }
    });
    table.put(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new GOST3411_2012_512Digest();
        }
    });
    table.put(TeleTrusTObjectIdentifiers.ripemd128, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new RIPEMD128Digest();
        }
    });
    table.put(TeleTrusTObjectIdentifiers.ripemd160, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new RIPEMD160Digest();
        }
    });
    table.put(TeleTrusTObjectIdentifiers.ripemd256, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new RIPEMD256Digest();
        }
    });
    table.put(GMObjectIdentifiers.sm3, new BcDigestProvider() {

        public ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) {
            return new SM3Digest();
        }
    });
    return Collections.unmodifiableMap(table);
}
Also used : ExtendedDigest(com.github.zhenwei.core.crypto.ExtendedDigest) SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) RIPEMD128Digest(com.github.zhenwei.core.crypto.digests.RIPEMD128Digest) MD2Digest(com.github.zhenwei.core.crypto.digests.MD2Digest) SHA224Digest(com.github.zhenwei.core.crypto.digests.SHA224Digest) HashMap(java.util.HashMap) SHA1Digest(com.github.zhenwei.core.crypto.digests.SHA1Digest) GOST3411Digest(com.github.zhenwei.core.crypto.digests.GOST3411Digest) RIPEMD160Digest(com.github.zhenwei.core.crypto.digests.RIPEMD160Digest) RIPEMD256Digest(com.github.zhenwei.core.crypto.digests.RIPEMD256Digest) MD4Digest(com.github.zhenwei.core.crypto.digests.MD4Digest) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) GOST3411_2012_256Digest(com.github.zhenwei.core.crypto.digests.GOST3411_2012_256Digest) SHA3Digest(com.github.zhenwei.core.crypto.digests.SHA3Digest) MD5Digest(com.github.zhenwei.core.crypto.digests.MD5Digest) SM3Digest(com.github.zhenwei.core.crypto.digests.SM3Digest) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) GOST3411_2012_512Digest(com.github.zhenwei.core.crypto.digests.GOST3411_2012_512Digest) HashMap(java.util.HashMap) Map(java.util.Map) SHA384Digest(com.github.zhenwei.core.crypto.digests.SHA384Digest) SHAKEDigest(com.github.zhenwei.core.crypto.digests.SHAKEDigest)

Example 9 with SHA256Digest

use of com.github.zhenwei.core.crypto.digests.SHA256Digest in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        Integer paramStrength = Integers.valueOf(strength);
        if (params.containsKey(paramStrength)) {
            param = (DSAKeyGenerationParameters) params.get(paramStrength);
        } else {
            synchronized (lock) {
                // our key size.
                if (params.containsKey(paramStrength)) {
                    param = (DSAKeyGenerationParameters) params.get(paramStrength);
                } else {
                    DSAParametersGenerator pGen;
                    DSAParameterGenerationParameters dsaParams;
                    int certainty = PrimeCertaintyCalculator.getDefaultCertainty(strength);
                    // For legacy keysize that is less than 1024-bit, we just use the 186-2 style parameters
                    if (strength == 1024) {
                        pGen = new DSAParametersGenerator();
                        if (Properties.isOverrideSet("org.bouncycastle.dsa.FIPS186-2for1024bits")) {
                            pGen.init(strength, certainty, random);
                        } else {
                            dsaParams = new DSAParameterGenerationParameters(1024, 160, certainty, random);
                            pGen.init(dsaParams);
                        }
                    } else if (strength > 1024) {
                        dsaParams = new DSAParameterGenerationParameters(strength, 256, certainty, random);
                        pGen = new DSAParametersGenerator(new SHA256Digest());
                        pGen.init(dsaParams);
                    } else {
                        pGen = new DSAParametersGenerator();
                        pGen.init(strength, certainty, random);
                    }
                    param = new DSAKeyGenerationParameters(random, pGen.generateParameters());
                    params.put(paramStrength, param);
                }
            }
        }
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    DSAPublicKeyParameters pub = (DSAPublicKeyParameters) pair.getPublic();
    DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCDSAPublicKey(pub), new BCDSAPrivateKey(priv));
}
Also used : DSAParametersGenerator(com.github.zhenwei.core.crypto.generators.DSAParametersGenerator) DSAPublicKeyParameters(com.github.zhenwei.core.crypto.params.DSAPublicKeyParameters) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) DSAParameterGenerationParameters(com.github.zhenwei.core.crypto.params.DSAParameterGenerationParameters) DSAKeyGenerationParameters(com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters) DSAPrivateKeyParameters(com.github.zhenwei.core.crypto.params.DSAPrivateKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 10 with SHA256Digest

use of com.github.zhenwei.core.crypto.digests.SHA256Digest in project LinLong-Java by zhenwei1108.

the class XMSSMTKeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof XMSSMTParameterSpec)) {
        throw new InvalidAlgorithmParameterException("parameter object not a XMSSMTParameterSpec");
    }
    XMSSMTParameterSpec xmssParams = (XMSSMTParameterSpec) params;
    if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHA256)) {
        treeDigest = NISTObjectIdentifiers.id_sha256;
        param = new XMSSMTKeyGenerationParameters(new XMSSMTParameters(xmssParams.getHeight(), xmssParams.getLayers(), new SHA256Digest()), random);
    } else if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHA512)) {
        treeDigest = NISTObjectIdentifiers.id_sha512;
        param = new XMSSMTKeyGenerationParameters(new XMSSMTParameters(xmssParams.getHeight(), xmssParams.getLayers(), new SHA512Digest()), random);
    } else if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHAKE128)) {
        treeDigest = NISTObjectIdentifiers.id_shake128;
        param = new XMSSMTKeyGenerationParameters(new XMSSMTParameters(xmssParams.getHeight(), xmssParams.getLayers(), new SHAKEDigest(128)), random);
    } else if (xmssParams.getTreeDigest().equals(XMSSParameterSpec.SHAKE256)) {
        treeDigest = NISTObjectIdentifiers.id_shake256;
        param = new XMSSMTKeyGenerationParameters(new XMSSMTParameters(xmssParams.getHeight(), xmssParams.getLayers(), new SHAKEDigest(256)), random);
    }
    engine.init(param);
    initialised = true;
}
Also used : SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) XMSSMTKeyGenerationParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTKeyGenerationParameters) XMSSMTParameterSpec(com.github.zhenwei.provider.jcajce.spec.XMSSMTParameterSpec) XMSSMTParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTParameters) SHAKEDigest(com.github.zhenwei.core.crypto.digests.SHAKEDigest)

Aggregations

SHA256Digest (com.github.zhenwei.core.crypto.digests.SHA256Digest)13 SHA512Digest (com.github.zhenwei.core.crypto.digests.SHA512Digest)4 BigInteger (java.math.BigInteger)4 Digest (com.github.zhenwei.core.crypto.Digest)3 SHAKEDigest (com.github.zhenwei.core.crypto.digests.SHAKEDigest)3 KeyParameter (com.github.zhenwei.core.crypto.params.KeyParameter)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 ExtendedDigest (com.github.zhenwei.core.crypto.ExtendedDigest)2 SHA1Digest (com.github.zhenwei.core.crypto.digests.SHA1Digest)2 SHA224Digest (com.github.zhenwei.core.crypto.digests.SHA224Digest)2 SHA384Digest (com.github.zhenwei.core.crypto.digests.SHA384Digest)2 DSAParametersGenerator (com.github.zhenwei.core.crypto.generators.DSAParametersGenerator)2 AsymmetricKeyParameter (com.github.zhenwei.core.crypto.params.AsymmetricKeyParameter)2 CramerShoupParameters (com.github.zhenwei.core.crypto.params.CramerShoupParameters)2 DSAParameterGenerationParameters (com.github.zhenwei.core.crypto.params.DSAParameterGenerationParameters)2 IESWithCipherParameters (com.github.zhenwei.core.crypto.params.IESWithCipherParameters)2 ParametersWithIV (com.github.zhenwei.core.crypto.params.ParametersWithIV)2 HashMap (java.util.HashMap)2 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1