public class BcTlsCrypto extends AbstractTlsCrypto
This class provides default implementations for everything. If you need to customise it, extend the class and override the appropriate methods.
Constructor and Description |
---|
BcTlsCrypto() |
BcTlsCrypto(java.security.SecureRandom entropySource) |
Modifier and Type | Method and Description |
---|---|
org.bouncycastle.crypto.Digest |
cloneDigest(int cryptoHashAlgorithm,
org.bouncycastle.crypto.Digest digest) |
protected org.bouncycastle.crypto.modes.AEADBlockCipher |
createAEADBlockCipher_AES_CCM() |
protected org.bouncycastle.crypto.modes.AEADBlockCipher |
createAEADBlockCipher_AES_GCM() |
protected org.bouncycastle.crypto.modes.AEADBlockCipher |
createAEADBlockCipher_ARIA_GCM() |
protected org.bouncycastle.crypto.modes.AEADBlockCipher |
createAEADBlockCipher_Camellia_GCM() |
protected org.bouncycastle.crypto.modes.AEADBlockCipher |
createAEADBlockCipher_SM4_CCM() |
protected org.bouncycastle.crypto.modes.AEADBlockCipher |
createAEADBlockCipher_SM4_GCM() |
protected org.bouncycastle.crypto.BlockCipher |
createAESEngine() |
protected org.bouncycastle.crypto.BlockCipher |
createARIAEngine() |
protected org.bouncycastle.crypto.BlockCipher |
createBlockCipher(int encryptionAlgorithm) |
protected org.bouncycastle.crypto.BlockCipher |
createCamelliaEngine() |
protected org.bouncycastle.crypto.BlockCipher |
createCBCBlockCipher(org.bouncycastle.crypto.BlockCipher blockCipher) |
protected org.bouncycastle.crypto.BlockCipher |
createCBCBlockCipher(int encryptionAlgorithm) |
protected org.bouncycastle.crypto.modes.AEADBlockCipher |
createCCMMode(org.bouncycastle.crypto.BlockCipher engine) |
TlsCertificate |
createCertificate(byte[] encoding)
Create a TlsCertificate from an ASN.1 binary encoding of an X.509 certificate.
|
TlsCertificate |
createCertificate(short type,
byte[] encoding)
Create a TlsCertificate from a ASN.1 binary encoding of a certificate.
|
protected TlsCipher |
createChaCha20Poly1305(TlsCryptoParameters cryptoParams) |
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) |
TlsCipher |
createCipher(TlsCryptoParameters cryptoParams,
int encryptionAlgorithm,
int macAlgorithm)
Create a cipher for the specified encryption and MAC algorithms.
|
protected org.bouncycastle.crypto.BlockCipher |
createDESedeEngine() |
TlsDHDomain |
createDHDomain(TlsDHConfig dhConfig)
Create a domain object supporting the domain parameters described in dhConfig.
|
org.bouncycastle.crypto.Digest |
createDigest(int cryptoHashAlgorithm) |
TlsECDomain |
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) |
TlsHash |
createHash(int cryptoHashAlgorithm)
Create a suitable hash for the hash algorithm identifier passed in.
|
protected TlsHMAC |
createHMAC_SSL(int macAlgorithm) |
TlsHMAC |
createHMAC(int macAlgorithm)
Create a suitable HMAC for the MAC algorithm identifier passed in.
|
TlsHMAC |
createHMACForHash(int cryptoHashAlgorithm)
Create a suitable HMAC using the hash algorithm identifier passed in.
|
TlsKemDomain |
createKemDomain(TlsKemConfig kemConfig)
Create a domain object supporting the domain parameters described in kemConfig.
|
protected TlsHMAC |
createMAC(TlsCryptoParameters cryptoParams,
int macAlgorithm) |
TlsNonceGenerator |
createNonceGenerator(byte[] additionalSeedMaterial)
Create a nonce generator.
|
protected TlsNullCipher |
createNullCipher(TlsCryptoParameters cryptoParams,
int macAlgorithm) |
TlsSecret |
createSecret(byte[] data)
Create a TlsSecret object based on provided data.
|
protected org.bouncycastle.crypto.BlockCipher |
createSEEDEngine() |
protected org.bouncycastle.crypto.BlockCipher |
createSM4Engine() |
TlsSRP6Client |
createSRP6Client(TlsSRPConfig srpConfig)
Create an SRP-6 client.
|
TlsSRP6Server |
createSRP6Server(TlsSRPConfig srpConfig,
java.math.BigInteger srpVerifier)
Create an SRP-6 server.
|
TlsSRP6VerifierGenerator |
createSRP6VerifierGenerator(TlsSRPConfig srpConfig)
Create an SRP-6 verifier generator.
|
TlsSecret |
generateRSAPreMasterSecret(ProtocolVersion version)
Create a TlsSecret object containing a randomly-generated RSA PreMasterSecret
|
java.security.SecureRandom |
getSecureRandom()
Return the primary (safest) SecureRandom for this crypto.
|
boolean |
hasAnyStreamVerifiers(java.util.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 |
hasDHAgreement()
Return true if this TlsCrypto can support DH key agreement.
|
boolean |
hasECDHAgreement()
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 |
hasKemAgreement()
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 in
named group value. |
boolean |
hasRSAEncryption()
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 |
hasSRPAuthentication()
Return true if this TlsCrypto can support SRP authentication.
|
TlsSecret |
hkdfInit(int cryptoHashAlgorithm)
Setup an initial "secret" for a chain of HKDF calls (RFC 5869), containing a string of HashLen zeroes.
|
adoptSecret
public BcTlsCrypto()
public BcTlsCrypto(java.security.SecureRandom entropySource)
public java.security.SecureRandom getSecureRandom()
TlsCrypto
public TlsCertificate createCertificate(byte[] encoding) throws java.io.IOException
TlsCrypto
encoding
- DER/BER encoding of the certificate of interest.java.io.IOException
- if there is an issue on decoding or constructing the certificate.public TlsCertificate createCertificate(short type, byte[] encoding) throws java.io.IOException
TlsCrypto
type
- Certificate type as per IANA TLS Certificate Types registryencoding
- DER/BER encoding of the certificate of interest.java.io.IOException
- if there is an issue on decoding or constructing the certificate.public TlsCipher createCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm) throws java.io.IOException
TlsCrypto
See enumeration classes EncryptionAlgorithm
, MACAlgorithm
for appropriate argument values.
cryptoParams
- context specific parameters.encryptionAlgorithm
- the encryption algorithm to be employed by the cipher.macAlgorithm
- the MAC algorithm to be employed by the cipher.TlsCipher
implementing the encryption and MAC algorithms.java.io.IOException
public TlsDHDomain createDHDomain(TlsDHConfig dhConfig)
TlsCrypto
dhConfig
- the config describing the DH parameters to use.public TlsECDomain createECDomain(TlsECConfig ecConfig)
TlsCrypto
ecConfig
- the config describing the EC parameters to use.public TlsKemDomain createKemDomain(TlsKemConfig kemConfig)
TlsCrypto
kemConfig
- the config describing the KEM parameters to use.public TlsNonceGenerator createNonceGenerator(byte[] additionalSeedMaterial)
TlsCrypto
TlsCrypto
's entropy source, and from the provided additional seed material. The
output of each returned generator must be completely independent of the others.additionalSeedMaterial
- context-specific seed materialTlsNonceGenerator
public boolean hasAnyStreamVerifiers(java.util.Vector signatureAndHashAlgorithms)
TlsCrypto
signatureAndHashAlgorithms
- A Vector
of SignatureAndHashAlgorithm
values.public boolean hasAnyStreamVerifiersLegacy(short[] clientCertificateTypes)
TlsCrypto
clientCertificateTypes
- An array of ClientCertificateType
values.public boolean hasCryptoHashAlgorithm(int cryptoHashAlgorithm)
TlsCrypto
cryptoHashAlgorithm
- the algorithm of interest.public boolean hasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm)
TlsCrypto
cryptoSignatureAlgorithm
- the algorithm of interest.public boolean hasDHAgreement()
TlsCrypto
public boolean hasECDHAgreement()
TlsCrypto
public boolean hasKemAgreement()
TlsCrypto
public boolean hasEncryptionAlgorithm(int encryptionAlgorithm)
TlsCrypto
encryptionAlgorithm
- the algorithm of interest.public boolean hasHKDFAlgorithm(int cryptoHashAlgorithm)
TlsCrypto
cryptoHashAlgorithm
- the algorithm of interest.public boolean hasMacAlgorithm(int macAlgorithm)
TlsCrypto
macAlgorithm
- the algorithm of interest.public boolean hasNamedGroup(int namedGroup)
TlsCrypto
named group
value.named group
value.public boolean hasRSAEncryption()
TlsCrypto
public boolean hasSignatureAlgorithm(short signatureAlgorithm)
TlsCrypto
signatureAlgorithm
- the algorithm of interest.public boolean hasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm)
TlsCrypto
sigAndHashAlgorithm
- the algorithm of interest.public boolean hasSignatureScheme(int signatureScheme)
TlsCrypto
signatureScheme
- the scheme of interest.public boolean hasSRPAuthentication()
TlsCrypto
public TlsSecret createSecret(byte[] data)
TlsCrypto
data
- the data to base the TlsSecret on.public TlsSecret generateRSAPreMasterSecret(ProtocolVersion version)
TlsCrypto
version
- the client version to place in the first 2 bytespublic org.bouncycastle.crypto.Digest cloneDigest(int cryptoHashAlgorithm, org.bouncycastle.crypto.Digest digest)
public org.bouncycastle.crypto.Digest createDigest(int cryptoHashAlgorithm)
public TlsHash createHash(int cryptoHashAlgorithm)
TlsCrypto
See enumeration class CryptoHashAlgorithm
for appropriate argument values.
cryptoHashAlgorithm
- the hash algorithm the hash needs to implement.TlsHash
.protected org.bouncycastle.crypto.BlockCipher createBlockCipher(int encryptionAlgorithm) throws java.io.IOException
java.io.IOException
protected org.bouncycastle.crypto.BlockCipher createCBCBlockCipher(org.bouncycastle.crypto.BlockCipher blockCipher)
protected org.bouncycastle.crypto.BlockCipher createCBCBlockCipher(int encryptionAlgorithm) throws java.io.IOException
java.io.IOException
protected TlsCipher createChaCha20Poly1305(TlsCryptoParameters cryptoParams) throws java.io.IOException
java.io.IOException
protected TlsAEADCipher createCipher_AES_CCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws java.io.IOException
java.io.IOException
protected TlsAEADCipher createCipher_AES_GCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws java.io.IOException
java.io.IOException
protected TlsAEADCipher createCipher_ARIA_GCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws java.io.IOException
java.io.IOException
protected TlsAEADCipher createCipher_Camellia_GCM(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize) throws java.io.IOException
java.io.IOException
protected TlsCipher createCipher_CBC(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int cipherKeySize, int macAlgorithm) throws java.io.IOException
java.io.IOException
protected TlsAEADCipher createCipher_SM4_CCM(TlsCryptoParameters cryptoParams) throws java.io.IOException
java.io.IOException
protected TlsAEADCipher createCipher_SM4_GCM(TlsCryptoParameters cryptoParams) throws java.io.IOException
java.io.IOException
protected TlsNullCipher createNullCipher(TlsCryptoParameters cryptoParams, int macAlgorithm) throws java.io.IOException
java.io.IOException
protected org.bouncycastle.crypto.BlockCipher createAESEngine()
protected org.bouncycastle.crypto.BlockCipher createARIAEngine()
protected org.bouncycastle.crypto.BlockCipher createCamelliaEngine()
protected org.bouncycastle.crypto.BlockCipher createDESedeEngine()
protected org.bouncycastle.crypto.BlockCipher createSEEDEngine()
protected org.bouncycastle.crypto.BlockCipher createSM4Engine()
protected org.bouncycastle.crypto.modes.AEADBlockCipher createCCMMode(org.bouncycastle.crypto.BlockCipher engine)
protected org.bouncycastle.crypto.modes.AEADBlockCipher createGCMMode(org.bouncycastle.crypto.BlockCipher engine)
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_AES_CCM()
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_AES_GCM()
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_ARIA_GCM()
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_Camellia_GCM()
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_SM4_CCM()
protected org.bouncycastle.crypto.modes.AEADBlockCipher createAEADBlockCipher_SM4_GCM()
public TlsHMAC createHMAC(int macAlgorithm)
TlsCrypto
See enumeration class MACAlgorithm
for appropriate argument values.
macAlgorithm
- the MAC algorithm the HMAC needs to match.TlsHMAC
.public TlsHMAC createHMACForHash(int cryptoHashAlgorithm)
TlsCrypto
See enumeration class CryptoHashAlgorithm
for appropriate argument values.
cryptoHashAlgorithm
- the hash algorithm the HMAC should use.TlsHMAC
.protected TlsHMAC createHMAC_SSL(int macAlgorithm) throws java.io.IOException
java.io.IOException
protected TlsHMAC createMAC(TlsCryptoParameters cryptoParams, int macAlgorithm) throws java.io.IOException
java.io.IOException
public TlsSRP6Client createSRP6Client(TlsSRPConfig srpConfig)
TlsCrypto
srpConfig
- client config.public TlsSRP6Server createSRP6Server(TlsSRPConfig srpConfig, java.math.BigInteger srpVerifier)
TlsCrypto
srpConfig
- server config.srpVerifier
- the SRP6 verifier value.public TlsSRP6VerifierGenerator createSRP6VerifierGenerator(TlsSRPConfig srpConfig)
TlsCrypto
srpConfig
- generator config.public TlsSecret hkdfInit(int cryptoHashAlgorithm)
TlsCrypto
cryptoHashAlgorithm
- the hash algorithm to instantiate HMAC with. See CryptoHashAlgorithm
for values.