Class BcTlsCrypto
java.lang.Object
org.bouncycastle.tls.crypto.impl.AbstractTlsCrypto
org.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto
- All Implemented Interfaces:
TlsCrypto
Class for providing cryptographic services for TLS based on implementations in the BC light-weight API.
This class provides default implementations for everything. If you need to customise it, extend the class and override the appropriate methods.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.bouncycastle.crypto.Digest
cloneDigest
(int cryptoHashAlgorithm, org.bouncycastle.crypto.Digest digest) protected org.bouncycastle.crypto.modes.AEADBlockCipher
protected org.bouncycastle.crypto.modes.AEADBlockCipher
protected org.bouncycastle.crypto.modes.AEADBlockCipher
protected org.bouncycastle.crypto.modes.AEADBlockCipher
protected org.bouncycastle.crypto.modes.AEADBlockCipher
protected org.bouncycastle.crypto.modes.AEADBlockCipher
protected org.bouncycastle.crypto.BlockCipher
protected org.bouncycastle.crypto.BlockCipher
protected org.bouncycastle.crypto.BlockCipher
createBlockCipher
(int encryptionAlgorithm) protected org.bouncycastle.crypto.BlockCipher
protected org.bouncycastle.crypto.BlockCipher
createCBCBlockCipher
(int encryptionAlgorithm) protected org.bouncycastle.crypto.BlockCipher
createCBCBlockCipher
(org.bouncycastle.crypto.BlockCipher blockCipher) protected org.bouncycastle.crypto.modes.AEADBlockCipher
createCCMMode
(org.bouncycastle.crypto.BlockCipher engine) createCertificate
(byte[] encoding) Create a TlsCertificate from an ASN.1 binary encoding of an X.509 certificate.createCertificate
(short type, byte[] encoding) Create a TlsCertificate from a ASN.1 binary encoding of a certificate.protected TlsCipher
createChaCha20Poly1305
(TlsCryptoParameters cryptoParams) createCipher
(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm) Create a cipher for the specified encryption and MAC algorithms.protected TlsAEADCipher
createCipher_AES_CCM
(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) protected TlsAEADCipher
createCipher_AES_GCM
(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) protected TlsAEADCipher
createCipher_ARIA_GCM
(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) protected TlsAEADCipher
createCipher_Camellia_GCM
(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) protected TlsCipher
createCipher_CBC
(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int cipherKeySize, int macAlgorithm) protected TlsAEADCipher
createCipher_SM4_CCM
(TlsCryptoParameters cryptoParams) protected TlsAEADCipher
createCipher_SM4_GCM
(TlsCryptoParameters cryptoParams) protected org.bouncycastle.crypto.BlockCipher
createDHDomain
(TlsDHConfig dhConfig) Create a domain object supporting the domain parameters described in dhConfig.org.bouncycastle.crypto.Digest
createDigest
(int cryptoHashAlgorithm) createECDomain
(TlsECConfig ecConfig) Create a domain object supporting the domain parameters described in ecConfig.protected org.bouncycastle.crypto.modes.AEADBlockCipher
createGCMMode
(org.bouncycastle.crypto.BlockCipher engine) createHash
(int cryptoHashAlgorithm) Create a suitable hash for the hash algorithm identifier passed in.createHMAC
(int macAlgorithm) Create a suitable HMAC for the MAC algorithm identifier passed in.protected TlsHMAC
createHMAC_SSL
(int macAlgorithm) createHMACForHash
(int cryptoHashAlgorithm) Create a suitable HMAC using the hash algorithm identifier passed in.createKemDomain
(TlsKemConfig kemConfig) Create a domain object supporting the domain parameters described in kemConfig.protected TlsHMAC
createMAC
(TlsCryptoParameters cryptoParams, int macAlgorithm) createNonceGenerator
(byte[] additionalSeedMaterial) Create a nonce generator.protected TlsNullCipher
createNullCipher
(TlsCryptoParameters cryptoParams, int macAlgorithm) createSecret
(byte[] data) Create a TlsSecret object based on provided data.protected org.bouncycastle.crypto.BlockCipher
protected org.bouncycastle.crypto.BlockCipher
createSRP6Client
(TlsSRPConfig srpConfig) Create an SRP-6 client.createSRP6Server
(TlsSRPConfig srpConfig, BigInteger srpVerifier) Create an SRP-6 server.createSRP6VerifierGenerator
(TlsSRPConfig srpConfig) Create an SRP-6 verifier generator.Create a TlsSecret object containing a randomly-generated RSA PreMasterSecretReturn the primary (safest) SecureRandom for this crypto.boolean
hasAnyStreamVerifiers
(Vector signatureAndHashAlgorithms) Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.boolean
hasAnyStreamVerifiersLegacy
(short[] clientCertificateTypes) Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.boolean
hasCryptoHashAlgorithm
(int cryptoHashAlgorithm) Return true if this TlsCrypto can support the passed in hash algorithm.boolean
hasCryptoSignatureAlgorithm
(int cryptoSignatureAlgorithm) Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).boolean
Return true if this TlsCrypto can support DH key agreement.boolean
Return true if this TlsCrypto can support ECDH key agreement.boolean
hasEncryptionAlgorithm
(int encryptionAlgorithm) Return true if this TlsCrypto can support the passed in block/stream encryption algorithm.boolean
hasHKDFAlgorithm
(int cryptoHashAlgorithm) Return true if this TlsCrypto can support HKDF with the passed in hash algorithm.boolean
Return true if this TlsCrypto can support KEM key agreement.boolean
hasMacAlgorithm
(int macAlgorithm) Return true if this TlsCrypto can support the passed in MAC algorithm.boolean
hasNamedGroup
(int namedGroup) Return true if this TlsCrypto supports the passed innamed group
value.boolean
Return true if this TlsCrypto can support RSA encryption/decryption.boolean
hasSignatureAlgorithm
(short signatureAlgorithm) Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).boolean
hasSignatureAndHashAlgorithm
(SignatureAndHashAlgorithm sigAndHashAlgorithm) Return true if this TlsCrypto can support the passed in signature algorithm.boolean
hasSignatureScheme
(int signatureScheme) Return true if this TlsCrypto can support the passed in signature scheme.boolean
Return true if this TlsCrypto can support SRP authentication.hkdfInit
(int cryptoHashAlgorithm) Setup an initial "secret" for a chain of HKDF calls (RFC 5869), containing a string of HashLen zeroes.Methods inherited from class org.bouncycastle.tls.crypto.impl.AbstractTlsCrypto
adoptSecret
-
Constructor Details
-
BcTlsCrypto
public BcTlsCrypto() -
BcTlsCrypto
-
-
Method Details
-
getSecureRandom
Description copied from interface:TlsCrypto
Return the primary (safest) SecureRandom for this crypto.- Returns:
- a SecureRandom suitable for key generation.
-
createCertificate
Description copied from interface:TlsCrypto
Create a TlsCertificate from an ASN.1 binary encoding of an X.509 certificate.- Parameters:
encoding
- DER/BER encoding of the certificate of interest.- Returns:
- a TlsCertificate.
- Throws:
IOException
- if there is an issue on decoding or constructing the certificate.
-
createCertificate
Description copied from interface:TlsCrypto
Create a TlsCertificate from a ASN.1 binary encoding of a certificate.- Parameters:
type
- Certificate type as per IANA TLS Certificate Types registryencoding
- DER/BER encoding of the certificate of interest.- Returns:
- a TlsCertificate.
- Throws:
IOException
- if there is an issue on decoding or constructing the certificate.
-
createCipher
public TlsCipher createCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm) throws IOException Description copied from interface:TlsCrypto
Create a cipher for the specified encryption and MAC algorithms.See enumeration classes
EncryptionAlgorithm
,MACAlgorithm
for appropriate argument values.- Parameters:
cryptoParams
- context specific parameters.encryptionAlgorithm
- the encryption algorithm to be employed by the cipher.macAlgorithm
- the MAC algorithm to be employed by the cipher.- Returns:
- a
TlsCipher
implementing the encryption and MAC algorithms. - Throws:
IOException
-
createDHDomain
Description copied from interface:TlsCrypto
Create a domain object supporting the domain parameters described in dhConfig.- Parameters:
dhConfig
- the config describing the DH parameters to use.- Returns:
- a TlsDHDomain supporting the parameters in dhConfig.
-
createECDomain
Description copied from interface:TlsCrypto
Create a domain object supporting the domain parameters described in ecConfig.- Parameters:
ecConfig
- the config describing the EC parameters to use.- Returns:
- a TlsECDomain supporting the parameters in ecConfig.
-
createKemDomain
Description copied from interface:TlsCrypto
Create a domain object supporting the domain parameters described in kemConfig.- Parameters:
kemConfig
- the config describing the KEM parameters to use.- Returns:
- a TlsKemDomain supporting the parameters in kemConfig.
-
createNonceGenerator
Description copied from interface:TlsCrypto
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 thisTlsCrypto
'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
- context-specific seed material- Returns:
- a
TlsNonceGenerator
-
hasAnyStreamVerifiers
Description copied from interface:TlsCrypto
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
- AVector
ofSignatureAndHashAlgorithm
values.- Returns:
- true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.
-
hasAnyStreamVerifiersLegacy
public boolean hasAnyStreamVerifiersLegacy(short[] clientCertificateTypes) Description copied from interface:TlsCrypto
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
- An array ofClientCertificateType
values.- Returns:
- true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.
-
hasCryptoHashAlgorithm
public boolean hasCryptoHashAlgorithm(int cryptoHashAlgorithm) Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support the passed in hash algorithm.- Parameters:
cryptoHashAlgorithm
- the algorithm of interest.- Returns:
- true if cryptoHashAlgorithm is supported, false otherwise.
-
hasCryptoSignatureAlgorithm
public boolean hasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm) Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).- Parameters:
cryptoSignatureAlgorithm
- the algorithm of interest.- Returns:
- true if cryptoSignatureAlgorithm is supported, false otherwise.
-
hasDHAgreement
public boolean hasDHAgreement()Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support DH key agreement.- Returns:
- true if this instance can support DH key agreement, false otherwise.
-
hasECDHAgreement
public boolean hasECDHAgreement()Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support ECDH key agreement.- Returns:
- true if this instance can support ECDH key agreement, false otherwise.
-
hasKemAgreement
public boolean hasKemAgreement()Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support KEM key agreement.- Returns:
- true if this instance can support KEM key agreement, false otherwise.
-
hasEncryptionAlgorithm
public boolean hasEncryptionAlgorithm(int encryptionAlgorithm) Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support the passed in block/stream encryption algorithm.- Parameters:
encryptionAlgorithm
- the algorithm of interest.- Returns:
- true if encryptionAlgorithm is supported, false otherwise.
-
hasHKDFAlgorithm
public boolean hasHKDFAlgorithm(int cryptoHashAlgorithm) Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support HKDF with the passed in hash algorithm.- Parameters:
cryptoHashAlgorithm
- the algorithm of interest.- Returns:
- true if HKDF is supported with cryptoHashAlgorithm, false otherwise.
-
hasMacAlgorithm
public boolean hasMacAlgorithm(int macAlgorithm) Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support the passed in MAC algorithm.- Parameters:
macAlgorithm
- the algorithm of interest.- Returns:
- true if macAlgorithm is supported, false otherwise.
-
hasNamedGroup
public boolean hasNamedGroup(int namedGroup) Description copied from interface:TlsCrypto
Return true if this TlsCrypto supports the passed innamed group
value.- Returns:
- true if this instance supports the passed in
named group
value.
-
hasRSAEncryption
public boolean hasRSAEncryption()Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support RSA encryption/decryption.- Returns:
- true if this instance can support RSA encryption/decryption, false otherwise.
-
hasSignatureAlgorithm
public boolean hasSignatureAlgorithm(short signatureAlgorithm) Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).- Parameters:
signatureAlgorithm
- the algorithm of interest.- Returns:
- true if signatureAlgorithm is supported, false otherwise.
-
hasSignatureAndHashAlgorithm
Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support the passed in signature algorithm.- Parameters:
sigAndHashAlgorithm
- the algorithm of interest.- Returns:
- true if sigAndHashAlgorithm is supported, false otherwise.
-
hasSignatureScheme
public boolean hasSignatureScheme(int signatureScheme) Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support the passed in signature scheme.- Parameters:
signatureScheme
- the scheme of interest.- Returns:
- true if signatureScheme is supported, false otherwise.
-
hasSRPAuthentication
public boolean hasSRPAuthentication()Description copied from interface:TlsCrypto
Return true if this TlsCrypto can support SRP authentication.- Returns:
- true if this instance can support SRP authentication, false otherwise.
-
createSecret
Description copied from interface:TlsCrypto
Create a TlsSecret object based on provided data.- Parameters:
data
- the data to base the TlsSecret on.- Returns:
- a TlsSecret based on the provided data.
-
generateRSAPreMasterSecret
Description copied from interface:TlsCrypto
Create a TlsSecret object containing a randomly-generated RSA PreMasterSecret- Parameters:
version
- the client version to place in the first 2 bytes- Returns:
- a TlsSecret containing the PreMasterSecret.
-
cloneDigest
public org.bouncycastle.crypto.Digest cloneDigest(int cryptoHashAlgorithm, org.bouncycastle.crypto.Digest digest) -
createDigest
public org.bouncycastle.crypto.Digest createDigest(int cryptoHashAlgorithm) -
createHash
Description copied from interface:TlsCrypto
Create a suitable hash for the hash algorithm identifier passed in.See enumeration class
CryptoHashAlgorithm
for appropriate argument values.- Parameters:
cryptoHashAlgorithm
- the hash algorithm the hash needs to implement.- Returns:
- a
TlsHash
.
-
createBlockCipher
protected org.bouncycastle.crypto.BlockCipher createBlockCipher(int encryptionAlgorithm) throws IOException - Throws:
IOException
-
createCBCBlockCipher
protected org.bouncycastle.crypto.BlockCipher createCBCBlockCipher(org.bouncycastle.crypto.BlockCipher blockCipher) -
createCBCBlockCipher
protected org.bouncycastle.crypto.BlockCipher createCBCBlockCipher(int encryptionAlgorithm) throws IOException - Throws:
IOException
-
createChaCha20Poly1305
- Throws:
IOException
-
createCipher_AES_CCM
protected TlsAEADCipher createCipher_AES_CCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws IOException - Throws:
IOException
-
createCipher_AES_GCM
protected TlsAEADCipher createCipher_AES_GCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws IOException - Throws:
IOException
-
createCipher_ARIA_GCM
protected TlsAEADCipher createCipher_ARIA_GCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws IOException - Throws:
IOException
-
createCipher_Camellia_GCM
protected TlsAEADCipher createCipher_Camellia_GCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws IOException - Throws:
IOException
-
createCipher_CBC
protected TlsCipher createCipher_CBC(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int cipherKeySize, int macAlgorithm) throws IOException - Throws:
IOException
-
createCipher_SM4_CCM
- Throws:
IOException
-
createCipher_SM4_GCM
- Throws:
IOException
-
createNullCipher
protected TlsNullCipher createNullCipher(TlsCryptoParameters cryptoParams, int macAlgorithm) throws IOException - Throws:
IOException
-
createAESEngine
protected org.bouncycastle.crypto.BlockCipher createAESEngine() -
createARIAEngine
protected org.bouncycastle.crypto.BlockCipher createARIAEngine() -
createCamelliaEngine
protected org.bouncycastle.crypto.BlockCipher createCamelliaEngine() -
createDESedeEngine
protected org.bouncycastle.crypto.BlockCipher createDESedeEngine() -
createSEEDEngine
protected org.bouncycastle.crypto.BlockCipher createSEEDEngine() -
createSM4Engine
protected org.bouncycastle.crypto.BlockCipher createSM4Engine() -
createCCMMode
protected org.bouncycastle.crypto.modes.AEADBlockCipher createCCMMode(org.bouncycastle.crypto.BlockCipher engine) -
createGCMMode
protected org.bouncycastle.crypto.modes.AEADBlockCipher createGCMMode(org.bouncycastle.crypto.BlockCipher engine) -
createAEADBlockCipher_AES_CCM
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_AES_CCM() -
createAEADBlockCipher_AES_GCM
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_AES_GCM() -
createAEADBlockCipher_ARIA_GCM
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_ARIA_GCM() -
createAEADBlockCipher_Camellia_GCM
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_Camellia_GCM() -
createAEADBlockCipher_SM4_CCM
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_SM4_CCM() -
createAEADBlockCipher_SM4_GCM
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_SM4_GCM() -
createHMAC
Description copied from interface:TlsCrypto
Create a suitable HMAC for the MAC algorithm identifier passed in.See enumeration class
MACAlgorithm
for appropriate argument values.- Parameters:
macAlgorithm
- the MAC algorithm the HMAC needs to match.- Returns:
- a
TlsHMAC
.
-
createHMACForHash
Description copied from interface:TlsCrypto
Create a suitable HMAC using the hash algorithm identifier passed in.See enumeration class
CryptoHashAlgorithm
for appropriate argument values.- Parameters:
cryptoHashAlgorithm
- the hash algorithm the HMAC should use.- Returns:
- a
TlsHMAC
.
-
createHMAC_SSL
- Throws:
IOException
-
createMAC
- Throws:
IOException
-
createSRP6Client
Description copied from interface:TlsCrypto
Create an SRP-6 client.- Parameters:
srpConfig
- client config.- Returns:
- an initialised SRP6 client object.
-
createSRP6Server
Description copied from interface:TlsCrypto
Create an SRP-6 server.- Parameters:
srpConfig
- server config.srpVerifier
- the SRP6 verifier value.- Returns:
- an initialised SRP6 server object.
-
createSRP6VerifierGenerator
Description copied from interface:TlsCrypto
Create an SRP-6 verifier generator.- Parameters:
srpConfig
- generator config.- Returns:
- an initialized SRP6 verifier generator.
-
hkdfInit
Description copied from interface:TlsCrypto
Setup an initial "secret" for a chain of HKDF calls (RFC 5869), containing a string of HashLen zeroes.- Parameters:
cryptoHashAlgorithm
- the hash algorithm to instantiate HMAC with. SeeCryptoHashAlgorithm
for values.
-