Top Description Methods
org.bouncycastle.tls.crypto

public Interface TlsCrypto

Known Direct Implementers
org.bouncycastle.tls.crypto.impl.AbstractTlsCrypto
Imports
java.io.IOException, java.math.BigInteger, java.security.SecureRandom, java.util.Vector, org.bouncycastle.tls.ClientCertificateType, .EncryptionAlgorithm, .MACAlgorithm, .NamedGroup, .ProtocolVersion, .SignatureAndHashAlgorithm

Service and object creation interface for the primitive types and services that are associated with cryptography in the API.

Method Summary

Modifier and TypeMethod and Description
public TlsSecret

Returns:

a TlsSecret based on the original secret.
adoptSecret
(TlsSecret
the secret to make a copy of.
secret
)

Adopt the passed in secret, creating a new copy of it.

public TlsCertificate

Returns:

a TlsCertificate.
createCertificate
(byte[]
DER/BER encoding of the certificate of interest.
encoding
)

Create a TlsCertificate from an ASN.1 binary encoding of an X.509 certificate.

public TlsCertificate

Returns:

a TlsCertificate.
createCertificate
(short
Certificate type as per IANA TLS Certificate Types registry
type
,
byte[]
DER/BER encoding of the certificate of interest.
encoding
)

Create a TlsCertificate from a ASN.1 binary encoding of a certificate.

public TlsCipher

Returns:

a TlsCipher implementing the encryption and MAC algorithms.
createCipher
(TlsCryptoParameters
context specific parameters.
cryptoParams
,
int
the encryption algorithm to be employed by the cipher.
encryptionAlgorithm
,
int
the MAC algorithm to be employed by the cipher.
macAlgorithm
)

Create a cipher for the specified encryption and MAC algorithms.

public TlsDHDomain

Returns:

a TlsDHDomain supporting the parameters in dhConfig.
createDHDomain
(TlsDHConfig
the config describing the DH parameters to use.
dhConfig
)

Create a domain object supporting the domain parameters described in dhConfig.

public TlsECDomain

Returns:

a TlsECDomain supporting the parameters in ecConfig.
createECDomain
(TlsECConfig
the config describing the EC parameters to use.
ecConfig
)

Create a domain object supporting the domain parameters described in ecConfig.

public TlsHash

Returns:

a TlsHash.
createHash
(int
the hash algorithm the hash needs to implement.
cryptoHashAlgorithm
)

Create a suitable hash for the hash algorithm identifier passed in.

See enumeration class CryptoHashAlgorithm for appropriate argument values.

public TlsHMAC

Returns:

a TlsHMAC.
createHMAC
(int
the MAC algorithm the HMAC needs to match.
macAlgorithm
)

Create a suitable HMAC for the MAC algorithm identifier passed in.

See enumeration class MACAlgorithm for appropriate argument values.

public TlsHMAC

Returns:

a TlsHMAC.
createHMACForHash
(int
the hash algorithm the HMAC should use.
cryptoHashAlgorithm
)

Create a suitable HMAC using the hash algorithm identifier passed in.

See enumeration class CryptoHashAlgorithm for appropriate argument values.

public TlsKemDomain

Returns:

a TlsKemDomain supporting the parameters in kemConfig.
createKemDomain
(TlsKemConfig
the config describing the KEM parameters to use.
kemConfig
)

Create a domain object supporting the domain parameters described in kemConfig.

public TlsNonceGenerator
createNonceGenerator(byte[]
context-specific seed material
additionalSeedMaterial
)

Create a nonce generator.

public TlsSecret

Returns:

a TlsSecret based on the provided data.
createSecret
(byte[]
the data to base the TlsSecret on.
data
)

Create a TlsSecret object based on provided data.

public TlsSRP6Client

Returns:

an initialised SRP6 client object.
createSRP6Client
(TlsSRPConfig
client config.
srpConfig
)

Create an SRP-6 client.

public TlsSRP6Server

Returns:

an initialised SRP6 server object.
createSRP6Server
(TlsSRPConfig
server config.
srpConfig
,
BigInteger
the SRP6 verifier value.
srpVerifier
)

Create an SRP-6 server.

public TlsSRP6VerifierGenerator

Returns:

an initialized SRP6 verifier generator.
createSRP6VerifierGenerator
(TlsSRPConfig
generator config.
srpConfig
)

Create an SRP-6 verifier generator.

public TlsSecret

Returns:

a TlsSecret containing the PreMasterSecret.
generateRSAPreMasterSecret
(ProtocolVersion
the client version to place in the first 2 bytes
clientVersion
)

Create a TlsSecret object containing a randomly-generated RSA PreMasterSecret

public SecureRandom

Returns:

a SecureRandom suitable for key generation.
getSecureRandom
()

Return the primary (safest) SecureRandom for this crypto.

public boolean

Returns:

true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.
hasAnyStreamVerifiers
(Vector<E> signatureAndHashAlgorithms)

Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.

public boolean

Returns:

true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.
hasAnyStreamVerifiersLegacy
(short[]
An array of ClientCertificateType values.
clientCertificateTypes
)

Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.

public boolean

Returns:

true if cryptoHashAlgorithm is supported, false otherwise.
hasCryptoHashAlgorithm
(int
the algorithm of interest.
cryptoHashAlgorithm
)

Return true if this TlsCrypto can support the passed in hash algorithm.

public boolean

Returns:

true if cryptoSignatureAlgorithm is supported, false otherwise.
hasCryptoSignatureAlgorithm
(int
the algorithm of interest.
cryptoSignatureAlgorithm
)

Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).

public boolean

Returns:

true if this instance can support DH key agreement, false otherwise.
hasDHAgreement
()

Return true if this TlsCrypto can support DH key agreement.

public boolean

Returns:

true if this instance can support ECDH key agreement, false otherwise.
hasECDHAgreement
()

Return true if this TlsCrypto can support ECDH key agreement.

public boolean

Returns:

true if encryptionAlgorithm is supported, false otherwise.
hasEncryptionAlgorithm
(int
the algorithm of interest.
encryptionAlgorithm
)

Return true if this TlsCrypto can support the passed in block/stream encryption algorithm.

public boolean

Returns:

true if HKDF is supported with cryptoHashAlgorithm, false otherwise.
hasHKDFAlgorithm
(int
the algorithm of interest.
cryptoHashAlgorithm
)

Return true if this TlsCrypto can support HKDF with the passed in hash algorithm.

public boolean

Returns:

true if this instance can support KEM key agreement, false otherwise.
hasKemAgreement
()

Return true if this TlsCrypto can support KEM key agreement.

public boolean

Returns:

true if macAlgorithm is supported, false otherwise.
hasMacAlgorithm
(int
the algorithm of interest.
macAlgorithm
)

Return true if this TlsCrypto can support the passed in MAC algorithm.

public boolean

Returns:

true if this instance supports the passed in named group value.
hasNamedGroup
(int namedGroup)

Return true if this TlsCrypto supports the passed in named group value.

public boolean

Returns:

true if this instance can support RSA encryption/decryption, false otherwise.
hasRSAEncryption
()

Return true if this TlsCrypto can support RSA encryption/decryption.

public boolean

Returns:

true if signatureAlgorithm is supported, false otherwise.
hasSignatureAlgorithm
(short
the algorithm of interest.
signatureAlgorithm
)

Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).

public boolean

Returns:

true if sigAndHashAlgorithm is supported, false otherwise.
hasSignatureAndHashAlgorithm
(SignatureAndHashAlgorithm
the algorithm of interest.
sigAndHashAlgorithm
)

Return true if this TlsCrypto can support the passed in signature algorithm.

public boolean

Returns:

true if signatureScheme is supported, false otherwise.
hasSignatureScheme
(int
the scheme of interest.
signatureScheme
)

Return true if this TlsCrypto can support the passed in signature scheme.

public boolean

Returns:

true if this instance can support SRP authentication, false otherwise.
hasSRPAuthentication
()

Return true if this TlsCrypto can support SRP authentication.

public TlsSecret
hkdfInit(int
the hash algorithm to instantiate HMAC with. See CryptoHashAlgorithm for values.
cryptoHashAlgorithm
)

Setup an initial "secret" for a chain of HKDF calls (RFC 5869), containing a string of HashLen zeroes.

Method Detail

adoptSecretback to summary
public TlsSecret adoptSecret(TlsSecret secret)

Adopt the passed in secret, creating a new copy of it.

Parameters
secret:TlsSecret

the secret to make a copy of.

Returns:TlsSecret

a TlsSecret based on the original secret.

createCertificateback to summary
public TlsCertificate createCertificate(byte[] encoding) throws IOException

Create a TlsCertificate from an ASN.1 binary encoding of an X.509 certificate.

Parameters
encoding:byte[]

DER/BER encoding of the certificate of interest.

Returns:TlsCertificate

a TlsCertificate.

Exceptions
IOException:
if there is an issue on decoding or constructing the certificate.
createCertificateback to summary
public TlsCertificate createCertificate(short type, byte[] encoding) throws IOException

Create a TlsCertificate from a ASN.1 binary encoding of a certificate.

Parameters
type:short

Certificate type as per IANA TLS Certificate Types registry

encoding:byte[]

DER/BER encoding of the certificate of interest.

Returns:TlsCertificate

a TlsCertificate.

Exceptions
IOException:
if there is an issue on decoding or constructing the certificate.
createCipherback to summary
public TlsCipher createCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm) throws IOException

Create a cipher for the specified encryption and MAC algorithms.

See enumeration classes EncryptionAlgorithm, MACAlgorithm for appropriate argument values.

Parameters
cryptoParams:TlsCryptoParameters

context specific parameters.

encryptionAlgorithm:int

the encryption algorithm to be employed by the cipher.

macAlgorithm:int

the MAC algorithm to be employed by the cipher.

Returns:TlsCipher

a TlsCipher implementing the encryption and MAC algorithms.

createDHDomainback to summary
public TlsDHDomain createDHDomain(TlsDHConfig dhConfig)

Create a domain object supporting the domain parameters described in dhConfig.

Parameters
dhConfig:TlsDHConfig

the config describing the DH parameters to use.

Returns:TlsDHDomain

a TlsDHDomain supporting the parameters in dhConfig.

createECDomainback to summary
public TlsECDomain createECDomain(TlsECConfig ecConfig)

Create a domain object supporting the domain parameters described in ecConfig.

Parameters
ecConfig:TlsECConfig

the config describing the EC parameters to use.

Returns:TlsECDomain

a TlsECDomain supporting the parameters in ecConfig.

createHashback to summary
public TlsHash createHash(int cryptoHashAlgorithm)

Create a suitable hash for the hash algorithm identifier passed in.

See enumeration class CryptoHashAlgorithm for appropriate argument values.

Parameters
cryptoHashAlgorithm:int

the hash algorithm the hash needs to implement.

Returns:TlsHash

a TlsHash.

createHMACback to summary
public TlsHMAC createHMAC(int macAlgorithm)

Create a suitable HMAC for the MAC algorithm identifier passed in.

See enumeration class MACAlgorithm for appropriate argument values.

Parameters
macAlgorithm:int

the MAC algorithm the HMAC needs to match.

Returns:TlsHMAC

a TlsHMAC.

createHMACForHashback to summary
public TlsHMAC createHMACForHash(int cryptoHashAlgorithm)

Create a suitable HMAC using the hash algorithm identifier passed in.

See enumeration class CryptoHashAlgorithm for appropriate argument values.

Parameters
cryptoHashAlgorithm:int

the hash algorithm the HMAC should use.

Returns:TlsHMAC

a TlsHMAC.

createKemDomainback to summary
public TlsKemDomain createKemDomain(TlsKemConfig kemConfig)

Create a domain object supporting the domain parameters described in kemConfig.

Parameters
kemConfig:TlsKemConfig

the config describing the KEM parameters to use.

Returns:TlsKemDomain

a TlsKemDomain supporting the parameters in kemConfig.

createNonceGeneratorback to summary
public TlsNonceGenerator createNonceGenerator(byte[] additionalSeedMaterial)

Create a nonce generator. Each call should construct a new generator, and the generator should be returned from this call only after automatically seeding from this TlsCrypto's entropy source, and from the provided additional seed material. The output of each returned generator must be completely independent of the others.

Parameters
additionalSeedMaterial:byte[]

context-specific seed material

Returns:TlsNonceGenerator

a TlsNonceGenerator

createSecretback to summary
public TlsSecret createSecret(byte[] data)

Create a TlsSecret object based on provided data.

Parameters
data:byte[]

the data to base the TlsSecret on.

Returns:TlsSecret

a TlsSecret based on the provided data.

createSRP6Clientback to summary
public TlsSRP6Client createSRP6Client(TlsSRPConfig srpConfig)

Create an SRP-6 client.

Parameters
srpConfig:TlsSRPConfig

client config.

Returns:TlsSRP6Client

an initialised SRP6 client object.

createSRP6Serverback to summary
public TlsSRP6Server createSRP6Server(TlsSRPConfig srpConfig, BigInteger srpVerifier)

Create an SRP-6 server.

Parameters
srpConfig:TlsSRPConfig

server config.

srpVerifier:BigInteger

the SRP6 verifier value.

Returns:TlsSRP6Server

an initialised SRP6 server object.

createSRP6VerifierGeneratorback to summary
public TlsSRP6VerifierGenerator createSRP6VerifierGenerator(TlsSRPConfig srpConfig)

Create an SRP-6 verifier generator.

Parameters
srpConfig:TlsSRPConfig

generator config.

Returns:TlsSRP6VerifierGenerator

an initialized SRP6 verifier generator.

generateRSAPreMasterSecretback to summary
public TlsSecret generateRSAPreMasterSecret(ProtocolVersion clientVersion)

Create a TlsSecret object containing a randomly-generated RSA PreMasterSecret

Parameters
clientVersion:ProtocolVersion

the client version to place in the first 2 bytes

Returns:TlsSecret

a TlsSecret containing the PreMasterSecret.

getSecureRandomback to summary
public SecureRandom getSecureRandom()

Return the primary (safest) SecureRandom for this crypto.

Returns:SecureRandom

a SecureRandom suitable for key generation.

hasAnyStreamVerifiersback to summary
public boolean hasAnyStreamVerifiers(Vector<E> signatureAndHashAlgorithms)

Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms. This method is only relevant to handshakes negotiating (D)TLS 1.2.

Parameters
signatureAndHashAlgorithms:Vector<E>

A Vector of SignatureAndHashAlgorithm values.

Returns:boolean

true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.

hasAnyStreamVerifiersLegacyback to summary
public boolean hasAnyStreamVerifiersLegacy(short[] clientCertificateTypes)

Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms. This method is only relevant to handshakes negotiating (D)TLS versions older than 1.2.

Parameters
clientCertificateTypes:short[]

An array of ClientCertificateType values.

Returns:boolean

true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.

hasCryptoHashAlgorithmback to summary
public boolean hasCryptoHashAlgorithm(int cryptoHashAlgorithm)

Return true if this TlsCrypto can support the passed in hash algorithm.

Parameters
cryptoHashAlgorithm:int

the algorithm of interest.

Returns:boolean

true if cryptoHashAlgorithm is supported, false otherwise.

hasCryptoSignatureAlgorithmback to summary
public boolean hasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm)

Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).

Parameters
cryptoSignatureAlgorithm:int

the algorithm of interest.

Returns:boolean

true if cryptoSignatureAlgorithm is supported, false otherwise.

hasDHAgreementback to summary
public boolean hasDHAgreement()

Return true if this TlsCrypto can support DH key agreement.

Returns:boolean

true if this instance can support DH key agreement, false otherwise.

hasECDHAgreementback to summary
public boolean hasECDHAgreement()

Return true if this TlsCrypto can support ECDH key agreement.

Returns:boolean

true if this instance can support ECDH key agreement, false otherwise.

hasEncryptionAlgorithmback to summary
public boolean hasEncryptionAlgorithm(int encryptionAlgorithm)

Return true if this TlsCrypto can support the passed in block/stream encryption algorithm.

Parameters
encryptionAlgorithm:int

the algorithm of interest.

Returns:boolean

true if encryptionAlgorithm is supported, false otherwise.

hasHKDFAlgorithmback to summary
public boolean hasHKDFAlgorithm(int cryptoHashAlgorithm)

Return true if this TlsCrypto can support HKDF with the passed in hash algorithm.

Parameters
cryptoHashAlgorithm:int

the algorithm of interest.

Returns:boolean

true if HKDF is supported with cryptoHashAlgorithm, false otherwise.

hasKemAgreementback to summary
public boolean hasKemAgreement()

Return true if this TlsCrypto can support KEM key agreement.

Returns:boolean

true if this instance can support KEM key agreement, false otherwise.

hasMacAlgorithmback to summary
public boolean hasMacAlgorithm(int macAlgorithm)

Return true if this TlsCrypto can support the passed in MAC algorithm.

Parameters
macAlgorithm:int

the algorithm of interest.

Returns:boolean

true if macAlgorithm is supported, false otherwise.

hasNamedGroupback to summary
public boolean hasNamedGroup(int namedGroup)

Return true if this TlsCrypto supports the passed in named group value.

Returns:boolean

true if this instance supports the passed in named group value.

hasRSAEncryptionback to summary
public boolean hasRSAEncryption()

Return true if this TlsCrypto can support RSA encryption/decryption.

Returns:boolean

true if this instance can support RSA encryption/decryption, false otherwise.

hasSignatureAlgorithmback to summary
public boolean hasSignatureAlgorithm(short signatureAlgorithm)

Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).

Parameters
signatureAlgorithm:short

the algorithm of interest.

Returns:boolean

true if signatureAlgorithm is supported, false otherwise.

hasSignatureAndHashAlgorithmback to summary
public boolean hasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm)

Return true if this TlsCrypto can support the passed in signature algorithm.

Parameters
sigAndHashAlgorithm:SignatureAndHashAlgorithm

the algorithm of interest.

Returns:boolean

true if sigAndHashAlgorithm is supported, false otherwise.

hasSignatureSchemeback to summary
public boolean hasSignatureScheme(int signatureScheme)

Return true if this TlsCrypto can support the passed in signature scheme.

Parameters
signatureScheme:int

the scheme of interest.

Returns:boolean

true if signatureScheme is supported, false otherwise.

hasSRPAuthenticationback to summary
public boolean hasSRPAuthentication()

Return true if this TlsCrypto can support SRP authentication.

Returns:boolean

true if this instance can support SRP authentication, false otherwise.

hkdfInitback to summary
public TlsSecret hkdfInit(int cryptoHashAlgorithm)

Setup an initial "secret" for a chain of HKDF calls (RFC 5869), containing a string of HashLen zeroes.

Parameters
cryptoHashAlgorithm:int

the hash algorithm to instantiate HMAC with. See CryptoHashAlgorithm for values.