This module provides a set of cryptographic functions.
Hash functions -
Hmac functions -
Cmac functions -
Block ciphers -
Digital signatures
gcm: Dworkin, M., "Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC", National Institute of Standards and Technology SP 800- 38D, November 2007.
key_value() = integer() | binary()
Always
rsa_public() = [key_value()] = [E, N]
Where E is the public exponent and N is public modulus.
rsa_private() = [key_value()] = [E, N, D] | [E, N, D, P1, P2, E1, E2, C]
Where E is the public exponent, N is public modulus and D is
the private exponent. The longer key format contains redundant
information that will make the calculation faster. P1,P2 are first
and second prime factors. E1,E2 are first and second exponents. C
is the CRT coefficient. Terminology is taken from
dss_public() = [key_value()] = [P, Q, G, Y]
Where P, Q and G are the dss parameters and Y is the public key.
dss_private() = [key_value()] = [P, Q, G, X]
Where P, Q and G are the dss parameters and X is the private key.
srp_public() = key_value()
Where is
srp_private() = key_value()
Where is
Where Verifier is
dh_public() = key_value()
dh_private() = key_value()
dh_params() = [key_value()] = [P, G] | [P, G, PrivateKeyBitLength]
ecdh_public() = key_value()
ecdh_private() = key_value()
ecdh_params() = ec_named_curve() | ec_explicit_curve()
ed_named_curves_ecdh() -> x448 | x25519
Note that the curves are only supported if the underlying OpenSSL has support for them.
ec_explicit_curve() =
{ec_field(), Prime :: key_value(), Point :: key_value(), Order :: integer(),
CoFactor :: none | integer()}
ec_field() = {prime_field, Prime :: integer()} |
{characteristic_two_field, M :: integer(), Basis :: ec_basis()}
ec_basis() = {tpbasis, K :: non_neg_integer()} |
{ppbasis, K1 :: non_neg_integer(), K2 :: non_neg_integer(), K3 :: non_neg_integer()} |
onbasis
ec_named_curve() ->
sect571r1| sect571k1| sect409r1| sect409k1| secp521r1| secp384r1| secp224r1| secp224k1|
secp192k1| secp160r2| secp128r2| secp128r1| sect233r1| sect233k1| sect193r2| sect193r1|
sect131r2| sect131r1| sect283r1| sect283k1| sect163r2| secp256k1| secp160k1| secp160r1|
secp112r2| secp112r1| sect113r2| sect113r1| sect239k1| sect163r1| sect163k1| secp256r1|
secp192r1|
brainpoolP160r1| brainpoolP160t1| brainpoolP192r1| brainpoolP192t1| brainpoolP224r1|
brainpoolP224t1| brainpoolP256r1| brainpoolP256t1| brainpoolP320r1| brainpoolP320t1|
brainpoolP384r1| brainpoolP384t1| brainpoolP512r1| brainpoolP512t1
Note that the sect curves are GF2m (characteristic two) curves and are only supported if the
underlying OpenSSL has support for them.
See also
engine_key_ref() = #{engine := engine_ref(),
key_id := key_id(),
password => password()}
engine_ref() = term()
The result of a call to for example
key_id() = string() | binary()
Identifies the key to be used. The format depends on the loaded engine. It is passed to
the
password() = string() | binary()
The key's password
stream_cipher() = rc4 | aes_ctr | chacha20
block_cipher() = aes_cbc | aes_cfb8 | aes_cfb128 | aes_ige256 | blowfish_cbc |
blowfish_cfb64 | des_cbc | des_cfb | des3_cbc | des3_cfb | des_ede3 | rc2_cbc
aead_cipher() = aes_gcm | chacha20_poly1305
Note that the actual supported algorithms depends on the underlying crypto library.
stream_key() = aes_key() | rc4_key()
block_key() = aes_key() | blowfish_key() | des_key()| des3_key()
aes_key() = iodata()
Key length is 128, 192 or 256 bits
rc4_key() = iodata()
Variable key length from 8 bits up to 2048 bits (usually between 40 and 256)
blowfish_key() = iodata()
Variable key length from 32 bits up to 448 bits
des_key() = iodata()
Key length is 64 bits (in CBC mode only 8 bits are used)
des3_key() = [binary(), binary(), binary()]
Each key part is 64 bits (in CBC mode only 8 bits are used)
digest_type() = md5 | sha | sha224 | sha256 | sha384 | sha512
rsa_digest_type() = md5 | ripemd160 | sha | sha224 | sha256 | sha384 | sha512
dss_digest_type() = sha | sha224 | sha256 | sha384 | sha512
Note that the actual supported dss_digest_type depends on the underlying crypto library. In OpenSSL version >= 1.0.1 the listed digest are supported, while in 1.0.0 only sha, sha224 and sha256 are supported. In version 0.9.8 only sha is supported.
ecdsa_digest_type() = sha | sha224 | sha256 | sha384 | sha512
sign_options() = [{rsa_pad, rsa_sign_padding()} | {rsa_pss_saltlen, integer()}]
rsa_sign_padding() = rsa_pkcs1_padding | rsa_pkcs1_pss_padding
hash_algorithms() = md5 | ripemd160 | sha | sha224 | sha256 | sha384 | sha512 |
sha3_224 | sha3_256 | sha3_384 | sha3_512
md4 is also supported for hash_init/1 and hash/2. Note that both md4 and md5 are recommended only for compatibility with existing applications. Note that the actual supported hash_algorithms depends on the underlying crypto library.
cipher_algorithms() = aes_cbc | aes_cfb8 | aes_cfb128 | aes_ctr | aes_gcm |
aes_ige256 | blowfish_cbc | blowfish_cfb64 | chacha20 | chacha20_poly1305 | des_cbc |
des_cfb | des3_cbc | des3_cfb | des_ede3 | rc2_cbc | rc4
mac_algorithms() = hmac | cmac | poly1305
public_key_algorithms() = rsa |dss | ecdsa | dh | ecdh | ec_gf2m
Note that ec_gf2m is not strictly a public key algorithm, but a restriction on what curves are supported with ecdsa and ecdh.
engine_method_type() = engine_method_rsa | engine_method_dsa | engine_method_dh |
engine_method_rand | engine_method_ecdh | engine_method_ecdsa |
engine_method_ciphers | engine_method_digests | engine_method_store |
engine_method_pkey_meths | engine_method_pkey_asn1_meths
Encrypt
May throw exception
Decrypt
May throw exception
Encrypt
In AEAD (Authenticated Encryption with Associated Data) mode, encrypt
May throw exception
Decrypt
In AEAD (Authenticated Encryption with Associated Data) mode, decrypt
May throw exception
Convert binary representation, of an integer, to an Erlang integer.
Computes the shared secret from the private key and the other party's public key.
See also
Performs bit-wise XOR (exclusive or) on the data supplied.
Generates a public key of type
RSA key generation is only available if the runtime was
built with dirty scheduler support. Otherwise, attempting to
generate an RSA key will throw exception
Computes a message digest of type
May throw exception
Initializes the context for streaming hash operations.
May throw exception
Updates the digest represented by
Finalizes the hash operation referenced by
Computes a HMAC of type
Initializes the context for streaming HMAC operations.
Updates the HMAC represented by
Do not use a
Finalizes the HMAC operation referenced by
Finalizes the HMAC operation referenced by
Computes a CMAC of type
Provides information about the FIPS operating status of
crypto and the underlying OpenSSL library. If crypto was built
with FIPS support this can be either
In FIPS mode all non-FIPS compliant algorithms are
disabled and throw exception
Provides the name and version of the libraries used by crypto.
> info_lib(). [{<<"OpenSSL">>,269484095,<<"OpenSSL 1.1.0c 10 Nov 2016"">>}]
From OTP R16 the numeric version represents the version of the OpenSSL
header files (
Computes the function
Returns the initialization vector to be used in the next
iteration of encrypt/decrypt of type
Computes a POLY1305 message authentication code (
Decrypts the
Fetches the corresponding public key from a private key stored in an Engine. The key must be of the type indicated by the Type parameter.
Encrypts the
Decrypts the
Encrypts the
Set the seed for PRNG to the given binary. This calls the
RAND_seed function from openssl. Only use this if the system
you are running on does not have enough "randomness" built in.
Normally this is when
Generate a random number
Creates a digital signature.
Algorithm
See also
Equivalent to application:start(crypto).
Equivalent to application:stop(crypto).
Generates N bytes randomly uniform 0..255, and returns the
result in a binary. Uses a cryptographically secure prng seeded and
periodically mixed with operating system provided entropy. By default
this is the
May throw exception
Creates state object for
When using the state object from this function the
Example
_ = crypto:rand_seed(), _IntegerValue = rand:uniform(42), % [1; 42] _FloatValue = rand:uniform(). % [0.0; 1.0[
Creates state object for
When using the state object from this function the
The state returned from this function can not be used
to get a reproducable random sequence as from
the other
The only supported usage is to generate one distinct random sequence from this start state.
Creates state object for
When using the state object from this function the
The cache size can be changed from its default value using the
Example
_ = crypto:rand_seed_alg(crypto_cache), _IntegerValue = rand:uniform(42), % [1; 42] _FloatValue = rand:uniform(). % [0.0; 1.0[
Creates state object for
If
If
When using the state object from this function the
The cache size can be changed from its default value using the
The state returned from this function can not be used
to get a reproducable random sequence as from
the other
In fact since random data is cached some numbers may get reproduced if you try, but this is unpredictable.
The only supported usage is to generate one distinct random sequence from this start state.
Initializes the state for use in RC4 stream encryption
Initializes the state for use in streaming AES encryption using Counter mode (CTR).
Encrypts
Decrypts
Can be used to determine which crypto algorithms that are supported by the underlying OpenSSL library
Can be used to determine which named elliptic curves are supported.
Return the defining parameters of a elliptic curve.
Verifies a digital signature
Algorithm
See also
Returns a list of all possible engine methods.
May throw exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Loads the OpenSSL engine given by
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Loads the OpenSSL engine given by
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Unloads the OpenSSL engine given by
The function throws a badarg if the parameter is in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Get a reference to an already loaded engine with
The function throws a badarg if the parameter is in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Sends ctrl commands to the OpenSSL engine given by
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
Sends ctrl commands to the OpenSSL engine given by
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
Add the engine to OpenSSL's internal list.
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
Remove the engine from OpenSSL's internal list.
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
Return the ID for the engine, or an empty binary if there is no id set.
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
Return the name (eg a description) for the engine, or an empty binary if there is no name set.
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
List the id's of all engines in OpenSSL's internal list.
It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
May throw exception notsup in case engine functionality is not supported by the underlying OpenSSL implementation.
Loads the OpenSSL engine given by
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Loads the OpenSSL engine given by
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Unloads an engine loaded with the
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter
Unloads an engine loaded with the
The function throws a badarg if the parameters are in wrong format. It may also throw the exception notsup in case there is no engine support in the underlying OpenSSL implementation.
See also the chapter