Search in sources :

Example 6 with SHAKEDigest

use of com.github.zhenwei.core.crypto.digests.SHAKEDigest 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)

Example 7 with SHAKEDigest

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

the class Fingerprint method calculateFingerprint.

/**
 * Return a byte array containing a calculated fingerprint for the passed in input data. This
 * calculation is compatible with the BC FIPS API.
 *
 * @param input     data to base the fingerprint on.
 * @param bitLength bit length of finger print to be produced.
 * @return a byte array containing a 20 byte fingerprint.
 */
public static byte[] calculateFingerprint(byte[] input, int bitLength) {
    if (bitLength % 8 != 0) {
        throw new IllegalArgumentException("bitLength must be a multiple of 8");
    }
    SHAKEDigest digest = new SHAKEDigest(256);
    digest.update(input, 0, input.length);
    byte[] rv = new byte[bitLength / 8];
    digest.doFinal(rv, 0, bitLength / 8);
    return rv;
}
Also used : SHAKEDigest(com.github.zhenwei.core.crypto.digests.SHAKEDigest)

Aggregations

SHAKEDigest (com.github.zhenwei.core.crypto.digests.SHAKEDigest)7 SHA256Digest (com.github.zhenwei.core.crypto.digests.SHA256Digest)3 SHA512Digest (com.github.zhenwei.core.crypto.digests.SHA512Digest)3 CSHAKEDigest (com.github.zhenwei.core.crypto.digests.CSHAKEDigest)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)1 ExtendedDigest (com.github.zhenwei.core.crypto.ExtendedDigest)1 GOST3411Digest (com.github.zhenwei.core.crypto.digests.GOST3411Digest)1 GOST3411_2012_256Digest (com.github.zhenwei.core.crypto.digests.GOST3411_2012_256Digest)1 GOST3411_2012_512Digest (com.github.zhenwei.core.crypto.digests.GOST3411_2012_512Digest)1 MD2Digest (com.github.zhenwei.core.crypto.digests.MD2Digest)1 MD4Digest (com.github.zhenwei.core.crypto.digests.MD4Digest)1 MD5Digest (com.github.zhenwei.core.crypto.digests.MD5Digest)1 RIPEMD128Digest (com.github.zhenwei.core.crypto.digests.RIPEMD128Digest)1 RIPEMD160Digest (com.github.zhenwei.core.crypto.digests.RIPEMD160Digest)1 RIPEMD256Digest (com.github.zhenwei.core.crypto.digests.RIPEMD256Digest)1 SHA1Digest (com.github.zhenwei.core.crypto.digests.SHA1Digest)1 SHA224Digest (com.github.zhenwei.core.crypto.digests.SHA224Digest)1 SHA384Digest (com.github.zhenwei.core.crypto.digests.SHA384Digest)1 SHA3Digest (com.github.zhenwei.core.crypto.digests.SHA3Digest)1