This module provides a set of cryptographic functions.
Hash functions -
Hmac functions -
Block ciphers -
Digital signatures
byte() = 0 ... 255
ioelem() = byte() | binary() | iolist()
iolist() = [ioelem()]
key_value() = integer() | binary()
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 RFC 3447.
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.
dss_public() = [key_value()] =[P, Q, G, Y]
srp_public() = key_value()
Where is
srp_private() = key_value()
Where is
srp_params() = {user, [Generator::binary(), Prime::binary(), Version::atom()]} |
{host, [Verifier::binary(), Generator::binary(), Prime::binary(), Version::atom()]}
| {user, [DerivedKey::binary(), Prime::binary(), Generator::binary(), Version::atom() | [Scrambler:binary()]]}
| {host,[Verifier::binary(), Prime::binary(), Version::atom() | [Scrambler::binary]]}
Where Verifier is
dh_public() = key_value()
dh_private() = key_value()
dh_params() = [key_value()] = [P, G]
ecdh_public() = key_value()
ecdh_private() = key_value()
ecdh_params() = ec_named_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
Provides the available crypto algorithms in terms of a list of atoms.
Computes the shared secret from the private key and the other party's public key.
Performs bit-wise XOR (exclusive or) on the data supplied.
Generates public keys of type
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
Finalizes the HMAC operation referenced by
Finalizes the HMAC operation referenced by
Provides the available crypto functions in terms of a list of atoms.
Provides the name and version of the libraries used by crypto.
> info_lib(). [{<<"OpenSSL">>,9469983,<<"OpenSSL 0.9.8a 11 Oct 2005">>}]
From OTP R16 the numeric version represents the version of the OpenSSL
header files (
Computes the function
Generates N bytes randomly uniform 0..255, and returns the
result in a binary. Uses the
Generate a random number
Creates a digital signature.
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
Verifies a digital signature
Encrypts
Decrypts
Encrypts
Decrypts
Returns the
Encrypts
Decrypts
Initializes the state for use in streaming AES encryption using Counter mode (CTR).
Encrypts
Decrypts
Encrypts the first 64 bits of
Decrypts the first 64 bits of
Encrypts
Decrypts
Encrypts
Decrypts
Encrypts
Encrypts
Decrypts
Returns the
Encrypts
Decrypts
Returns the
Encrypts
Decrypts
Encrypts
May throw exception
Decrypts
May throw exception
Encrypts
Decrypts
Encrypts
Decrypts
Encrypts the data with RC4 symmetric stream encryption. Since it is symmetric, the same function is used for decryption.
Encrypts the
Decrypts the
Encrypts the
Decrypts the
The Data Encryption Standard (DES) defines an algorithm for encrypting and decrypting an 8 byte quantity using an 8 byte key (actually only 56 bits of the key is used).
When it comes to encrypting and decrypting blocks that are multiples of 8 bytes various modes are defined (NIST SP 800-38A). One of those modes is the Cipher Block Chaining (CBC) mode, where the encryption of an 8 byte segment depend not only of the contents of the segment itself, but also on the result of encrypting the previous segment: the encryption of the previous segment becomes the initializing vector of the encryption of the current segment.
Thus the encryption of every segment depends on the encryption key (which is secret) and the encryption of the previous segment, except the first segment which has to be provided with an initial initializing vector. That vector could be chosen at random, or be a counter of some kind. It does not have to be secret.
The following example is drawn from the old FIPS 81 standard (replaced by NIST SP 800-38A), where both the plain text and the resulting cipher text is settled. The following code fragment returns `true'.
>, IVec = <<16#12,16#34,16#56,16#78,16#90,16#ab,16#cd,16#ef>>, P = "Now is the time for all ", C = crypto:des_cbc_encrypt(Key, IVec, P), % Which is the same as P1 = "Now is t", P2 = "he time ", P3 = "for all ", C1 = crypto:des_cbc_encrypt(Key, IVec, P1), C2 = crypto:des_cbc_encrypt(Key, C1, P2), C3 = crypto:des_cbc_encrypt(Key, C2, P3), C = <>, C = <<16#e5,16#c7,16#cd,16#de,16#87,16#2b,16#f2,16#7c, 16#43,16#e9,16#34,16#00,16#8c,16#38,16#9c,16#0f, 16#68,16#37,16#88,16#49,16#9a,16#7c,16#05,16#f6>>, <<"Now is the time for all ">> == crypto:des_cbc_decrypt(Key, IVec, C). ]]>
The following is true for the DES CBC mode. For all
decompositions
Similarly, for all decompositions
For DES3 (which uses three 64 bit keys) the situation is the same.