添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Fast Software Encryption, Cambridge Security Workshop Proceedings (December 1993), Springer-Verlag, 1994, pp. 191-204.
Chacha20
ChaCha20 and Poly1305 for IETF Protocols [RFC 7539]
Chacha20_poly1305
ChaCha20 and Poly1305 for IETF Protocols [RFC 7539] Recommendation for Block Cipher Modes of Operation: Methods and Techniques [NIST SP 800-38A] Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC [NIST SP 800-38D] Recommendation for Block Cipher Modes of Operation: The CCM Mode for Authentication and Confidentiality [NIST SP 800-38C]

The actual supported algorithms and features depends on their availability in the actual libcrypto used. See the crypto (App) about dependencies.

Enabling FIPS mode will also disable algorithms and features. block_cipher_with_iv() =
cbc_cipher() |
cfb_cipher() |
aes_cbc128 |
aes_cbc256 |
aes_ige256 |
blowfish_ofb64 |
des3_cbf |
des_ede3 |
rc2_cbc

cbc_cipher() = des_cbc | des3_cbc | aes_cbc | blowfish_cbc
cfb_cipher() =
aes_cfb128 | aes_cfb8 | blowfish_cfb64 | des3_cfb | des_cfb

Block ciphers with initialization vector for block_encrypt/4 and block_decrypt/4 . ec_named_curve() =
brainpoolP160r1 |
brainpoolP160t1 |
brainpoolP192r1 |
brainpoolP192t1 |
brainpoolP224r1 |
brainpoolP224t1 |
brainpoolP256r1 |
brainpoolP256t1 |
brainpoolP320r1 |
brainpoolP320t1 |
brainpoolP384r1 |
brainpoolP384t1 |
brainpoolP512r1 |
brainpoolP512t1 |
c2pnb163v1 |
c2pnb163v2 |
c2pnb163v3 |
c2pnb176v1 |
c2pnb208w1 |
c2pnb272w1 |
c2pnb304w1 |
c2pnb368w1 |
c2tnb191v1 |
c2tnb191v2 |
c2tnb191v3 |
c2tnb239v1 |
c2tnb239v2 |
c2tnb239v3 |
c2tnb359v1 |
c2tnb431r1 |
ipsec3 |
ipsec4 |
prime192v1 |
prime192v2 |
prime192v3 |
prime239v1 |
prime239v2 |
prime239v3 |
prime256v1 |
secp112r1 |
secp112r2 |
secp128r1 |
secp128r2 |
secp160k1 |
secp160r1 |
secp160r2 |
secp192k1 |
secp192r1 |
secp224k1 |
secp224r1 |
secp256k1 |
secp256r1 |
secp384r1 |
secp521r1 |
sect113r1 |
sect113r2 |
sect131r1 |
sect131r2 |
sect163k1 |
sect163r1 |
sect163r2 |
sect193r1 |
sect193r2 |
sect233k1 |
sect233r1 |
sect239k1 |
sect283k1 |
sect283r1 |
sect409k1 |
sect409r1 |
sect571k1 |
sect571r1 |
wtls1 |
wtls10 |
wtls11 |
wtls12 |
wtls3 |
wtls4 |
wtls5 |
wtls6 |
wtls7 |
wtls8 |
wtls9

edwards_curve_dh() = x25519 | x448
edwards_curve_ed() = ed25519 | ed448

Note that some curves are disabled if FIPS is enabled.

ec_explicit_curve() =
{Field :: ec_field() ,
Curve :: ec_curve() ,
BasePoint :: binary(),
Order :: binary(),
CoFactor :: none | binary()}

ec_field() = ec_prime_field() | ec_characteristic_two_field()
ec_curve() =
{A :: binary(), B :: binary(), Seed :: none | binary()}

Parametric curve definition.

ec_prime_field() = {prime_field, Prime :: integer()}
ec_characteristic_two_field() =
{characteristic_two_field,
M :: integer(),
Basis :: ec_basis() }

ec_basis() =
{tpbasis, K :: integer() >= 0} |
{ppbasis,
K1 :: integer() >= 0,
K2 :: integer() >= 0,
K3 :: integer() >= 0} |
onbasis

Curve definition details.

key() = iodata()
des3_key() = [ key() ]

For keylengths, iv-sizes and blocksizes see the User's Guide .

A key for des3 is a list of three iolists

rsa_public() = [ key_integer() ]
rsa_private() = [ key_integer() ]
rsa_params() =
{ModulusSizeInBits :: integer(),
PublicExponent :: key_integer() }

rsa_public() = [E, N]
rsa_private() = [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 RFC 3447 .

dss_public() = [P, Q, G, Y] 

Where P, Q and G are the dss parameters and Y is the public key.

dss_private() = [P, Q, G, X] 

Where P, Q and G are the dss parameters and X is the private key.

srp_user_gen_params() = [DerivedKey::binary(), Prime::binary(), Generator::binary(), Version::atom()]
srp_host_gen_params() = [Verifier::binary(), Prime::binary(), Version::atom() ]
srp_user_comp_params() = [DerivedKey::binary(), Prime::binary(), Generator::binary(), Version::atom() | ScramblerArg::list()]
srp_host_comp_params() = [Verifier::binary(), Prime::binary(), Version::atom() | ScramblerArg::list()]

Where Verifier is v , Generator is g and Prime is N , DerivedKey is X , and Scrambler is u (optional will be generated if not provided) from SRP design Version = '3' | '6' | '6a' pk_encrypt_decrypt_opts() = [ rsa_opt() ] | rsa_compat_opts()
rsa_opt() =
{rsa_padding, rsa_padding() } |
{signature_md, atom()} |
{rsa_mgf1_md, sha} |
{rsa_oaep_label, binary()} |
{rsa_oaep_md, sha}

rsa_padding() =
rsa_pkcs1_padding |
rsa_pkcs1_oaep_padding |
rsa_sslv23_padding |
rsa_x931_padding |
rsa_no_padding

Options for public key encrypt/decrypt. Only RSA is supported.

Warning

The RSA options are experimental.

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

pk_sign_verify_opts() = [ rsa_sign_verify_opt() ]
rsa_sign_verify_opt() =
{rsa_padding, rsa_sign_verify_padding() } |
{rsa_pss_saltlen, integer()}

rsa_sign_verify_padding() =
rsa_pkcs1_padding |
rsa_pkcs1_pss_padding |
rsa_x931_padding |
rsa_no_padding

Options for sign and verify.

Warning

The RSA options are experimental.

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

engine_key_ref() =
#{engine := engine_ref() ,
key_id := key_id() ,
password => password() ,
term() => term()}

engine_ref() = term()

The result of a call to engine_load/3 . 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 |
engine_method_ec

block_encrypt(Type :: block_cipher_without_iv() ,
Key :: key() ,
PlainText :: iodata()) ->
binary() OTP 18.0

Encrypt PlainText according to Type block cipher.

May raise exception error:notsup in case the chosen Type is not supported by the underlying libcrypto implementation.

For keylengths and blocksizes see the User's Guide . block_decrypt(Type :: block_cipher_without_iv() ,
Key :: key() ,
Data :: iodata()) ->
binary() OTP 18.0

Decrypt CipherText according to Type block cipher.

May raise exception error:notsup in case the chosen Type is not supported by the underlying libcrypto implementation.

For keylengths and blocksizes see the User's Guide .

OTP R16B01

Types

Type = block_cipher_with_iv()
AeadType = aead_cipher()
Key = key() | des3_key()
PlainText = iodata()
AAD = IVec = CipherText = CipherTag = binary()
TagLength = 1..16

Encrypt PlainText according to Type block cipher. IVec is an arbitrary initializing vector.

In AEAD (Authenticated Encryption with Associated Data) mode, encrypt PlainText according to Type block cipher and calculate CipherTag that also authenticates the AAD (Associated Authenticated Data).

May raise exception error:notsup in case the chosen Type is not supported by the underlying libcrypto implementation.

For keylengths, iv-sizes and blocksizes see the User's Guide .

OTP R16B01

Types

Type = block_cipher_with_iv()
AeadType = aead_cipher()
Key = key() | des3_key()
PlainText = iodata()
AAD = IVec = CipherText = CipherTag = binary()

Decrypt CipherText according to Type block cipher. IVec is an arbitrary initializing vector.

In AEAD (Authenticated Encryption with Associated Data) mode, decrypt CipherText according to Type block cipher and check the authenticity the PlainText and AAD (Associated Authenticated Data) using the CipherTag . May return error if the decryption or validation fail's

May raise exception error:notsup in case the chosen Type is not supported by the underlying libcrypto implementation.

For keylengths, iv-sizes and blocksizes see the User's Guide . compute_key(Type, OthersPublicKey, MyPrivateKey, Params) ->
SharedSecret OTP R16B01

Types

Type = dh | ecdh | srp
SharedSecret = binary()

Computes the shared secret from the private key and the other party's public key. See also public_key:compute_key/2

Types

Type = dh | ecdh | rsa | srp

Generates a public key of type Type . See also public_key:generate_key/1 . May raise exception: error:badarg : an argument is of wrong type or has an illegal value, error:low_entropy : the random generator failed due to lack of secure "randomness", error:computation_failed : the computation fails of another reason than low_entropy .

RSA key generation is only available if the runtime was built with dirty scheduler support. Otherwise, attempting to generate an RSA key will raise exception error:notsup .

Types

Data = iodata()
Digest = binary()

Computes a message digest of type Type from Data .

May raise exception error:notsup in case the chosen Type is not supported by the underlying libcrypto implementation.

Types

Initializes the context for streaming hash operations. Type determines which digest to use. The returned context should be used as argument to hash_update .

May raise exception error:notsup in case the chosen Type is not supported by the underlying libcrypto implementation.

Updates the digest represented by Context using the given Data . Context must have been generated using hash_init or a previous call to this function. Data can be any length. NewContext must be passed into the next call to hash_update or hash_final .

Finalizes the hash operation referenced by Context returned from a previous call to hash_update . The size of Digest is determined by the type of hash function used to generate it.

Key = iodata()

Initializes the context for streaming HMAC operations. Type determines which hash function to use in the HMAC operation. Key is the authentication key. The key can be any length.

Updates the HMAC represented by Context using the given Data . Context must have been generated using an HMAC init function (such as hmac_init ). Data can be any length. NewContext must be passed into the next call to hmac_update or to one of the functions hmac_final and hmac_final_n

Warning

Do not use a Context as argument in more than one call to hmac_update or hmac_final. The semantics of reusing old contexts in any way is undefined and could even crash the VM in earlier releases. The reason for this limitation is a lack of support in the underlying libcrypto API.

Types

Type =
cbc_cipher() |
cfb_cipher() |
blowfish_cbc |
des_ede3 |
rc2_cbc
Key = Data = iodata()
MacLength = integer()
Mac = binary()

Computes a CMAC of type Type from Data using Key as the authentication key.

MacLength will limit the size of the resultant Mac .

Provides information about the FIPS operating status of crypto and the underlying libcrypto library. If crypto was built with FIPS support this can be either enabled (when running in FIPS mode) or not_enabled . For other builds this value is always not_supported .

See enable_fips_mode/1 about how to enable FIPS mode.

Warning

In FIPS mode all non-FIPS compliant algorithms are disabled and raise exception error:notsup . Check supports that in FIPS mode returns the restricted list of available algorithms.

Enables ( Enable = true ) or disables ( Enable = false ) FIPS mode. Returns true if the operation was successful or false otherwise.

Note that to enable FIPS mode succesfully, OTP must be built with the configure option --enable-fips , and the underlying libcrypto must also support FIPS.

See also info_fips/0 .

Provides the name and version of the libraries used by crypto.

Name is the name of the library. VerNum is the numeric version according to the library's own versioning scheme. VerStr contains a text variant of the version.

> 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 ( openssl/opensslv.h ) used when crypto was compiled. The text variant represents the libcrypto library used at runtime. In earlier OTP versions both numeric and text was taken from the library.

Returns the initialization vector to be used in the next iteration of encrypt/decrypt of type Type . Data is the encrypted data from the previous iteration step. The IVec argument is only needed for des_cfb as the vector used in the previous iteration step.

private_decrypt(Algorithm, CipherText, PrivateKey, Options) ->
PlainText OTP R16B01

Types

Algorithm = pk_encrypt_decrypt_algs()
CipherText = binary()
PlainText = binary()

Decrypts the CipherText , encrypted with public_encrypt/4 (or equivalent function) using the PrivateKey , and returns the plaintext (message digest). This is a low level signature verification operation used for instance by older versions of the SSL protocol. See also public_key:decrypt_private/[2,3] private_encrypt(Algorithm, PlainText, PrivateKey, Options) ->
CipherText OTP R16B01

Types

PlainText = binary()
CipherText = binary()

Encrypts the PlainText using the PrivateKey and returns the ciphertext. This is a low level signature operation used for instance by older versions of the SSL protocol. See also public_key:encrypt_private/[2,3] public_decrypt(Algorithm, CipherText, PublicKey, Options) ->
PlainText OTP R16B01

Types

CipherText = binary()
PlainText = binary()

Decrypts the CipherText , encrypted with private_encrypt/4 (or equivalent function) using the PrivateKey , and returns the plaintext (message digest). This is a low level signature verification operation used for instance by older versions of the SSL protocol. See also public_key:decrypt_public/[2,3] public_encrypt(Algorithm, PlainText, PublicKey, Options) ->
CipherText OTP R16B01

Types

PlainText = binary()
CipherText = binary()

Encrypts the PlainText (message digest) using the PublicKey and returns the CipherText . This is a low level signature operation used for instance by older versions of the SSL protocol. See also public_key:encrypt_public/[2,3]

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 strong_rand_bytes/1 raises error:low_entropy

Types

Lo, Hi, N = integer()

Generate a random number N, Lo =< N < Hi. Uses the crypto library pseudo-random number generator. Hi must be larger than Lo .

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 RAND_bytes method from OpenSSL.

May raise exception error:low_entropy in case the random generator failed due to lack of secure "randomness".

Creates state object for random number generation , in order to generate cryptographically strong random numbers (based on OpenSSL's BN_rand_range ), and saves it in the process dictionary before returning it as well. See also rand:seed/1 and rand_seed_s/0 . When using the state object from this function the rand functions using it may raise exception error:low_entropy in case the random generator failed due to lack of secure "randomness".

Example

_ = crypto:rand_seed(), _IntegerValue = rand:uniform(42), % [1; 42] _FloatValue = rand:uniform(). % [0.0; 1.0[ Creates state object for random number generation , in order to generate cryptographically strongly random numbers (based on OpenSSL's BN_rand_range ). See also rand:seed_s/1 . When using the state object from this function the rand functions using it may raise exception error:low_entropy in case the random generator failed due to lack of secure "randomness". The state returned from this function can not be used to get a reproducable random sequence as from the other functions, since reproducability does not match cryptographically safe. The only supported usage is to generate one distinct random sequence from this start state. Creates state object for random number generation , in order to generate cryptographically strong random numbers. See also rand:seed/1 and rand_seed_alg_s/1 . When using the state object from this function the rand functions using it may raise exception error:low_entropy in case the random generator failed due to lack of secure "randomness". The cache size can be changed from its default value using the crypto app's configuration parameter rand_cache_size .

Example

_ = crypto:rand_seed_alg(crypto_cache), _IntegerValue = rand:uniform(42), % [1; 42] _FloatValue = rand:uniform(). % [0.0; 1.0[ OTP 21.0

Types

Alg = crypto | crypto_cache
Creates state object for random number generation , in order to generate cryptographically strongly random numbers. See also rand:seed_s/1 . If Alg is crypto this function behaves exactly like rand_seed_s/0 . If Alg is crypto_cache this function fetches random data with OpenSSL's RAND_bytes and caches it for speed using an internal word size of 56 bits that makes calculations fast on 64 bit machines. When using the state object from this function the rand functions using it may raise exception error:low_entropy in case the random generator failed due to lack of secure "randomness". The cache size can be changed from its default value using the crypto app's configuration parameter rand_cache_size . The state returned from this function can not be used to get a reproducable random sequence as from the other functions, since reproducability does not match cryptographically safe. 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 streaming AES encryption using Counter mode (CTR). Key is the AES key and must be either 128, 192, or 256 bits long. IVec is an arbitrary initializing vector of 128 bits (16 bytes). This state is for use with stream_encrypt and stream_decrypt .

For keylengths and iv-sizes see the User's Guide .

Encrypts PlainText according to the stream cipher Type specified in stream_init/3. Text can be any number of bytes. The initial State is created using stream_init . NewState must be passed into the next call to stream_encrypt .

Decrypts CipherText according to the stream cipher Type specified in stream_init/3. PlainText can be any number of bytes. The initial State is created using stream_init . NewState must be passed into the next call to stream_decrypt .

Types

Support =
{hashs, Hashs} |
{ciphers, Ciphers} |
{public_keys, PKs} |
{macs, Macs} |
{curves, Curves} |
{rsa_opts, RSAopts}
PKs = [rsa | dss | ecdsa | dh | ecdh | ec_gf2m]
Macs = [hmac | cmac | poly1305]

Can be used to determine which crypto algorithms that are supported by the underlying libcrypto library

Note: the rsa_opts entry is in an experimental state and may change or be removed without notice. No guarantee for the accuarcy of the rsa option's value list should be assumed.

Types

Msg = binary() | {digest, binary()}
Signature = binary()

Creates a digital signature.

The msg is either the binary "cleartext" data to be signed or it is the hashed value of "cleartext" i.e. the digest (plaintext).

Algorithm dss can only be used together with digest type sha .

See also public_key:sign/3 .

Types

Msg = binary() | {digest, binary()}
Signature = binary()
Result = boolean()

Verifies a digital signature

The msg is either the binary "cleartext" data to be signed or it is the hashed value of "cleartext" i.e. the digest (plaintext).

Algorithm dss can only be used together with digest type sha .

See also public_key:verify/4 .

Type = rsa | dss
EnginePrivateKeyRef = engine_key_ref()

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. May raise exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Loads the OpenSSL engine given by EngineId if it is available and then returns ok and an engine handle. This function is the same as calling engine_load/4 with EngineMethods set to a list of all the possible methods. An error tuple is returned if the engine can't be loaded. The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Loads the OpenSSL engine given by EngineId if it is available and then returns ok and an engine handle. An error tuple is returned if the engine can't be loaded. The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Unloads the OpenSSL engine given by Engine . An error tuple is returned if the engine can't be unloaded. The function raises a error:badarg if the parameter is in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Get a reference to an already loaded engine with EngineId . An error tuple is returned if the engine can't be unloaded. The function raises a error:badarg if the parameter is in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Sends ctrl commands to the OpenSSL engine given by Engine . This function is the same as calling engine_ctrl_cmd_string/4 with Optional set to false . The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. engine_ctrl_cmd_string(Engine, CmdName, CmdArg, Optional) ->
Result OTP 20.2

Types

Engine = term()
CmdName = CmdArg = unicode:chardata()
Optional = boolean()
Result = ok | {error, Reason :: term()}
Sends ctrl commands to the OpenSSL engine given by Engine . Optional is a boolean argument that can relax the semantics of the function. If set to true it will only return failure if the ENGINE supported the given command name but failed while executing it, if the ENGINE doesn't support the command name it will simply return success without doing anything. In this case we assume the user is only supplying commands specific to the given ENGINE so we set this to false . The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation.

Add the engine to OpenSSL's internal list.

The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation.

Remove the engine from OpenSSL's internal list.

The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error: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 raises a error:badarg if the parameters are in wrong format. It may also raise the exception error: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 raises a error:badarg if the parameters are in wrong format. It may also raise the exception error: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 raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. May raise exception error:notsup in case engine functionality is not supported by the underlying OpenSSL implementation. Loads the OpenSSL engine given by EngineId and the path to the dynamic library implementing the engine. This function is the same as calling ensure_engine_loaded/3 with EngineMethods set to a list of all the possible methods. An error tuple is returned if the engine can't be loaded. The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Loads the OpenSSL engine given by EngineId and the path to the dynamic library implementing the engine. This function differs from the normal engine_load in that sense it also add the engine id to the internal list in OpenSSL. Then in the following calls to the function it just fetch the reference to the engine instead of loading it again. An error tuple is returned if the engine can't be loaded. The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Unloads an engine loaded with the ensure_engine_loaded function. It both removes the label from the OpenSSL internal engine list and unloads the engine. This function is the same as calling ensure_engine_unloaded/2 with EngineMethods set to a list of all the possible methods. An error tuple is returned if the engine can't be unloaded. The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide. Unloads an engine loaded with the ensure_engine_loaded function. It both removes the label from the OpenSSL internal engine list and unloads the engine. An error tuple is returned if the engine can't be unloaded. The function raises a error:badarg if the parameters are in wrong format. It may also raise the exception error:notsup in case there is no engine support in the underlying OpenSSL implementation. See also the chapter Engine Load in the User's Guide.