View Source Algorithm Details

This chapter describes details of algorithms in the crypto application.

The tables only documents the supported cryptos and key lengths. The user should not draw any conclusion on security from the supplied tables.

Ciphers

A cipher in the new api is categorized as either cipher_no_iv(), cipher_iv() or cipher_aead(). The letters IV are short for Initialization Vector and AEAD is an abbreviation of Authenticated Encryption with Associated Data.

Due to irregular naming conventions, some cipher names in the old api are substituted by new names in the new api. For a list of retired names, see Retired cipher names.

To dynamically check availability, check that the name in the Cipher and Mode column is present in the list returned by crypto:supports(ciphers).

Ciphers without an IV - cipher_no_iv()

To be used with:

The ciphers are:

Cipher and ModeKey length [bytes]Block size [bytes]
aes_128_ecb1616
aes_192_ecb2416
aes_256_ecb3216
blowfish_ecb168
des_ecb88
rc4161
sm4_ecb1616

Table: Ciphers without IV

Ciphers with an IV - cipher_iv()

To be used with:

The ciphers are:

Cipher and ModeKey length [bytes]IV length [bytes]Block size [bytes]Limited to OpenSSL versions
aes_128_cbc161616
aes_192_cbc241616
aes_256_cbc321616
aes_128_cfb816161
aes_192_cfb824161
aes_256_cfb832161
aes_128_cfb12816161
aes_192_cfb12824161
aes_256_cfb12832161
aes_128_ctr16161
aes_192_ctr24161
aes_256_ctr32161
aes_128_ofb16161
aes_192_ofb24161
aes_256_ofb32161
blowfish_cbc1688
blowfish_cfb641681
blowfish_ofb641681
chacha2032161≥1.1.0d
des_cbc888
des_ede3_cbc2488
des_cfb881
des_ede3_cfb2481
rc2_cbc1688
sm4_cbc161616≥1.1.1
sm4_cfb161616≥1.1.1
sm4_ofb161616≥1.1.1
sm4_ctr161616≥1.1.1

Table: Ciphers with IV

Ciphers with AEAD - cipher_aead()

To be used with:

The ciphers are:

Cipher and ModeKey length [bytes]IV length [bytes]AAD length [bytes]Tag length [bytes]Block size [bytes]Limited to OpenSSL versions
aes_128_ccm167-13anyeven 4-16 default: 12any≥1.0.1
aes_192_ccm247-13anyeven 4-16 default: 12any≥1.0.1
aes_256_ccm327-13anyeven 4-16 default: 12any≥1.0.1
aes_128_gcm16≥1any1-16 default: 16any≥1.0.1
aes_192_gcm24≥1any1-16 default: 16any≥1.0.1
aes_256_gcm32≥1any1-16 default: 16any≥1.0.1
chacha20_poly1305321-16any16any≥1.1.0
sm4_gcm1612any16any≥3.1.0
sm4_ccm1612any16any≥3.1.0

Table: AEAD ciphers

Message Authentication Codes (MACs)

To be used in mac/4 and related functions.

CMAC

CMAC with the following ciphers are available with OpenSSL 1.0.1 or later if not disabled by configuration.

To dynamically check availability, check that the name cmac is present in the list returned by crypto:supports(macs). Also check that the name in the Cipher and Mode column is present in the list returned by crypto:supports(ciphers).

Cipher and ModeKey length [bytes]Max Mac Length (= default length) [bytes]
aes_128_cbc1616
aes_192_cbc2416
aes_256_cbc3216
aes_128_ecb1616
aes_192_ecb2416
aes_256_ecb3216
blowfish_cbc168
blowfish_ecb168
des_cbc88
des_ecb88
des_ede3_cbc248
rc2_cbc168

Table: CMAC cipher key lengths

HMAC

Available in all OpenSSL compatible with Erlang CRYPTO if not disabled by configuration.

To dynamically check availability, check that the name hmac is present in the list returned by crypto:supports(macs) and that the hash name is present in the list returned by crypto:supports(hashs).

HashMax Mac Length (= default length) [bytes]
sha20
sha22428
sha25632
sha38448
sha51264
sha3_22428
sha3_25632
sha3_38448
sha3_51264
shake12864
shake25664
blake2b64
blake2s32
md416
md516
ripemd16020

Table: HMAC output sizes

POLY1305

POLY1305 is available with OpenSSL 1.1.1 or later if not disabled by configuration.

To dynamically check availability, check that the name poly1305 is present in the list returned by crypto:supports(macs).

The poly1305 mac wants an 32 bytes key and produces a 16 byte MAC by default.

Hash

To dynamically check availability, check that the wanted name in the Names column is present in the list returned by crypto:supports(hashs).

TypeNamesLimited to OpenSSL versions
SHA1sha
SHA2sha224, sha256, sha384, sha512
SHA3sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256≥1.1.1
SM3sm3≥1.1.1
MD4md4
MD5md5
RIPEMDripemd160

Public Key Cryptography

RSA

RSA is available with all OpenSSL versions compatible with Erlang CRYPTO if not disabled by configuration. To dynamically check availability, check that the atom rsa is present in the list returned by crypto:supports(public_keys).

Warning

The RSA options are experimental.

The exact set of options and there syntax may be changed without prior notice.

Optionsign/verifypublic encrypt private decryptprivate encrypt public decrypt
{rsa_padding,rsa_x931_padding}xx
{rsa_padding,rsa_pkcs1_padding}xxx
{rsa_padding,rsa_pkcs1_pss_padding} {rsa_pss_saltlen, -2..} {rsa_mgf1_md, atom()}x (2) x (2) x (2)
{rsa_padding,rsa_pkcs1_oaep_padding} {rsa_mgf1_md, atom()} {rsa_oaep_label, binary()}} {rsa_oaep_md, atom()}x (2) x (2) x (3) x (3)
{rsa_padding,rsa_no_padding}x (1)

Notes:

  1. (1) OpenSSL ≤ 1.0.0
  2. (2) OpenSSL ≥ 1.0.1
  3. (3) OpenSSL ≥ 1.1.0

DSS

DSS is available with OpenSSL versions compatible with Erlang CRYPTO if not disabled by configuration. To dynamically check availability, check that the atom dss is present in the list returned by crypto:supports(public_keys).

ECDSA

ECDSA is available with OpenSSL 0.9.8o or later if not disabled by configuration. To dynamically check availability, check that the atom ecdsa is present in the list returned by crypto:supports(public_keys). If the atom ec_gf2m also is present, the characteristic two field curves are available.

The actual supported named curves could be checked by examining the list returned by crypto:supports(curves).

EdDSA

EdDSA is available with OpenSSL 1.1.1 or later if not disabled by configuration. To dynamically check availability, check that the atom eddsa is present in the list returned by crypto:supports(public_keys).

Support for the curves ed25519 and ed448 is implemented. The actual supported named curves could be checked by examining the list with the list returned by crypto:supports(curves).

Diffie-Hellman

Diffie-Hellman computations are available with OpenSSL versions compatible with Erlang CRYPTO if not disabled by configuration. To dynamically check availability, check that the atom dh is present in the list returned by crypto:supports(public_keys).

Elliptic Curve Diffie-Hellman

Elliptic Curve Diffie-Hellman is available with OpenSSL 0.9.8o or later if not disabled by configuration. To dynamically check availability, check that the atom ecdh is present in the list returned by crypto:supports(public_keys).

The Edward curves x25519 and x448 are supported with OpenSSL 1.1.1 or later if not disabled by configuration.

The actual supported named curves could be checked by examining the list returned by crypto:supports(curves).