This module provides a set of cryptographic functions.
References:
md4: The MD4 Message Digest Algorithm (RFC 1320)
md5: The MD5 Message Digest Algorithm (RFC 1321)
sha: Secure Hash Standard (FIPS 180-2)
hmac: Keyed-Hashing for Message Authentication (RFC 2104)
des: Data Encryption Standard (FIPS 46-3)
aes: Advanced Encryption Standard (AES) (FIPS 197)
ecb, cbc, cfb, ofb: Recommendation for Block Cipher Modes of Operation (NIST SP 800-38A).
rsa: Recommendation for Block Cipher Modes of Operation (NIST 800-38A)
dss: Digital Signature Standard (FIPS 186-2)
The above publications can be found at
Types
byte() = 0 ... 255 ioelem() = byte() | binary() | iolist() iolist() = [ioelem()] Mpint() = >]]>
Starts the crypto server.
Stops the crypto server.
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">>}]
Computes an
Creates an MD4 context, to be used in subsequent calls to
Updates an MD4
Finishes the update of an MD4
Computes an
Creates an MD5 context, to be used in subsequent calls to
Updates an MD5
Finishes the update of an MD5
Computes an
Creates an SHA context, to be used in subsequent calls to
Updates an SHA
Finishes the update of an SHA
Computes an
Computes an
Computes an
Computes an
Encrypts
Decrypts
Returns the
Encrypts
Decrypts
Encrypts
Decrypts
Encrypts the first 64 bits of
Decrypts the first 64 bits of
Encrypts
Decrypts
Encrypts
Decrypts
Encrypts
Encrypts
Decrypts
Returns the
Convert a binary multi-precision integer
Generates N bytes randomly uniform 0..255, and returns the
result in a binary. Uses the
Generate a random number
This function performs the exponentiation
Calculates a
Calculates a
Encrypts the
Decrypts the
Encrypts the
Decrypts the
Calculates the sha digest of the
Calculates the sha digest of the
Encrypts the data with RC4 symmetric stream encryption. Since it is symmetric, the same function is used for decryption.
Generates a Diffie-Hellman
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.
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.