From 7c901c92f5936ca2f212300d2f13f899b7a222e0 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Fri, 26 Apr 2013 18:08:48 +0200 Subject: crypto: Deprecate functions, update doc and specs --- lib/crypto/doc/src/crypto.xml | 1442 +++++++++++++------------------------ lib/crypto/doc/src/crypto_app.xml | 47 +- lib/crypto/src/crypto.erl | 99 ++- lib/crypto/test/crypto_SUITE.erl | 86 ++- 4 files changed, 594 insertions(+), 1080 deletions(-) (limited to 'lib/crypto') diff --git a/lib/crypto/doc/src/crypto.xml b/lib/crypto/doc/src/crypto.xml index 9201d649d7..c4e6993460 100644 --- a/lib/crypto/doc/src/crypto.xml +++ b/lib/crypto/doc/src/crypto.xml @@ -22,100 +22,115 @@ crypto - Peter Högfeldt - - 2000-06-20 - B crypto Crypto Functions

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)

+

Hash functions - The MD4 Message Digest Algorithm (RFC 1320), + The MD5 Message Digest Algorithm (RFC 1321) and + Secure Hash Standard +

-

ecb, cbc, cfb, ofb, ctr: Recommendation for Block Cipher Modes - of Operation (NIST SP 800-38A).

+

Hmac functions - Keyed-Hashing for Message Authentication (RFC 2104)

-

rsa: Recommendation for Block Cipher Modes of Operation - (NIST 800-38A)

+

Block ciphers - DES and AES and + and Block Cipher Modes - ECB, CBC, CFB, OFB and CTR

-

dss: Digital Signature Standard (FIPS 186-2)

+

RSA encryption RFC 1321

-

srp: Secure Remote Password Protocol (RFC 2945)

+

Digital signatures Digital Signature Standard (DSS) and Elliptic Curve Digital + Signature Algorithm (ECDSA)

-

ecdsa: "Public Key Cryptography for the Financial - Services Industry: The Elliptic Curve Digital - Signature Standard (ECDSA)", November, 2005.

+

Secure Remote Password Protocol (SRP - RFC 2945)

- -

ec: Standards for Efficient Cryptography Group (SECG), "SEC 1: - Elliptic Curve Cryptography", Version 1.0, September 2000.

-
- -

ecdsa: American National Standards Institute (ANSI), - ANS X9.62-2005: The Elliptic Curve Digital Signature - Algorithm (ECDSA), 2005.

-
-

The above publications can be found at NIST publications, at IETF. -

-

Types

-
-byte() = 0 ... 255
-ioelem() = byte() | binary() | iolist()
-iolist() = [ioelem()]
-Mpint() = >]]>
-    
-

+ +
+ DATA TYPES + +

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 A or B from SRP design

+ +

srp_private() = key_value()

+

Where is a or b from SRP design

+ +

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 v, Generator is g and Prime is N, DerivedKey is X, and Scrambler is + u (optional will be genrated if not provided) from SRP design + Version = '3' | '6' | '6a' +

+ +

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

+ +
+ - - start() -> ok - Start the crypto server. - -

Starts the crypto server.

-
-
- - stop() -> ok - Stop the crypto server. - -

Stops the crypto server.

-
-
- - info() -> [atom()] - Provide a list of available crypto functions. - -

Provides the available crypto functions in terms of a list - of atoms.

-
-
- + algorithms() -> [atom()] Provide a list of available crypto algorithms. @@ -123,170 +138,52 @@ Mpint() = >]]> of atoms.

+ - info_lib() -> [{Name,VerNum,VerStr}] - Provides information about the libraries used by crypto. - - Name = binary() - VerNum = integer() - VerStr = binary() - - -

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">>,9469983,<<"OpenSSL 0.9.8a 11 Oct 2005">>}]
-        
-

- 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 OpenSSL library used at runtime. - In earlier OTP versions both numeric and text was taken from the library. -

-
-
- - md4(Data) -> Digest - Compute an MD4message digest from Data - - Data = iolist() | binary() - Digest = binary() - - -

Computes an MD4 message digest from Data, where - the length of the digest is 128 bits (16 bytes).

-
-
- - md4_init() -> Context - Creates an MD4 context - - Context = binary() - - -

Creates an MD4 context, to be used in subsequent calls to - md4_update/2.

-
-
- - md4_update(Context, Data) -> NewContext - Update an MD4 Contextwith Data, and return a NewContext - - Data = iolist() | binary() - Context = NewContext = binary() - - -

Updates an MD4 Context with Data, and returns - a NewContext.

-
-
- - md4_final(Context) -> Digest - Finish the update of an MD4 Contextand return the computed MD4message digest - - Context = Digest = binary() - - -

Finishes the update of an MD4 Context and returns - the computed MD4 message digest.

-
-
- - md5(Data) -> Digest - Compute an MD5message digest from Data - - Data = iolist() | binary() - Digest = binary() - - -

Computes an MD5 message digest from Data, where - the length of the digest is 128 bits (16 bytes).

-
-
- - md5_init() -> Context - Creates an MD5 context - - Context = binary() - - -

Creates an MD5 context, to be used in subsequent calls to - md5_update/2.

-
-
- - md5_update(Context, Data) -> NewContext - Update an MD5 Contextwith Data, and return a NewContext - - Data = iolist() | binary() - Context = NewContext = binary() - - -

Updates an MD5 Context with Data, and returns - a NewContext.

-
-
- - md5_final(Context) -> Digest - Finish the update of an MD5 Contextand return the computed MD5message digest - - Context = Digest = binary() - - -

Finishes the update of an MD5 Context and returns - the computed MD5 message digest.

-
-
- - sha(Data) -> Digest - Compute an SHAmessage digest from Data - - Data = iolist() | binary() - Digest = binary() - - -

Computes an SHA message digest from Data, where - the length of the digest is 160 bits (20 bytes).

-
-
- - sha_init() -> Context - Create an SHA context + compute_key(Type, OthersPublicKey, MyPrivateKey, Params) -> SharedSecret + Computes the shared secret - Context = binary() + Type = dh | ecdh | srp + OthersPublicKey = dh_public() | ecdh_public() | srp_public() + MyPrivate = dh_private() | ecdh_private() | srp_private() + Params = dh_params() | edhc_params() | srp_params() + SharedSecret = binary() -

Creates an SHA context, to be used in subsequent calls to - sha_update/2.

+

Computes the shared secret from the private key and the other party's public key. +

+ - sha_update(Context, Data) -> NewContext - Update an SHA context + exor(Data1, Data2) -> Result + XOR data - Data = iolist() | binary() - Context = NewContext = binary() + Data1, Data2 = iolist() | binary() + Result = binary() -

Updates an SHA Context with Data, and returns - a NewContext.

+

Performs bit-wise XOR (exclusive or) on the data supplied.

- - sha_final(Context) -> Digest - Finish the update of an SHA context + + + generate_key(Type, Params) -> {PublicKey, PrivateKey} + generate_key(Type, Params, PrivateKey) -> {PublicKey, PrivateKey} + Generates a public keys of type Type - Context = Digest = binary() + Type = dh | ecdh | srp + Params = dh_params() | edhc_params() | srp_params() + PublicKey = dh_public() | ecdh_public() | srp_public() + PrivateKey = dh_private() | ecdh_private() | srp_private() -

Finishes the update of an SHA Context and returns - the computed SHA message digest.

+

Generates public keys of type Type. +

- + + hash(Type, Data) -> Digest @@ -300,6 +197,7 @@ Mpint() = >]]> is not supported by the underlying OpenSSL implementation.

+ hash_init(Type) -> Context @@ -314,6 +212,7 @@ Mpint() = >]]> is not supported by the underlying OpenSSL implementation.

+ hash_update(Context, Data) -> NewContext @@ -341,32 +240,7 @@ Mpint() = >]]> function used to generate it.

- - md5_mac(Key, Data) -> Mac - Compute an MD5 MACmessage authentification code - - Key = Data = iolist() | binary() - Mac = binary() - - -

Computes an MD5 MAC message authentification code - from Key and Data, where the the length of the - Mac is 128 bits (16 bytes).

-
-
- - md5_mac_96(Key, Data) -> Mac - Compute an MD5 MACmessage authentification code - - Key = Data = iolist() | binary() - Mac = binary() - - -

Computes an MD5 MAC message authentification code - from Key and Data, where the length of the Mac - is 96 bits (12 bytes).

-
-
+ hmac(Type, Key, Data) -> Mac hmac(Type, Key, Data, MacLength) -> Mac @@ -384,6 +258,7 @@ Mpint() = >]]> will limit the size of the resultant Mac. + hmac_init(Type, Key) -> Context @@ -398,6 +273,7 @@ Mpint() = >]]> key. The key can be any length.

+ hmac_update(Context, Data) -> NewContext @@ -412,6 +288,7 @@ Mpint() = >]]> must be passed into the next call to hmac_update.

+ hmac_final(Context) -> Mac @@ -423,6 +300,7 @@ Mpint() = >]]> determined by the type of hash function used to generate it.

+ hmac_final_n(Context, HashLen) -> Mac @@ -435,318 +313,143 @@ Mpint() = >]]> zero. Mac will be a binary with at most HashLen bytes. Note that if HashLen is greater than the actual number of bytes returned from the underlying hash, the returned hash will have fewer than HashLen bytes.

+ + + info() -> [atom()] + Provide a list of available crypto functions. + +

Provides the available crypto functions in terms of a list + of atoms.

+
+
+ - sha_mac(Key, Data) -> Mac - sha_mac(Key, Data, MacLength) -> Mac - Compute an MD5 MACmessage authentification code + info_lib() -> [{Name,VerNum,VerStr}] + Provides information about the libraries used by crypto. - Key = Data = iolist() | binary() - Mac = binary() - MacLenength = integer() =< 20 + Name = binary() + VerNum = integer() + VerStr = binary() -

Computes an SHA MAC message authentification code - from Key and Data, where the default length of the Mac - is 160 bits (20 bytes).

+

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">>,9469983,<<"OpenSSL 0.9.8a 11 Oct 2005">>}]
+        
+

+ 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 OpenSSL library used at runtime. + In earlier OTP versions both numeric and text was taken from the library. +

+ - sha_mac_96(Key, Data) -> Mac - Compute an SHA MACmessage authentification code + mod_exp_prime(N, P, M) -> Result + Computes the function: N^P mod M - Key = Data = iolist() | binary() - Mac = binary() + N, P, M = binary() + Result = binary() | error -

Computes an SHA MAC message authentification code - from Key and Data, where the length of the Mac - is 96 bits (12 bytes).

+

Computes the function N^P mod M.

+ - des_cbc_encrypt(Key, IVec, Text) -> Cipher - Encrypt Textaccording to DES in CBC mode + rand_bytes(N) -> binary() + Generate a binary of random bytes - Key = Text = iolist() | binary() - IVec = Cipher = binary() + N = integer() -

Encrypts Text according to DES in CBC - mode. Text must be a multiple of 64 bits (8 - bytes). Key is the DES key, and IVec is an - arbitrary initializing vector. The lengths of Key and - IVec must be 64 bits (8 bytes).

+

Generates N bytes randomly uniform 0..255, and returns the + result in a binary. Uses the crypto library pseudo-random + number generator.

- - des_cbc_decrypt(Key, IVec, Cipher) -> Text - Decrypt Cipheraccording to DES in CBC mode + + + rand_uniform(Lo, Hi) -> N + Generate a random number - Key = Cipher = iolist() | binary() - IVec = Text = binary() + Lo, Hi, N = integer() -

Decrypts Cipher according to DES in CBC mode. - Key is the DES key, and IVec is an arbitrary - initializing vector. Key and IVec must have - the same values as those used when encrypting. Cipher - must be a multiple of 64 bits (8 bytes). The lengths of - Key and IVec must be 64 bits (8 bytes).

+

Generate a random number Uses the + crypto library pseudo-random number generator. + Hi must be larger than Lo.

+ - des_cbc_ivec(Data) -> IVec - Get IVec to be used in next iteration of - des_cbc_[ecrypt|decrypt] + sign(Algorithm, DigestType, Msg, Key) -> binary() + Create digital signature. - Data = iolist() | binary() - IVec = binary() + Algorithm = rsa | dss | ecdsa + Msg = binary() | {digest,binary()} + The msg is either the binary "plain text" data to be + signed or it is the hashed value of "plain text" i.e. the + digest. + DigestType = digest_type() + Key = rsa_private_key() | dsa_private_key() | ec_private_key() -

Returns the IVec to be used in a next iteration of - des_cbc_[encrypt|decrypt]. Data is the encrypted - data from the previous iteration step.

-
-
- - des_cfb_encrypt(Key, IVec, Text) -> Cipher - Encrypt Textaccording to DES in CFB mode - - Key = Text = iolist() | binary() - IVec = Cipher = binary() - - -

Encrypts Text according to DES in 8-bit CFB - mode. Key is the DES key, and IVec is an - arbitrary initializing vector. The lengths of Key and - IVec must be 64 bits (8 bytes).

-
-
- - des_cfb_decrypt(Key, IVec, Cipher) -> Text - Decrypt Cipheraccording to DES in CFB mode - - Key = Cipher = iolist() | binary() - IVec = Text = binary() - - -

Decrypts Cipher according to DES in 8-bit CFB mode. - Key is the DES key, and IVec is an arbitrary - initializing vector. Key and IVec must have - the same values as those used when encrypting. The lengths of - Key and IVec must be 64 bits (8 bytes).

-
-
- - des_cfb_ivec(IVec, Data) -> NextIVec - Get IVec to be used in next iteration of - des_cfb_[ecrypt|decrypt] - - IVec = iolist() | binary() - Data = iolist() | binary() - NextIVec = binary() - - -

Returns the IVec to be used in a next iteration of - des_cfb_[encrypt|decrypt]. IVec is the vector - used in the previous iteration step. Data is the encrypted - data from the previous iteration step.

-
-
- - des3_cbc_encrypt(Key1, Key2, Key3, IVec, Text) -> Cipher - Encrypt Textaccording to DES3 in CBC mode - - Key1 =Key2 = Key3 Text = iolist() | binary() - IVec = Cipher = binary() - - -

Encrypts Text according to DES3 in CBC - mode. Text must be a multiple of 64 bits (8 - bytes). Key1, Key2, Key3, are the DES - keys, and IVec is an arbitrary initializing - vector. The lengths of each of Key1, Key2, - Key3 and IVec must be 64 bits (8 bytes).

-
-
- - des3_cbc_decrypt(Key1, Key2, Key3, IVec, Cipher) -> Text - Decrypt Cipheraccording to DES3 in CBC mode - - Key1 = Key2 = Key3 = Cipher = iolist() | binary() - IVec = Text = binary() - - -

Decrypts Cipher according to DES3 in CBC mode. - Key1, Key2, Key3 are the DES key, and - IVec is an arbitrary initializing vector. - Key1, Key2, Key3 and IVec must - and IVec must have the same values as those used when - encrypting. Cipher must be a multiple of 64 bits (8 - bytes). The lengths of Key1, Key2, - Key3, and IVec must be 64 bits (8 bytes).

-
-
- - des3_cfb_encrypt(Key1, Key2, Key3, IVec, Text) -> Cipher - Encrypt Textaccording to DES3 in CFB mode - - Key1 =Key2 = Key3 Text = iolist() | binary() - IVec = Cipher = binary() - - -

Encrypts Text according to DES3 in 8-bit CFB - mode. Key1, Key2, Key3, are the DES - keys, and IVec is an arbitrary initializing - vector. The lengths of each of Key1, Key2, - Key3 and IVec must be 64 bits (8 bytes).

-

May throw exception notsup for old OpenSSL - versions (0.9.7) that does not support this encryption mode.

-
-
- - des3_cfb_decrypt(Key1, Key2, Key3, IVec, Cipher) -> Text - Decrypt Cipheraccording to DES3 in CFB mode - - Key1 = Key2 = Key3 = Cipher = iolist() | binary() - IVec = Text = binary() - - -

Decrypts Cipher according to DES3 in 8-bit CFB mode. - Key1, Key2, Key3 are the DES key, and - IVec is an arbitrary initializing vector. - Key1, Key2, Key3 and IVec must - and IVec must have the same values as those used when - encrypting. The lengths of Key1, Key2, - Key3, and IVec must be 64 bits (8 bytes).

-

May throw exception notsup for old OpenSSL - versions (0.9.7) that does not support this encryption mode.

-
-
- - - des_ecb_encrypt(Key, Text) -> Cipher - Encrypt Textaccording to DES in ECB mode - - Key = Text = iolist() | binary() - Cipher = binary() - - -

Encrypts Text according to DES in ECB mode. - Key is the DES key. The lengths of Key and - Text must be 64 bits (8 bytes).

-
-
- - des_ecb_decrypt(Key, Cipher) -> Text - Decrypt Cipheraccording to DES in ECB mode - - Key = Cipher = iolist() | binary() - Text = binary() - - -

Decrypts Cipher according to DES in ECB mode. - Key is the DES key. The lengths of Key and - Cipher must be 64 bits (8 bytes).

-
-
- - - blowfish_ecb_encrypt(Key, Text) -> Cipher - Encrypt the first 64 bits of Text using Blowfish in ECB mode - - Key = Text = iolist() | binary() - Cipher = binary() - - -

Encrypts the first 64 bits of Text using Blowfish in ECB mode. Key is the Blowfish key. The length of Text must be at least 64 bits (8 bytes).

-
-
- - blowfish_ecb_decrypt(Key, Text) -> Cipher - Decrypt the first 64 bits of Text using Blowfish in ECB mode - - Key = Text = iolist() | binary() - Cipher = binary() - - -

Decrypts the first 64 bits of Text using Blowfish in ECB mode. Key is the Blowfish key. The length of Text must be at least 64 bits (8 bytes).

+

Creates a digital signature.

- blowfish_cbc_encrypt(Key, IVec, Text) -> Cipher - Encrypt Text using Blowfish in CBC mode - - Key = Text = iolist() | binary() - IVec = Cipher = binary() - + start() -> ok + Equivalent to application:start(crypto). -

Encrypts Text using Blowfish in CBC mode. Key is the Blowfish key, and IVec is an - arbitrary initializing vector. The length of IVec - must be 64 bits (8 bytes). The length of Text must be a multiple of 64 bits (8 bytes).

+

Equivalent to application:start(crypto).

- blowfish_cbc_decrypt(Key, IVec, Text) -> Cipher - Decrypt Text using Blowfish in CBC mode - - Key = Text = iolist() | binary() - IVec = Cipher = binary() - + stop() -> ok + Equivalent to application:stop(crypto). -

Decrypts Text using Blowfish in CBC mode. Key is the Blowfish key, and IVec is an - arbitrary initializing vector. The length of IVec - must be 64 bits (8 bytes). The length of Text must be a multiple 64 bits (8 bytes).

+

Equivalent to application:stop(crypto).

- blowfish_cfb64_encrypt(Key, IVec, Text) -> Cipher - Encrypt Textusing Blowfish in CFB mode with 64 - bit feedback - - Key = Text = iolist() | binary() - IVec = Cipher = binary() - - -

Encrypts Text using Blowfish in CFB mode with 64 bit - feedback. Key is the Blowfish key, and IVec is an - arbitrary initializing vector. The length of IVec - must be 64 bits (8 bytes).

-
-
- - blowfish_cfb64_decrypt(Key, IVec, Text) -> Cipher - Decrypt Textusing Blowfish in CFB mode with 64 - bit feedback + strong_rand_bytes(N) -> binary() + Generate a binary of random bytes - Key = Text = iolist() | binary() - IVec = Cipher = binary() + N = integer() -

Decrypts Text using Blowfish in CFB mode with 64 bit - feedback. Key is the Blowfish key, and IVec is an - arbitrary initializing vector. The length of IVec - must be 64 bits (8 bytes).

+

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 throw exception low_entropy in case the random generator + failed due to lack of secure "randomness".

- - blowfish_ofb64_encrypt(Key, IVec, Text) -> Cipher - Encrypt Textusing Blowfish in OFB mode with 64 - bit feedback + verify(Algorithm, DigestType, Msg, Signature, Key) -> boolean() + Verifies a digital signature. - Key = Text = iolist() | binary() - IVec = Cipher = binary() + Algorithm = rsa | dss | ecdsa + Msg = binary() | {digest,binary()} + The msg is either the binary "plain text" data + or it is the hashed value of "plain text" i.e. the digest. + DigestType = digest_type() + Signature = binary() + Key = rsa_public_key() | dsa_public_key() | ec_public_key() -

Encrypts Text using Blowfish in OFB mode with 64 bit - feedback. Key is the Blowfish key, and IVec is an - arbitrary initializing vector. The length of IVec - must be 64 bits (8 bytes).

+

Verifies a digital signature

-
+
aes_cfb_128_encrypt(Key, IVec, Text) -> Cipher @@ -763,6 +466,7 @@ Mpint() = >]]> (16 bytes).

+ aes_cfb_128_decrypt(Key, IVec, Cipher) -> Text Decrypt Cipheraccording to AES in Cipher Feedback mode @@ -778,6 +482,7 @@ Mpint() = >]]> Key and IVec must be 128 bits (16 bytes).

+ aes_cbc_128_encrypt(Key, IVec, Text) -> Cipher Encrypt Textaccording to AES in Cipher Block Chaining mode @@ -794,6 +499,7 @@ Mpint() = >]]> (16 bytes).

+ aes_cbc_128_decrypt(Key, IVec, Cipher) -> Text Decrypt Cipheraccording to AES in Cipher Block Chaining mode @@ -811,6 +517,7 @@ Mpint() = >]]> Key and IVec must be 128 bits (16 bytes).

+ aes_cbc_ivec(Data) -> IVec Get IVec to be used in next iteration of @@ -825,6 +532,7 @@ Mpint() = >]]> data from the previous iteration step.

+ aes_ctr_encrypt(Key, IVec, Text) -> Cipher Encrypt Textaccording to AES in Counter mode @@ -839,6 +547,7 @@ Mpint() = >]]> (16 bytes).

+ aes_ctr_decrypt(Key, IVec, Cipher) -> Text Decrypt Cipheraccording to AES in Counter mode @@ -853,6 +562,7 @@ Mpint() = >]]> (16 bytes).

+ aes_ctr_stream_init(Key, IVec) -> State @@ -870,6 +580,7 @@ Mpint() = >]]> aes_ctr_stream_decrypt.

+ aes_ctr_stream_encrypt(State, Text) -> { NewState, Cipher} @@ -886,6 +597,7 @@ Mpint() = >]]> Cipher is the encrypted cipher text.

+ aes_ctr_stream_decrypt(State, Cipher) -> { NewState, Text } @@ -902,620 +614,446 @@ Mpint() = >]]> Text is the decrypted data.

- - erlint(Mpint) -> N - mpint(N) -> Mpint - Convert between binary multi-precision integer and erlang big integer - - Mpint = binary() - N = integer() + + + blowfish_ecb_encrypt(Key, Text) -> Cipher + Encrypt the first 64 bits of Text using Blowfish in ECB mode + + Key = Text = iolist() | binary() + Cipher = binary() -

Convert a binary multi-precision integer Mpint to and from - an erlang big integer. A multi-precision integer is a binary - with the following form: - >]]> where both - ByteLen and Bytes are big-endian. Mpints are used in - some of the functions in crypto and are not translated - in the API for performance reasons.

+

Encrypts the first 64 bits of Text using Blowfish in ECB mode. Key is the Blowfish key. The length of Text must be at least 64 bits (8 bytes).

+ - rand_bytes(N) -> binary() - Generate a binary of random bytes + blowfish_ecb_decrypt(Key, Text) -> Cipher + Decrypt the first 64 bits of Text using Blowfish in ECB mode - N = integer() + Key = Text = iolist() | binary() + Cipher = binary() -

Generates N bytes randomly uniform 0..255, and returns the - result in a binary. Uses the crypto library pseudo-random - number generator.

-
-
- - strong_rand_bytes(N) -> binary() - Generate a binary of random bytes - - N = integer() - - -

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 throw exception low_entropy in case the random generator - failed due to lack of secure "randomness".

+

Decrypts the first 64 bits of Text using Blowfish in ECB mode. Key is the Blowfish key. The length of Text must be at least 64 bits (8 bytes).

+ - rand_uniform(Lo, Hi) -> N - Generate a random number + blowfish_cbc_encrypt(Key, IVec, Text) -> Cipher + Encrypt Text using Blowfish in CBC mode - Lo, Hi, N = Mpint | integer() - Mpint = binary() + Key = Text = iolist() | binary() + IVec = Cipher = binary() -

Generate a random number Uses the - crypto library pseudo-random number generator. The - arguments (and result) can be either erlang integers or binary - multi-precision integers. Hi must be larger than Lo.

+

Encrypts Text using Blowfish in CBC mode. Key is the Blowfish key, and IVec is an + arbitrary initializing vector. The length of IVec + must be 64 bits (8 bytes). The length of Text must be a multiple of 64 bits (8 bytes).

- strong_rand_mpint(N, Top, Bottom) -> Mpint - Generate an N bit random number + blowfish_cbc_decrypt(Key, IVec, Text) -> Cipher + Decrypt Text using Blowfish in CBC mode - N = non_neg_integer() - Top = -1 | 0 | 1 - Bottom = 0 | 1 - Mpint = binary() + Key = Text = iolist() | binary() + IVec = Cipher = binary() -

Generate an N bit random number using OpenSSL's - cryptographically strong pseudo random number generator - BN_rand.

-

The parameter Top places constraints on the most - significant bits of the generated number. If Top is 1, then the - two most significant bits will be set to 1, if Top is 0, the - most significant bit will be 1, and if Top is -1 then no - constraints are applied and thus the generated number may be less than - N bits long.

-

If Bottom is 1, then the generated number is - constrained to be odd.

-

May throw exception low_entropy in case the random generator - failed due to lack of secure "randomness".

+

Decrypts Text using Blowfish in CBC mode. Key is the Blowfish key, and IVec is an + arbitrary initializing vector. The length of IVec + must be 64 bits (8 bytes). The length of Text must be a multiple 64 bits (8 bytes).

+ - mod_exp(N, P, M) -> Result - Perform N ^ P mod M + blowfish_cfb64_encrypt(Key, IVec, Text) -> Cipher + Encrypt Textusing Blowfish in CFB mode with 64 + bit feedback - N, P, M, Result = Mpint - Mpint = binary() + Key = Text = iolist() | binary() + IVec = Cipher = binary() -

This function performs the exponentiation N ^ P mod M, - using the crypto library.

+

Encrypts Text using Blowfish in CFB mode with 64 bit + feedback. Key is the Blowfish key, and IVec is an + arbitrary initializing vector. The length of IVec + must be 64 bits (8 bytes).

+ - mod_exp_prime(N, P, M) -> Result - Computes the function: N^P mod M + blowfish_cfb64_decrypt(Key, IVec, Text) -> Cipher + Decrypt Textusing Blowfish in CFB mode with 64 + bit feedback - N, P, M = binary() - Result = binary() | error + Key = Text = iolist() | binary() + IVec = Cipher = binary() -

Computes the function N^P mod M.

+

Decrypts Text using Blowfish in CFB mode with 64 bit + feedback. Key is the Blowfish key, and IVec is an + arbitrary initializing vector. The length of IVec + must be 64 bits (8 bytes).

+ - rsa_sign(DataOrDigest, Key) -> Signature - rsa_sign(DigestType, DataOrDigest, Key) -> Signature - Sign the data using rsa with the given key. + blowfish_ofb64_encrypt(Key, IVec, Text) -> Cipher + Encrypt Textusing Blowfish in OFB mode with 64 + bit feedback - DataOrDigest = Data | {digest,Digest} - Data = Mpint - Digest = binary() - Key = [E, N, D] | [E, N, D, P1, P2, E1, E2, C] - E, N, D = Mpint - Where E is the public exponent, N is public modulus and - D is the private exponent. - P1, P2, E1, E2, C = Mpint - 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. - DigestType = md5 | sha | sha224 | sha256 | sha384 | sha512 - The default DigestType is sha. - Mpint = binary() - Signature = binary() + Key = Text = iolist() | binary() + IVec = Cipher = binary() -

Creates a RSA signature with the private key Key - of a digest. The digest is either calculated as a - DigestType digest of Data or a precalculated - binary Digest.

+

Encrypts Text using Blowfish in OFB mode with 64 bit + feedback. Key is the Blowfish key, and IVec is an + arbitrary initializing vector. The length of IVec + must be 64 bits (8 bytes).

- rsa_verify(DataOrDigest, Signature, Key) -> Verified - rsa_verify(DigestType, DataOrDigest, Signature, Key) -> Verified - Verify the digest and signature using rsa with given public key. + des_cbc_encrypt(Key, IVec, Text) -> Cipher + Encrypt Textaccording to DES in CBC mode - Verified = boolean() - DataOrDigest = Data | {digest|Digest} - Data, Signature = Mpint - Digest = binary() - Key = [E, N] - E, N = Mpint - Where E is the public exponent and N is public modulus. - DigestType = md5 | sha | sha224 | sha256 | sha384 | sha512 - The default DigestType is sha. - Mpint = binary() + Key = Text = iolist() | binary() + IVec = Cipher = binary() -

Verifies that a digest matches the RSA signature using the - signer's public key Key. - The digest is either calculated as a DigestType - digest of Data or a precalculated binary Digest.

-

May throw exception notsup in case the chosen DigestType - is not supported by the underlying OpenSSL implementation.

+

Encrypts Text according to DES in CBC + mode. Text must be a multiple of 64 bits (8 + bytes). Key is the DES key, and IVec is an + arbitrary initializing vector. The lengths of Key and + IVec must be 64 bits (8 bytes).

- + - rsa_public_encrypt(PlainText, PublicKey, Padding) -> ChipherText - Encrypts Msg using the public Key. + des_cbc_decrypt(Key, IVec, Cipher) -> Text + Decrypt Cipheraccording to DES in CBC mode - PlainText = binary() - PublicKey = [E, N] - E, N = Mpint - Where E is the public exponent and N is public modulus. - Padding = rsa_pkcs1_padding | rsa_pkcs1_oaep_padding | rsa_no_padding - ChipherText = binary() + Key = Cipher = iolist() | binary() + IVec = Text = binary() -

Encrypts the PlainText (usually a session key) using the PublicKey - and returns the cipher. The Padding decides what padding mode is used, - rsa_pkcs1_padding is PKCS #1 v1.5 currently the most - used mode and rsa_pkcs1_oaep_padding is EME-OAEP as - defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty encoding - parameter. This mode is recommended for all new applications. - The size of the Msg must be less - than byte_size(N)-11 if - rsa_pkcs1_padding is used, byte_size(N)-41 if - rsa_pkcs1_oaep_padding is used and byte_size(N) if rsa_no_padding - is used. - Where byte_size(N) is the size part of an Mpint-1. -

+

Decrypts Cipher according to DES in CBC mode. + Key is the DES key, and IVec is an arbitrary + initializing vector. Key and IVec must have + the same values as those used when encrypting. Cipher + must be a multiple of 64 bits (8 bytes). The lengths of + Key and IVec must be 64 bits (8 bytes).

- rsa_private_decrypt(ChipherText, PrivateKey, Padding) -> PlainText - Decrypts ChipherText using the private Key. + des_cbc_ivec(Data) -> IVec + Get IVec to be used in next iteration of + des_cbc_[ecrypt|decrypt] - ChipherText = binary() - PrivateKey = [E, N, D] | [E, N, D, P1, P2, E1, E2, C] - E, N, D = Mpint - Where E is the public exponent, N is public modulus and - D is the private exponent. - P1, P2, E1, E2, C = Mpint - 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. - Padding = rsa_pkcs1_padding | rsa_pkcs1_oaep_padding | rsa_no_padding - PlainText = binary() + Data = iolist() | binary() + IVec = binary() -

Decrypts the ChipherText (usually a session key encrypted with - rsa_public_encrypt/3) - using the PrivateKey and returns the - message. The Padding is the padding mode that was - used to encrypt the data, - see rsa_public_encrypt/3. -

+

Returns the IVec to be used in a next iteration of + des_cbc_[encrypt|decrypt]. Data is the encrypted + data from the previous iteration step.

+ - rsa_private_encrypt(PlainText, PrivateKey, Padding) -> ChipherText - Encrypts Msg using the private Key. + des_cfb_encrypt(Key, IVec, Text) -> Cipher + Encrypt Textaccording to DES in CFB mode - PlainText = binary() - PrivateKey = [E, N, D] | [E, N, D, P1, P2, E1, E2, C] - E, N, D = Mpint - Where E is the public exponent, N is public modulus and - D is the private exponent. - P1, P2, E1, E2, C = Mpint - 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. - Padding = rsa_pkcs1_padding | rsa_no_padding - ChipherText = binary() + Key = Text = iolist() | binary() + IVec = Cipher = binary() -

Encrypts the PlainText using the PrivateKey - and returns the cipher. The Padding decides what padding mode is used, - rsa_pkcs1_padding is PKCS #1 v1.5 currently the most - used mode. - The size of the Msg must be less than byte_size(N)-11 if - rsa_pkcs1_padding is used, and byte_size(N) if rsa_no_padding - is used. Where byte_size(N) is the size part of an Mpint-1. -

+

Encrypts Text according to DES in 8-bit CFB + mode. Key is the DES key, and IVec is an + arbitrary initializing vector. The lengths of Key and + IVec must be 64 bits (8 bytes).

- rsa_public_decrypt(ChipherText, PublicKey, Padding) -> PlainText - Decrypts ChipherText using the public Key. + des_cfb_decrypt(Key, IVec, Cipher) -> Text + Decrypt Cipheraccording to DES in CFB mode - ChipherText = binary() - PublicKey = [E, N] - E, N = Mpint - Where E is the public exponent and N is public modulus - Padding = rsa_pkcs1_padding | rsa_no_padding - PlainText = binary() + Key = Cipher = iolist() | binary() + IVec = Text = binary() -

Decrypts the ChipherText (encrypted with - rsa_private_encrypt/3) - using the PrivateKey and returns the - message. The Padding is the padding mode that was - used to encrypt the data, - see rsa_private_encrypt/3. -

+

Decrypts Cipher according to DES in 8-bit CFB mode. + Key is the DES key, and IVec is an arbitrary + initializing vector. Key and IVec must have + the same values as those used when encrypting. The lengths of + Key and IVec must be 64 bits (8 bytes).

- + - dss_sign(DataOrDigest, Key) -> Signature - dss_sign(DigestType, DataOrDigest, Key) -> Signature - Sign the data using dsa with given private key. + des_cfb_ivec(IVec, Data) -> NextIVec + Get IVec to be used in next iteration of + des_cfb_[ecrypt|decrypt] - DigestType = sha - DataOrDigest = Mpint | {digest,Digest} - Key = [P, Q, G, X] - P, Q, G, X = Mpint - Where P, Q and G are the dss - parameters and X is the private key. - Digest = binary() with length 20 bytes - Signature = binary() + IVec = iolist() | binary() + Data = iolist() | binary() + NextIVec = binary() -

Creates a DSS signature with the private key Key of - a digest. The digest is either calculated as a SHA1 - digest of Data or a precalculated binary Digest.

-

A deprecated feature is having DigestType = 'none' - in which case DataOrDigest is a precalculated SHA1 - digest.

+

Returns the IVec to be used in a next iteration of + des_cfb_[encrypt|decrypt]. IVec is the vector + used in the previous iteration step. Data is the encrypted + data from the previous iteration step.

- dss_verify(DataOrDigest, Signature, Key) -> Verified - dss_verify(DigestType, DataOrDigest, Signature, Key) -> Verified - Verify the data and signature using dsa with given public key. + des3_cbc_encrypt(Key1, Key2, Key3, IVec, Text) -> Cipher + Encrypt Textaccording to DES3 in CBC mode - Verified = boolean() - DigestType = sha - DataOrDigest = Mpint | {digest,Digest} - Data = Mpint | ShaDigest - Signature = Mpint - Key = [P, Q, G, Y] - P, Q, G, Y = Mpint - Where P, Q and G are the dss - parameters and Y is the public key. - Digest = binary() with length 20 bytes + Key1 =Key2 = Key3 Text = iolist() | binary() + IVec = Cipher = binary() -

Verifies that a digest matches the DSS signature using the - public key Key. The digest is either calculated as a SHA1 - digest of Data or is a precalculated binary Digest.

-

A deprecated feature is having DigestType = 'none' - in which case DataOrDigest is a precalculated SHA1 - digest binary.

+

Encrypts Text according to DES3 in CBC + mode. Text must be a multiple of 64 bits (8 + bytes). Key1, Key2, Key3, are the DES + keys, and IVec is an arbitrary initializing + vector. The lengths of each of Key1, Key2, + Key3 and IVec must be 64 bits (8 bytes).

- rc2_cbc_encrypt(Key, IVec, Text) -> Cipher - Encrypt Textaccording to RC2 in CBC mode + des3_cbc_decrypt(Key1, Key2, Key3, IVec, Cipher) -> Text + Decrypt Cipheraccording to DES3 in CBC mode - Key = Text = iolist() | binary() - Ivec = Cipher = binary() + Key1 = Key2 = Key3 = Cipher = iolist() | binary() + IVec = Text = binary() -

Encrypts Text according to RC2 in CBC mode.

+

Decrypts Cipher according to DES3 in CBC mode. + Key1, Key2, Key3 are the DES key, and + IVec is an arbitrary initializing vector. + Key1, Key2, Key3 and IVec must + and IVec must have the same values as those used when + encrypting. Cipher must be a multiple of 64 bits (8 + bytes). The lengths of Key1, Key2, + Key3, and IVec must be 64 bits (8 bytes).

- rc2_cbc_decrypt(Key, IVec, Cipher) -> Text - Decrypts Cipheraccording to RC2 in CBC mode + des3_cfb_encrypt(Key1, Key2, Key3, IVec, Text) -> Cipher + Encrypt Textaccording to DES3 in CFB mode - Key = Text = iolist() | binary() - Ivec = Cipher = binary() + Key1 =Key2 = Key3 Text = iolist() | binary() + IVec = Cipher = binary() -

Decrypts Cipher according to RC2 in CBC mode.

+

Encrypts Text according to DES3 in 8-bit CFB + mode. Key1, Key2, Key3, are the DES + keys, and IVec is an arbitrary initializing + vector. The lengths of each of Key1, Key2, + Key3 and IVec must be 64 bits (8 bytes).

+

May throw exception notsup for old OpenSSL + versions (0.9.7) that does not support this encryption mode.

- + - rc4_encrypt(Key, Data) -> Result - Encrypt data using RC4 + des3_cfb_decrypt(Key1, Key2, Key3, IVec, Cipher) -> Text + Decrypt Cipheraccording to DES3 in CFB mode - Key, Data = iolist() | binary() - Result = binary() + Key1 = Key2 = Key3 = Cipher = iolist() | binary() + IVec = Text = binary() -

Encrypts the data with RC4 symmetric stream encryption. - Since it is symmetric, the same function is used for - decryption.

+

Decrypts Cipher according to DES3 in 8-bit CFB mode. + Key1, Key2, Key3 are the DES key, and + IVec is an arbitrary initializing vector. + Key1, Key2, Key3 and IVec must + and IVec must have the same values as those used when + encrypting. The lengths of Key1, Key2, + Key3, and IVec must be 64 bits (8 bytes).

+

May throw exception notsup for old OpenSSL + versions (0.9.7) that does not support this encryption mode.

- dh_generate_key(DHParams) -> {PublicKey,PrivateKey} - dh_generate_key(PrivateKey, DHParams) -> {PublicKey,PrivateKey} - Generates a Diffie-Hellman public key + des_ecb_encrypt(Key, Text) -> Cipher + Encrypt Textaccording to DES in ECB mode - DHParameters = [P, G] - P, G = Mpint - Where P is the shared prime number and G is the shared generator. - PublicKey, PrivateKey = Mpint() + Key = Text = iolist() | binary() + Cipher = binary() -

Generates a Diffie-Hellman PublicKey and PrivateKey (if not given). -

+

Encrypts Text according to DES in ECB mode. + Key is the DES key. The lengths of Key and + Text must be 64 bits (8 bytes).

- - dh_compute_key(OthersPublicKey, MyPrivateKey, DHParams) -> SharedSecret - Computes the shared secret + des_ecb_decrypt(Key, Cipher) -> Text + Decrypt Cipheraccording to DES in ECB mode - DHParameters = [P, G] - P, G = Mpint - Where P is the shared prime number and G is the shared generator. - OthersPublicKey, MyPrivateKey = Mpint() - SharedSecret = binary() + Key = Cipher = iolist() | binary() + Text = binary() -

Computes the shared secret from the private key and the other party's public key. -

+

Decrypts Cipher according to DES in ECB mode. + Key is the DES key. The lengths of Key and + Cipher must be 64 bits (8 bytes).

- - - srp_generate_key(Generator, Prime, Version) -> {PublicKey, PrivateKey} - srp_generate_key(Generator, Prime, Version, Private) -> {PublicKey, PrivateKey} - srp_generate_key(Verifier, Generator, Prime, Version) -> {PublicKey, PrivateKey} - srp_generate_key(Verifier, Generator, Prime, Version, Private) -> {PublicKey, PrivateKey} - Generates SRP public keys + + rc2_cbc_encrypt(Key, IVec, Text) -> Cipher + Encrypt Textaccording to RC2 in CBC mode - Verifier = binary() - Parameter v from SRP design - - Generator = binary() - Parameter g from SRP design - - Prime = binary() - Parameter N from SRP design - - Version = '3' | '6' | '6a' - SRP version, TLS SRP cipher suites uses '6a'. - PublicKey = binary() - Parameter A or B from SRP design - Private = PrivateKey = binary() - generated if not supplied - Parameter a or b from SRP design + Key = Text = iolist() | binary() + Ivec = Cipher = binary() -

Generates SRP public keys for the client side (first argument is Generator) - or for the server side (first argument is Verifier).

+

Encrypts Text according to RC2 in CBC mode.

- srp_compute_key(DerivedKey, Prime, Generator, - ClientPublic, ClientPrivate, ServerPublic, Version) -> SessionKey - srp_compute_key(DerivedKey, Prime, Generator, - ClientPublic, ClientPrivate, ServerPublic, Version, Scrambler) -> SessionKey - srp_compute_key(Verifier, Prime, - ClientPublic, ServerPublic, ServerPrivate, Version, Scrambler)-> SessionKey - srp_compute_key(Verifier, Prime, - ClientPublic, ServerPublic, ServerPrivate, Version) -> SessionKey - - Computes SRP session key + rc2_cbc_decrypt(Key, IVec, Cipher) -> Text + Decrypts Cipheraccording to RC2 in CBC mode - DerivedKey = binary() - Parameter x from SRP design - - Verifier = binary() - Parameter v from SRP design - - Prime = binary() - Parameter N from SRP design - - Generator = binary() - Parameter g from SRP design - - ClientPublic = binary() - Parameter A from SRP design - - ClientPrivate = binary() - Parameter a from SRP design - - ServerPublic = binary() - Parameter B from SRP design - - ServerPrivate = binary() - Parameter b from SRP design - - Version = '3' | '6' | '6a' - SRP version, TLS SRP cipher suites uses '6a'. - SessionKey = binary() - Result K from SRP design - + Key = Text = iolist() | binary() + Ivec = Cipher = binary() -

- Computes the SRP session key (shared secret) for the client side (first argument is DerivedKey) - or for the server side (first argument is Verifier). Also used - as premaster secret by TLS-SRP cipher suites. -

+

Decrypts Cipher according to RC2 in CBC mode.

- ec_key_new(NamedCurve) -> ECKey + rc4_encrypt(Key, Data) -> Result + Encrypt data using RC4 - NamedCurve = atom() - ECKey = EC key resource() + Key, Data = iolist() | binary() + Result = binary() -

Generate an new EC key from the named curve. The private key - will be initialized with random data. -

+

Encrypts the data with RC4 symmetric stream encryption. + Since it is symmetric, the same function is used for + decryption.

- - ec_key_generate(ECKey) -> ok | error - - ECKey = EC key resource() - - -

Fills in the public key if only the private key is known or generates - a new private/public key pair if only the curve parameters are known. -

-
-
- ec_key_to_term(ECKey) -> ECKeyTerm. + rsa_public_encrypt(PlainText, PublicKey, Padding) -> ChipherText + Encrypts Msg using the public Key. - ECKey = EC key resource() - ECKeyTerm = EC key as Erlang term + PlainText = binary() + PublicKey = [E, N] + E, N = integer() + Where E is the public exponent and N is public modulus. + Padding = rsa_pkcs1_padding | rsa_pkcs1_oaep_padding | rsa_no_padding + ChipherText = binary() -

Convert a EC key from a NIF resource into an Erlang term. +

Encrypts the PlainText (usually a session key) using the PublicKey + and returns the cipher. The Padding decides what padding mode is used, + rsa_pkcs1_padding is PKCS #1 v1.5 currently the most + used mode and rsa_pkcs1_oaep_padding is EME-OAEP as + defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty encoding + parameter. This mode is recommended for all new applications. + The size of the Msg must be less + than byte_size(N)-11 if + rsa_pkcs1_padding is used, byte_size(N)-41 if + rsa_pkcs1_oaep_padding is used and byte_size(N) if rsa_no_padding + is used.

- term_to_ec_key(ECKeyTerm) -> ECKey + rsa_private_decrypt(ChipherText, PrivateKey, Padding) -> PlainText + Decrypts ChipherText using the private Key. - ECKeyTerm = EC key as Erlang term - ECKey = EC key resource() + ChipherText = binary() + PrivateKey = [E, N, D] | [E, N, D, P1, P2, E1, E2, C] + E, N, D = integer() + Where E is the public exponent, N is public modulus and + D is the private exponent. + P1, P2, E1, E2, C = integer() + 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. + Padding = rsa_pkcs1_padding | rsa_pkcs1_oaep_padding | rsa_no_padding + PlainText = binary() -

Convert a EC key an Erlang term into a NIF resource. +

Decrypts the ChipherText (usually a session key encrypted with + rsa_public_encrypt/3) + using the PrivateKey and returns the + message. The Padding is the padding mode that was + used to encrypt the data, + see rsa_public_encrypt/3.

- ecdsa_sign(DataOrDigest, ECKey) -> Signature - ecdsa_sign(DigestType, DataOrDigest, ECKey) -> Signature - Sign the data using ecdsa with the given key. - - DataOrDigest = Data | {digest,Digest} - Data = Mpint - Digest = binary() - ECKey = EC key resource() - DigestType = md5 | sha | sha256 | sha384 | sha512 - The default DigestType is sha. - Mpint = binary() - Signature = binary() - - -

Creates a ESDSA signature with the private key Key - of a digest. The digest is either calculated as a - DigestType digest of Data or a precalculated - binary Digest.

-
-
- - - ecdsa_verify(DataOrDigest, Signature, ECKey) -> Verified - ecdsa_verify(DigestType, DataOrDigest, Signature, ECKey) -> Verified - Verify the digest and signature using ecdsa with given public key. - - Verified = boolean() - DataOrDigest = Data | {digest|Digest} - Data, Signature = Mpint - Digest = binary() - ECKey = EC key resource() - DigestType = md5 | sha | sha256 | sha384 | sha512 - The default DigestType is sha. - Mpint = binary() - - -

Verifies that a digest matches the ECDSA signature using the - signer's public key Key. - The digest is either calculated as a DigestType - digest of Data or a precalculated binary Digest.

-

May throw exception notsup in case the chosen DigestType - is not supported by the underlying OpenSSL implementation.

-
-
- - - ecdh_compute_key(OthersPublicKey, MyPrivateKey) -> SharedSecret - ecdh_compute_key(OthersPublicKey, MyECPoint) -> SharedSecret - Computes the shared secret + rsa_private_encrypt(PlainText, PrivateKey, Padding) -> ChipherText + Encrypts Msg using the private Key. - OthersPublicKey, MyPrivateKey = ECKey() - MyPrivatePoint = binary() - SharedSecret = binary() + PlainText = binary() + PrivateKey = [E, N, D] | [E, N, D, P1, P2, E1, E2, C] + E, N, D = integer() + Where E is the public exponent, N is public modulus and + D is the private exponent. + P1, P2, E1, E2, C = integer() + 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. + Padding = rsa_pkcs1_padding | rsa_no_padding + ChipherText = binary() -

Computes the shared secret from the private key and the other party's public key. +

Encrypts the PlainText using the PrivateKey + and returns the cipher. The Padding decides what padding mode is used, + rsa_pkcs1_padding is PKCS #1 v1.5 currently the most + used mode. + The size of the Msg must be less than byte_size(N)-11 if + rsa_pkcs1_padding is used, and byte_size(N) if rsa_no_padding + is used.

- - exor(Data1, Data2) -> Result - XOR data + rsa_public_decrypt(ChipherText, PublicKey, Padding) -> PlainText + Decrypts ChipherText using the public Key. - Data1, Data2 = iolist() | binary() - Result = binary() + ChipherText = binary() + PublicKey = [E, N] + E, N = integer() + Where E is the public exponent and N is public modulus + Padding = rsa_pkcs1_padding | rsa_no_padding + PlainText = binary() -

Performs bit-wise XOR (exclusive or) on the data supplied.

+

Decrypts the ChipherText (encrypted with + rsa_private_encrypt/3) + using the PrivateKey and returns the + message. The Padding is the padding mode that was + used to encrypt the data, + see rsa_private_encrypt/3. +

-
- -
- Elliptic Curve Key -

Elliptic Curve keys consist of the curve paramters and a the - private and public keys (points on the curve). Translating the - raw curve paraters into something usable for the underlying - OpenSSL implementation is a complicated process. The main cryptografic - functions therefore expect a NIF resource as input that contains the - key in an internal format. Two functions ec_key_to_term/1 - and term_to_ec_key are provided to convert between Erlang - terms and the resource format

-

Key in term form

-
-ec_named_curve() = atom()
-ec_point() = binary()
-ec_basis() = {tpbasis, K :: non_neg_integer()} | {ppbasis, K1 :: non_neg_integer(), K2 :: non_neg_integer(), K3 :: non_neg_integer()} | onbasis
-ec_field() = {prime_field, Prime :: Mpint()} | {characteristic_two_field, M :: integer(), Basis :: ec_basis()}
-ec_prime() = {A :: Mpint(), B :: Mpint(), Seed :: binary()}
-ec_curve_spec() = {Field :: ec_field(), Prime :: ec_prime(), Point :: ec_point(), Order :: Mpint(), CoFactor :: none | Mpint()}
-ec_curve() = ec_named_curve() | ec_curve_spec()
-ec_key() = {Curve :: ec_curve(), PrivKey :: Mpint() | undefined, PubKey :: ec_point() | undefined}
-    
-
+
DES in CBC mode diff --git a/lib/crypto/doc/src/crypto_app.xml b/lib/crypto/doc/src/crypto_app.xml index 8371db1ff2..20f4ed5c45 100644 --- a/lib/crypto/doc/src/crypto_app.xml +++ b/lib/crypto/doc/src/crypto_app.xml @@ -1,4 +1,4 @@ - + @@ -24,23 +24,14 @@ crypto - Peter Högfeldt - Peter Högfeldt - - Peter Högfeldt - Peter Högfeldt - 2003-06-01 - B crypto_app.sgml crypto The Crypto Application -

The purpose of the Crypto application is to provide message - digest and DES encryption for SMNPv3. It provides computation of - message digests MD5 and SHA, and CBC-DES encryption and - decryption.

-

+

The purpose of the Crypto application is to provide erlang + acess to crypto graphic functions in openssl. +

@@ -68,36 +59,6 @@

Source releases of OpenSSL can be downloaded from the OpenSSL project home page, or mirror sites listed there.

-

The same URL also contains links to some compiled binaries and - libraries of OpenSSL (see the Related/Binaries menu) of - which the Shining Light Productions Win32 and OpenSSL pages are of - interest for the Win32 user. -

-

For some Unix flavours there are binary packages available - on the net. -

-

If you cannot find a suitable binary OpenSSL package, you - have to fetch an OpenSSL source release and compile it. -

-

You then have to compile and install the library - libcrypto.so (Unix), or the library libeay32.dll - (Win32). -

-

For Unix The crypto_drv dynamic driver is delivered linked - to OpenSSL libraries in /usr/local/lib, but the default - dynamic linking will also accept libraries in /lib and - /usr/lib. -

-

If that is not applicable to the particular Unix operating - system used, the example Makefile in the Crypto - priv/obj directory, should be used as a basis for - relinking the final version of the port program. -

-

For Win32 it is only required that the library can be - found from the PATH environment variable, or that they - reside in the appropriate SYSTEM32 directory; hence no - particular relinking is need. Hence no example Makefile - for Win32 is provided.

diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl index f87644b3fe..2b5ccb6ef4 100644 --- a/lib/crypto/src/crypto.erl +++ b/lib/crypto/src/crypto.erl @@ -23,19 +23,13 @@ -export([start/0, stop/0, info/0, info_lib/0, algorithms/0, version/0]). -export([hash/2, hash_init/1, hash_update/2, hash_final/1]). --export([md4/1, md4_init/0, md4_update/2, md4_final/1]). --export([md5/1, md5_init/0, md5_update/2, md5_final/1]). --export([sha/1, sha_init/0, sha_update/2, sha_final/1]). --export([sha224/1, sha224_init/0, sha224_update/2, sha224_final/1]). --export([sha256/1, sha256_init/0, sha256_update/2, sha256_final/1]). --export([sha384/1, sha384_init/0, sha384_update/2, sha384_final/1]). --export([sha512/1, sha512_init/0, sha512_update/2, sha512_final/1]). --export([md5_mac/2, md5_mac_96/2, sha_mac/2, sha_mac/3, sha_mac_96/2]). --export([sha224_mac/2, sha224_mac/3]). --export([sha256_mac/2, sha256_mac/3]). --export([sha384_mac/2, sha384_mac/3]). --export([sha512_mac/2, sha512_mac/3]). +-export([sign/4, verify/5]). +-export([generate_key/2, generate_key/3, compute_key/4]). -export([hmac/3, hmac/4, hmac_init/2, hmac_update/2, hmac_final/1, hmac_final_n/2]). +-export([exor/2]). +-export([strong_rand_bytes/1, mod_exp_prime/3]). +-export([rand_bytes/1, rand_bytes/3, rand_uniform/2]). + -export([des_cbc_encrypt/3, des_cbc_decrypt/3, des_cbc_ivec/1]). -export([des_ecb_encrypt/2, des_ecb_decrypt/2]). -export([des_cfb_encrypt/3, des_cfb_decrypt/3, des_cfb_ivec/2]). @@ -47,41 +41,69 @@ -export([blowfish_ofb64_encrypt/3]). -export([des_ede3_cbc_encrypt/5, des_ede3_cbc_decrypt/5]). -export([aes_cfb_128_encrypt/3, aes_cfb_128_decrypt/3]). --export([exor/2]). -export([rc4_encrypt/2, rc4_set_key/1, rc4_encrypt_with_state/2]). -export([rc2_cbc_encrypt/3, rc2_cbc_decrypt/3, rc2_40_cbc_encrypt/3, rc2_40_cbc_decrypt/3]). --export([dss_verify/3, dss_verify/4, rsa_verify/3, rsa_verify/4]). --export([dss_sign/2, dss_sign/3, rsa_sign/2, rsa_sign/3]). -export([rsa_public_encrypt/3, rsa_private_decrypt/3]). -export([rsa_private_encrypt/3, rsa_public_decrypt/3]). --export([dh_generate_key/1, dh_generate_key/2, dh_compute_key/3]). --export([rand_bytes/1, rand_bytes/3, rand_uniform/2]). --export([strong_rand_bytes/1, strong_rand_mpint/3]). --export([mod_exp/3, mod_exp_prime/3, mpint/1, erlint/1]). - -%% -export([idea_cbc_encrypt/3, idea_cbc_decrypt/3]). -export([aes_cbc_128_encrypt/3, aes_cbc_128_decrypt/3]). -export([aes_cbc_256_encrypt/3, aes_cbc_256_decrypt/3]). -export([aes_cbc_ivec/1]). -export([aes_ctr_encrypt/3, aes_ctr_decrypt/3]). -export([aes_ctr_stream_init/2, aes_ctr_stream_encrypt/2, aes_ctr_stream_decrypt/2]). --export([sign/4, verify/5]). --export([generate_key/2, generate_key/3, compute_key/4]). +-export([dh_generate_parameters/2, dh_check/1]). %% Testing see + +%% DEPRECATED +-export([md4/1, md4_init/0, md4_update/2, md4_final/1]). +-export([md5/1, md5_init/0, md5_update/2, md5_final/1]). +-export([sha/1, sha_init/0, sha_update/2, sha_final/1]). +-deprecated({md4, 1, next_major_release}). +-deprecated({md5, 1, next_major_release}). +-deprecated({sha, 1, next_major_release}). +-deprecated({md4_init, 0, next_major_release}). +-deprecated({md5_init, 0, next_major_release}). +-deprecated({sha_init, 0, next_major_release}). +-deprecated({md4_update, 2, next_major_release}). +-deprecated({md5_update, 2, next_major_release}). +-deprecated({sha_update, 2, next_major_release}). +-deprecated({md4_final, 1, next_major_release}). +-deprecated({md5_final, 1, next_major_release}). +-deprecated({sha_final, 1, next_major_release}). + +-export([md5_mac/2, md5_mac_96/2, sha_mac/2, sha_mac/3, sha_mac_96/2]). +-deprecated({md5_mac, 2, next_major_release}). +-deprecated({md5_mac_96, 2, next_major_release}). +-deprecated({sha_mac, 2, next_major_release}). +-deprecated({sha_mac, 3, next_major_release}). +-deprecated({sha_mac_96, 2, next_major_release}). --export([dh_generate_parameters/2, dh_check/1]). %% Testing see below +-export([dss_verify/3, dss_verify/4, rsa_verify/3, rsa_verify/4]). +-export([dss_sign/2, dss_sign/3, rsa_sign/2, rsa_sign/3]). +-deprecated({dss_verify, 3, next_major_release}). +-deprecated({dss_verify, 4, next_major_release}). +-deprecated({rsa_verify, 3, next_major_release}). +-deprecated({rsa_verify, 4, next_major_release}). +-deprecated({dss_sign, 2, next_major_release}). +-deprecated({dss_sign, 3, next_major_release}). +-deprecated({rsa_sign, 2, next_major_release}). +-deprecated({rsa_sign, 3, next_major_release}). +-export([dh_generate_key/1, dh_generate_key/2, dh_compute_key/3]). +-deprecated({dh_generate_key, 1, next_major_release}). +-deprecated({dh_generate_key, 2, next_major_release}). +-deprecated({dh_compute_key, 3, next_major_release}). + +-export([mod_exp/3, mpint/1, erlint/1, strong_rand_mpint/3]). +-deprecated({mod_exp, 3, next_major_release}). +-deprecated({mpint, 1, next_major_release}). +-deprecated({erlint, 1, next_major_release}). +-deprecated({strong_rand_mpint, 3, next_major_release}). -define(FUNC_LIST, [md4, md4_init, md4_update, md4_final, md5, md5_init, md5_update, md5_final, sha, sha_init, sha_update, sha_final, - sha224, sha224_init, sha224_update, sha224_final, - sha256, sha256_init, sha256_update, sha256_final, - sha384, sha384_init, sha384_update, sha384_final, - sha512, sha512_init, sha512_update, sha512_final, md5_mac, md5_mac_96, sha_mac, sha_mac_96, - sha224_mac, sha256_mac, sha384_mac, sha512_mac, des_cbc_encrypt, des_cbc_decrypt, des_cfb_encrypt, des_cfb_decrypt, des_ecb_encrypt, des_ecb_decrypt, @@ -102,7 +124,6 @@ exor, rc4_encrypt, rc4_set_key, rc4_encrypt_with_state, rc2_40_cbc_encrypt, rc2_40_cbc_decrypt, - %% idea_cbc_encrypt, idea_cbc_decrypt, aes_cbc_256_encrypt, aes_cbc_256_decrypt, aes_ctr_encrypt, aes_ctr_decrypt, aes_ctr_stream_init, aes_ctr_stream_encrypt, aes_ctr_stream_decrypt, @@ -124,13 +145,13 @@ -type crypto_integer() :: binary() | integer(). -type ec_key_res() :: any(). %% nif resource -type ec_named_curve() :: atom(). --type ec_point() :: binary(). +-type ec_point() :: crypto_integer(). -type ec_basis() :: {tpbasis, K :: non_neg_integer()} | {ppbasis, K1 :: non_neg_integer(), K2 :: non_neg_integer(), K3 :: non_neg_integer()} | onbasis. --type ec_field() :: {prime_field, Prime :: mpint()} | {characteristic_two_field, M :: integer(), Basis :: ec_basis()}. --type ec_prime() :: {A :: mpint(), B :: mpint(), Seed :: binary()}. --type ec_curve_spec() :: {Field :: ec_field(), Prime :: ec_prime(), Point :: ec_point(), Order :: mpint(), CoFactor :: none | mpint()}. +-type ec_field() :: {prime_field, Prime :: integer()} | {characteristic_two_field, M :: integer(), Basis :: ec_basis()}. +-type ec_prime() :: {A :: crypto_integer(), B :: crypto_integer(), Seed :: binary() | none}. +-type ec_curve_spec() :: {Field :: ec_field(), Prime :: ec_prime(), Point :: crypto_integer(), Order :: integer(), CoFactor :: none | integer()}. -type ec_curve() :: ec_named_curve() | ec_curve_spec(). --type ec_key() :: {Curve :: ec_curve(), PrivKey :: mpint() | undefined, PubKey :: ec_point() | undefined}. +-type ec_key() :: {Curve :: ec_curve(), PrivKey :: binary() | undefined, PubKey :: ec_point() | undefined}. -define(nif_stub,nif_stub_error(?LINE)). @@ -944,11 +965,11 @@ ecdsa_sign_nif(_Type, _DataOrDigest, _Key) -> ?nif_stub. -spec rsa_public_encrypt(binary(), [binary()], rsa_padding()) -> binary(). --spec rsa_public_decrypt(binary(), [binary()], rsa_padding()) -> +-spec rsa_public_decrypt(binary(), [integer() | mpint()], rsa_padding()) -> binary(). --spec rsa_private_encrypt(binary(), [binary()], rsa_padding()) -> +-spec rsa_private_encrypt(binary(), [integer() | mpint()], rsa_padding()) -> binary(). --spec rsa_private_decrypt(binary(), [binary()], rsa_padding()) -> +-spec rsa_private_decrypt(binary(), [integer() | mpint()], rsa_padding()) -> binary(). %% Binary, Key = [E,N] @@ -1216,8 +1237,6 @@ ecdh_compute_key_nif(_Others, _My) -> ?nif_stub. %% %% EC %% - --spec ec_key_to_term(ec_key_res()) -> ec_key(). ec_key_to_term(Key) -> case ec_key_to_term_nif(Key) of {PrivKey, PubKey} -> diff --git a/lib/crypto/test/crypto_SUITE.erl b/lib/crypto/test/crypto_SUITE.erl index 3ebe10866c..eff0f8a878 100644 --- a/lib/crypto/test/crypto_SUITE.erl +++ b/lib/crypto/test/crypto_SUITE.erl @@ -360,7 +360,7 @@ hmac_update_sha(Config) when is_list(Config) -> ?line Ctx2 = crypto:hmac_update(Ctx, Data), ?line Ctx3 = crypto:hmac_update(Ctx2, Data2), ?line Mac = crypto:hmac_final(Ctx3), - ?line Exp = crypto:sha_mac(Key, lists:flatten([Data, Data2])), + ?line Exp = crypto:hmac(sha, Key, lists:flatten([Data, Data2])), ?line m(Exp, Mac). hmac_update_sha256(doc) -> @@ -382,7 +382,7 @@ hmac_update_sha256_do() -> ?line Ctx2 = crypto:hmac_update(Ctx, Data), ?line Ctx3 = crypto:hmac_update(Ctx2, Data2), ?line Mac = crypto:hmac_final(Ctx3), - ?line Exp = crypto:sha256_mac(Key, lists:flatten([Data, Data2])), + ?line Exp = crypto:hmac(sha256, Key, lists:flatten([Data, Data2])), ?line m(Exp, Mac). hmac_update_sha512(doc) -> @@ -404,7 +404,7 @@ hmac_update_sha512_do() -> ?line Ctx2 = crypto:hmac_update(Ctx, Data), ?line Ctx3 = crypto:hmac_update(Ctx2, Data2), ?line Mac = crypto:hmac_final(Ctx3), - ?line Exp = crypto:sha512_mac(Key, lists:flatten([Data, Data2])), + ?line Exp = crypto:hmac(sha512, Key, lists:flatten([Data, Data2])), ?line m(Exp, Mac). hmac_update_md5(doc) -> @@ -619,68 +619,64 @@ hmac_rfc4231_sha512(suite) -> hmac_rfc4231_sha512(Config) when is_list(Config) -> if_supported(sha512, fun() -> hmac_rfc4231_sha512_do() end). -hmac_rfc4231_case(Hash, HashFun, case1, Exp) -> +hmac_rfc4231_case(Hash, case1, Exp) -> %% Test 1 Key = binary:copy(<<16#0b>>, 20), Data = <<"Hi There">>, - hmac_rfc4231_case(Hash, HashFun, Key, Data, Exp); + hmac_rfc4231_case(Hash, Key, Data, Exp); -hmac_rfc4231_case(Hash, HashFun, case2, Exp) -> +hmac_rfc4231_case(Hash, case2, Exp) -> %% Test 2 Key = <<"Jefe">>, Data = <<"what do ya want for nothing?">>, - hmac_rfc4231_case(Hash, HashFun, Key, Data, Exp); + hmac_rfc4231_case(Hash, Key, Data, Exp); -hmac_rfc4231_case(Hash, HashFun, case3, Exp) -> +hmac_rfc4231_case(Hash, case3, Exp) -> %% Test 3 Key = binary:copy(<<16#aa>>, 20), Data = binary:copy(<<16#dd>>, 50), - hmac_rfc4231_case(Hash, HashFun, Key, Data, Exp); + hmac_rfc4231_case(Hash, Key, Data, Exp); -hmac_rfc4231_case(Hash, HashFun, case4, Exp) -> +hmac_rfc4231_case(Hash, case4, Exp) -> %% Test 4 Key = list_to_binary(lists:seq(1, 16#19)), Data = binary:copy(<<16#cd>>, 50), - hmac_rfc4231_case(Hash, HashFun, Key, Data, Exp); + hmac_rfc4231_case(Hash, Key, Data, Exp); -hmac_rfc4231_case(Hash, HashFun, case5, Exp) -> +hmac_rfc4231_case(Hash, case5, Exp) -> %% Test 5 Key = binary:copy(<<16#0c>>, 20), Data = <<"Test With Truncation">>, - hmac_rfc4231_case(Hash, HashFun, Key, Data, 16, Exp); + hmac_rfc4231_case(Hash, Key, Data, 16, Exp); -hmac_rfc4231_case(Hash, HashFun, case6, Exp) -> +hmac_rfc4231_case(Hash, case6, Exp) -> %% Test 6 Key = binary:copy(<<16#aa>>, 131), Data = <<"Test Using Larger Than Block-Size Key - Hash Key First">>, - hmac_rfc4231_case(Hash, HashFun, Key, Data, Exp); + hmac_rfc4231_case(Hash, Key, Data, Exp); -hmac_rfc4231_case(Hash, HashFun, case7, Exp) -> +hmac_rfc4231_case(Hash, case7, Exp) -> %% Test Case 7 Key = binary:copy(<<16#aa>>, 131), Data = <<"This is a test using a larger than block-size key and a larger t", "han block-size data. The key needs to be hashed before being use", "d by the HMAC algorithm.">>, - hmac_rfc4231_case(Hash, HashFun, Key, Data, Exp). + hmac_rfc4231_case(Hash, Key, Data, Exp). -hmac_rfc4231_case(Hash, HashFun, Key, Data, Exp) -> +hmac_rfc4231_case(Hash, Key, Data, Exp) -> ?line Ctx = crypto:hmac_init(Hash, Key), ?line Ctx2 = crypto:hmac_update(Ctx, Data), ?line Mac1 = crypto:hmac_final(Ctx2), - ?line Mac2 = crypto:HashFun(Key, Data), ?line Mac3 = crypto:hmac(Hash, Key, Data), ?line m(Exp, Mac1), - ?line m(Exp, Mac2), ?line m(Exp, Mac3). -hmac_rfc4231_case(Hash, HashFun, Key, Data, Trunc, Exp) -> +hmac_rfc4231_case(Hash, Key, Data, Trunc, Exp) -> ?line Ctx = crypto:hmac_init(Hash, Key), ?line Ctx2 = crypto:hmac_update(Ctx, Data), ?line Mac1 = crypto:hmac_final_n(Ctx2, Trunc), - ?line Mac2 = crypto:HashFun(Key, Data, Trunc), ?line Mac3 = crypto:hmac(Hash, Key, Data, Trunc), ?line m(Exp, Mac1), - ?line m(Exp, Mac2), ?line m(Exp, Mac3). hmac_rfc4231_sha224_do() -> @@ -697,7 +693,7 @@ hmac_rfc4231_sha224_do() -> "d499f112f2d2b7273fa6870e"), Case7 = hexstr2bin("3a854166ac5d9f023f54d517d0b39dbd" "946770db9c2b95c9f6f565d1"), - hmac_rfc4231_cases_do(sha224, sha224_mac, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). + hmac_rfc4231_cases_do(sha224, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). hmac_rfc4231_sha256_do() -> Case1 = hexstr2bin("b0344c61d8db38535ca8afceaf0bf12b" @@ -713,7 +709,7 @@ hmac_rfc4231_sha256_do() -> "8e0bc6213728c5140546040f0ee37f54"), Case7 = hexstr2bin("9b09ffa71b942fcb27635fbcd5b0e944" "bfdc63644f0713938a7f51535c3a35e2"), - hmac_rfc4231_cases_do(sha256, sha256_mac, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). + hmac_rfc4231_cases_do(sha256, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). hmac_rfc4231_sha384_do() -> Case1 = hexstr2bin("afd03944d84895626b0825f4ab46907f" @@ -735,7 +731,7 @@ hmac_rfc4231_sha384_do() -> Case7 = hexstr2bin("6617178e941f020d351e2f254e8fd32c" "602420feb0b8fb9adccebb82461e99c5" "a678cc31e799176d3860e6110c46523e"), - hmac_rfc4231_cases_do(sha384, sha384_mac, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). + hmac_rfc4231_cases_do(sha384, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). hmac_rfc4231_sha512_do() -> Case1 = hexstr2bin("87aa7cdea5ef619d4ff0b4241a1d6cb0" @@ -763,16 +759,16 @@ hmac_rfc4231_sha512_do() -> "debd71f8867289865df5a32d20cdc944" "b6022cac3c4982b10d5eeb55c3e4de15" "134676fb6de0446065c97440fa8c6a58"), - hmac_rfc4231_cases_do(sha512, sha512_mac, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). + hmac_rfc4231_cases_do(sha512, [Case1, Case2, Case3, Case4, Case5, Case6, Case7]). -hmac_rfc4231_cases_do(Hash, HashFun, CasesData) -> - hmac_rfc4231_cases_do(Hash, HashFun, [case1, case2, case3, case4, case5, case6, case7], CasesData). +hmac_rfc4231_cases_do(Hash, CasesData) -> + hmac_rfc4231_cases_do(Hash, [case1, case2, case3, case4, case5, case6, case7], CasesData). -hmac_rfc4231_cases_do(_Hash, _HashFun, _, []) -> +hmac_rfc4231_cases_do(_Hash, _, []) -> ok; -hmac_rfc4231_cases_do(Hash, HashFun, [C|Cases], [D|CasesData]) -> - hmac_rfc4231_case(Hash, HashFun, C, D), - hmac_rfc4231_cases_do(Hash, HashFun, Cases, CasesData). +hmac_rfc4231_cases_do(Hash, [C|Cases], [D|CasesData]) -> + hmac_rfc4231_case(Hash, C, D), + hmac_rfc4231_cases_do(Hash, Cases, CasesData). hmac_update_md5_io(doc) -> ["Generate an MD5 HMAC using hmac_init, hmac_update, and hmac_final. " @@ -859,10 +855,10 @@ sha256(Config) when is_list(Config) -> if_supported(sha256, fun() -> sha256_do() end). sha256_do() -> - ?line m(crypto:sha256("abc"), + ?line m(crypto:hash(sha256, "abc"), hexstr2bin("BA7816BF8F01CFEA4141" "40DE5DAE2223B00361A396177A9CB410FF61F20015AD")), - ?line m(crypto:sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklm" + ?line m(crypto:hash(sha256, "abcdbcdecdefdefgefghfghighijhijkijkljklmklm" "nlmnomnopnopq"), hexstr2bin("248D6A61D20638B8" "E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1")). @@ -878,10 +874,10 @@ sha256_update(Config) when is_list(Config) -> if_supported(sha256, fun() -> sha256_update_do() end). sha256_update_do() -> - ?line Ctx = crypto:sha256_init(), - ?line Ctx1 = crypto:sha256_update(Ctx, "abcdbcdecdefdefgefghfghighi"), - ?line Ctx2 = crypto:sha256_update(Ctx1, "jhijkijkljklmklmnlmnomnopnopq"), - ?line m(crypto:sha256_final(Ctx2), + ?line Ctx = crypto:hash_init(sha256), + ?line Ctx1 = crypto:hash_update(Ctx, "abcdbcdecdefdefgefghfghighi"), + ?line Ctx2 = crypto:hash_update(Ctx1, "jhijkijkljklmklmnlmnomnopnopq"), + ?line m(crypto:hash_final(Ctx2), hexstr2bin("248D6A61D20638B8" "E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1")). @@ -897,11 +893,11 @@ sha512(Config) when is_list(Config) -> if_supported(sha512, fun() -> sha512_do() end). sha512_do() -> - ?line m(crypto:sha512("abc"), + ?line m(crypto:hash(sha512, "abc"), hexstr2bin("DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA2" "0A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD" "454D4423643CE80E2A9AC94FA54CA49F")), - ?line m(crypto:sha512("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + ?line m(crypto:hash(sha512, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"), hexstr2bin("8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7FA1" "7299AEADB6889018501D289E4900F7E4331B99DEC4B5433A" @@ -918,10 +914,10 @@ sha512_update(Config) when is_list(Config) -> if_supported(sha512, fun() -> sha512_update_do() end). sha512_update_do() -> - ?line Ctx = crypto:sha512_init(), - ?line Ctx1 = crypto:sha512_update(Ctx, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"), - ?line Ctx2 = crypto:sha512_update(Ctx1, "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"), - ?line m(crypto:sha512_final(Ctx2), + ?line Ctx = crypto:hash_init(sha512), + ?line Ctx1 = crypto:hash_update(Ctx, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"), + ?line Ctx2 = crypto:hash_update(Ctx1, "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"), + ?line m(crypto:hash_final(Ctx2), hexstr2bin("8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7FA1" "7299AEADB6889018501D289E4900F7E4331B99DEC4B5433A" "C7D329EEB6DD26545E96E55B874BE909")). -- cgit v1.2.3