All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.crypto.hqc.HQCKEMExtractor Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.8 and up.

There is a newer version: 1.78.1
Show newest version
package org.bouncycastle.pqc.crypto.hqc;


import org.bouncycastle.crypto.EncapsulatedSecretExtractor;
import org.bouncycastle.util.Arrays;

public class HQCKEMExtractor
    implements EncapsulatedSecretExtractor
{
    private HQCEngine engine;

    private HQCKeyParameters key;

    public HQCKEMExtractor(HQCPrivateKeyParameters privParams)
    {
        this.key = privParams;
        initCipher(key.getParameters());
    }

    private void initCipher(HQCParameters param)
    {
        engine = param.getEngine();
    }

    public byte[] extractSecret(byte[] encapsulation)
    {
        byte[] session_key = new byte[engine.getSessionKeySize()];
        HQCPrivateKeyParameters secretKey = (HQCPrivateKeyParameters)key;
        byte[] sk = secretKey.getPrivateKey();

        engine.decaps(session_key, encapsulation, sk);

        return Arrays.copyOfRange(session_key, 0, key.getParameters().getK());
    }

    public int getEncapsulationLength()
    {
        return key.getParameters().getN_BYTES() + key.getParameters().getN1N2_BYTES() + 64;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy