Search in sources :

Example 1 with SHA512Digest

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

the class DRBG method createBaseRandom.

private static SecureRandom createBaseRandom(boolean isPredictionResistant) {
    if (Properties.getPropertyValue("org.bouncycastle.drbg.entropysource") != null) {
        EntropySourceProvider entropyProvider = createEntropySource();
        EntropySource initSource = entropyProvider.get(16 * 8);
        byte[] personalisationString = isPredictionResistant ? generateDefaultPersonalizationString(initSource.getEntropy()) : generateNonceIVPersonalizationString(initSource.getEntropy());
        return new SP800SecureRandomBuilder(entropyProvider).setPersonalizationString(personalisationString).buildHash(new SHA512Digest(), Arrays.concatenate(initSource.getEntropy(), initSource.getEntropy()), isPredictionResistant);
    } else {
        // needs to be done late, can't use static
        SecureRandom randomSource = new HybridSecureRandom();
        byte[] personalisationString = isPredictionResistant ? generateDefaultPersonalizationString(randomSource.generateSeed(16)) : generateNonceIVPersonalizationString(randomSource.generateSeed(16));
        return new SP800SecureRandomBuilder(randomSource, true).setPersonalizationString(personalisationString).buildHash(new SHA512Digest(), randomSource.generateSeed(32), isPredictionResistant);
    }
}
Also used : SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) SP800SecureRandom(com.github.zhenwei.core.crypto.prng.SP800SecureRandom) SecureRandom(java.security.SecureRandom) SP800SecureRandomBuilder(com.github.zhenwei.core.crypto.prng.SP800SecureRandomBuilder) EntropySource(com.github.zhenwei.core.crypto.prng.EntropySource) EntropySourceProvider(com.github.zhenwei.core.crypto.prng.EntropySourceProvider)

Example 2 with SHA512Digest

use of com.github.zhenwei.core.crypto.digests.SHA512Digest 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 3 with SHA512Digest

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

the class XMSSKeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        param = new XMSSKeyGenerationParameters(new XMSSParameters(10, new SHA512Digest()), random);
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    XMSSPublicKeyParameters pub = (XMSSPublicKeyParameters) pair.getPublic();
    XMSSPrivateKeyParameters priv = (XMSSPrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCXMSSPublicKey(treeDigest, pub), new BCXMSSPrivateKey(treeDigest, priv));
}
Also used : SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) XMSSParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSParameters) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) XMSSPrivateKeyParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSPrivateKeyParameters) XMSSKeyGenerationParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSKeyGenerationParameters) XMSSPublicKeyParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSPublicKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 4 with SHA512Digest

use of com.github.zhenwei.core.crypto.digests.SHA512Digest 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 5 with SHA512Digest

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

the class XMSSMTKeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        param = new XMSSMTKeyGenerationParameters(new XMSSMTParameters(10, 20, new SHA512Digest()), random);
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    XMSSMTPublicKeyParameters pub = (XMSSMTPublicKeyParameters) pair.getPublic();
    XMSSMTPrivateKeyParameters priv = (XMSSMTPrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCXMSSMTPublicKey(treeDigest, pub), new BCXMSSMTPrivateKey(treeDigest, priv));
}
Also used : SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) XMSSMTKeyGenerationParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTKeyGenerationParameters) XMSSMTPublicKeyParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTPublicKeyParameters) XMSSMTParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) XMSSMTPrivateKeyParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTPrivateKeyParameters)

Aggregations

SHA512Digest (com.github.zhenwei.core.crypto.digests.SHA512Digest)8 SHA256Digest (com.github.zhenwei.core.crypto.digests.SHA256Digest)4 SHAKEDigest (com.github.zhenwei.core.crypto.digests.SHAKEDigest)3 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)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 SHA3Digest (com.github.zhenwei.core.crypto.digests.SHA3Digest)2 XMSSKeyGenerationParameters (com.github.zhenwei.core.pqc.crypto.xmss.XMSSKeyGenerationParameters)2 XMSSMTKeyGenerationParameters (com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTKeyGenerationParameters)2 XMSSMTParameters (com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTParameters)2 XMSSParameters (com.github.zhenwei.core.pqc.crypto.xmss.XMSSParameters)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 KeyPair (java.security.KeyPair)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ScryptParams (com.github.zhenwei.core.asn1.misc.ScryptParams)1 PBKDF2Params (com.github.zhenwei.core.asn1.pkcs.PBKDF2Params)1