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);
}
}
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);
}
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));
}
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;
}
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));
}
Aggregations