use of com.github.zhenwei.core.crypto.digests.SHAKEDigest 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.SHAKEDigest in project LinLong-Java by zhenwei1108.
the class HashUtils method secureHashAlgorithmKECCAK128.
/**
*************************************************************************************************************************************************************
* Description: The Secure-Hash-Algorithm-3 Extendable-Output Function That Generally Supports 128 Bits of Security Strength, If the Output is Sufficiently Long
**************************************************************************************************************************************************************
*/
static void secureHashAlgorithmKECCAK128(byte[] output, int outputOffset, int outputLength, byte[] input, int inputOffset, int inputLength) {
SHAKEDigest dig = new SHAKEDigest(128);
dig.update(input, inputOffset, inputLength);
dig.doFinal(output, outputOffset, outputLength);
}
use of com.github.zhenwei.core.crypto.digests.SHAKEDigest in project LinLong-Java by zhenwei1108.
the class HashUtils method secureHashAlgorithmKECCAK256.
/**
*************************************************************************************************************************************************************
* Description: The Secure-Hash-Algorithm-3 Extendable-Output Function That Generally Supports 256 Bits of Security Strength, If the Output is Sufficiently Long
**************************************************************************************************************************************************************
*/
static void secureHashAlgorithmKECCAK256(byte[] output, int outputOffset, int outputLength, byte[] input, int inputOffset, int inputLength) {
SHAKEDigest dig = new SHAKEDigest(256);
dig.update(input, inputOffset, inputLength);
dig.doFinal(output, outputOffset, outputLength);
}
use of com.github.zhenwei.core.crypto.digests.SHAKEDigest in project LinLong-Java by zhenwei1108.
the class Poly method uniform.
static void uniform(short[] a, byte[] seed) {
SHAKEDigest xof = new SHAKEDigest(128);
xof.update(seed, 0, seed.length);
int pos = 0;
for (; ; ) {
byte[] output = new byte[256];
xof.doOutput(output, 0, output.length);
for (int i = 0; i < output.length; i += 2) {
int val = (output[i] & 0xFF) | ((output[i + 1] & 0xFF) << 8);
if (val < 5 * Params.Q) {
a[pos++] = (short) val;
if (pos == Params.N) {
return;
}
}
}
}
}
use of com.github.zhenwei.core.crypto.digests.SHAKEDigest 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);
}
Aggregations