org.bouncycastle.tls.crypto.impl.jcajce.JceTlsSecret Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bctls-fips Show documentation
Show all versions of bctls-fips Show documentation
The Bouncy Castle Java APIs for the TLS, including a JSSE provider. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.
package org.bouncycastle.tls.crypto.impl.jcajce;
import org.bouncycastle.crypto.KDFCalculator;
import org.bouncycastle.crypto.fips.FipsKDF;
import org.bouncycastle.tls.PRFAlgorithm;
import org.bouncycastle.tls.crypto.TlsSecret;
import org.bouncycastle.tls.crypto.impl.AbstractTlsCrypto;
import org.bouncycastle.tls.crypto.impl.AbstractTlsSecret;
/**
* JCE support class for handling TLS secrets and deriving key material and other secrets from them.
*/
public class JceTlsSecret
extends AbstractTlsSecret
{
private final JcaTlsCrypto crypto;
public JceTlsSecret(JcaTlsCrypto crypto, byte[] data)
{
super(data);
this.crypto = crypto;
}
public synchronized TlsSecret deriveUsingPRF(int prfAlgorithm, String label, byte[] seed, int length)
{
checkAlive();
KDFCalculator calculator;
if (prfAlgorithm == PRFAlgorithm.tls_prf_legacy)
{
calculator = new FipsKDF.TLSOperatorFactory().createKDFCalculator(
FipsKDF.TLS1_1.using(data, label, seed));
}
else if (prfAlgorithm == PRFAlgorithm.tls_prf_sha256)
{
calculator = new FipsKDF.TLSOperatorFactory().createKDFCalculator(
FipsKDF.TLS1_2.withPRF(FipsKDF.TLSPRF.SHA256_HMAC).using(data, label, seed));
}
else if (prfAlgorithm == PRFAlgorithm.tls_prf_sha384)
{
calculator = new FipsKDF.TLSOperatorFactory().createKDFCalculator(
FipsKDF.TLS1_2.withPRF(FipsKDF.TLSPRF.SHA384_HMAC).using(data, label, seed));
}
else
{
throw new IllegalStateException("unknown prf: " + prfAlgorithm);
}
byte[] result = new byte[length];
calculator.generateBytes(result);
return crypto.adoptLocalSecret(result);
}
protected TlsSecret adoptLocalSecret(byte[] data)
{
return crypto.adoptLocalSecret(data);
}
protected AbstractTlsCrypto getCrypto()
{
return crypto;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy