Add support for 3DES-ECB.

Change-Id: I9f7f1dd609c38d1f4be536daff94a4ba002582d0
Reviewed-on: https://boringssl-review.googlesource.com/14888
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/cipher/cipher_test.cc b/crypto/cipher/cipher_test.cc
index 09802c2..04fa2d1 100644
--- a/crypto/cipher/cipher_test.cc
+++ b/crypto/cipher/cipher_test.cc
@@ -71,6 +71,8 @@
     return EVP_des_ecb();
   } else if (name == "DES-EDE") {
     return EVP_des_ede();
+  } else if (name == "DES-EDE3") {
+    return EVP_des_ede3();
   } else if (name == "DES-EDE-CBC") {
     return EVP_des_ede_cbc();
   } else if (name == "DES-EDE3-CBC") {
diff --git a/crypto/cipher/e_des.c b/crypto/cipher/e_des.c
index 6834a42..e72f003 100644
--- a/crypto/cipher/e_des.c
+++ b/crypto/cipher/e_des.c
@@ -203,3 +203,13 @@
     NULL /* cleanup */,  NULL /* ctrl */, };
 
 const EVP_CIPHER *EVP_des_ede(void) { return &des_ede_ecb; }
+
+
+static const EVP_CIPHER des_ede3_ecb = {
+    NID_des_ede3_cbc,    8 /* block_size */,  24 /* key_size */,
+    0 /* iv_len */,      sizeof(DES_EDE_KEY), EVP_CIPH_ECB_MODE,
+    NULL /* app_data */, des_ede3_init_key,   des_ede_ecb_cipher,
+    NULL /* cleanup */,  NULL /* ctrl */,
+};
+
+const EVP_CIPHER *EVP_des_ede3(void) { return &des_ede3_ecb; }
diff --git a/crypto/cipher/test/cipher_tests.txt b/crypto/cipher/test/cipher_tests.txt
index e75e664..8bffdf9 100644
--- a/crypto/cipher/test/cipher_tests.txt
+++ b/crypto/cipher/test/cipher_tests.txt
@@ -30,6 +30,58 @@
 Ciphertext = d6a141a7ec3c38dfbd61
 
 
+# DES EDE3 ECB tests
+Cipher = DES-EDE3
+Key = 2eaf97304cfaeb822c04a7b7bef328c7b82fef2ae81b06b5
+Plaintext = b3ed255d4f5e2d6d9a1aa2bc03489064d28fe1431eceee183b7231fad3273140
+Ciphertext = 629d608789e51dff699343d061ec01d94c0681c7698ab617ea0145f37304c8e2
+
+Cipher = DES-EDE3
+Key = 72f52e1ded0a88eac6c88d2901b27c2fd6e9f3f3387432ee
+Plaintext = 60de7b5667a1ad5995f178553d695d9b0fb537562876faa9b6cc50d05a1271ac
+Ciphertext = 09875b215ed2499318c2d99c48209ca5f288830cc6edb9538190fa3ca31fa175
+
+Cipher = DES-EDE3
+Key = 4cd30f1e14d485dbc05c69b65ebf44e556056a2261c9e714
+Plaintext = 7ae59441bbd665d8867273386fc72a8cd62cc5bc6bb7cbd57fc1f5dcdc73adfd
+Ciphertext = 004d0daad970bfee944c8779927867b964dd0afaae7a830c2b8e7fdcaeac2158
+
+Cipher = DES-EDE3
+Key = 7a07ac63adfaf1b26860ce39edfc402758bc4d1edda156ab
+Plaintext = ed4f18cf10bfcbd4354710df053d3e2b776860137349471b8dcf526b8eea8b22
+Ciphertext = a1fc1014abda7e198ac8e096a368f65d9b59e1eddf5d97715015a2408dd8e799
+
+Cipher = DES-EDE3
+Key = 37c443ab336fed59b0efae51ea7f5d07b7040868beefcd99
+Plaintext = a10a180cc94b75fc9d6556dfc0a816b71020dc3906f9d59d9dd4c839dfc1c1d3
+Ciphertext = 0a874652b621618635138a7d4b33bb624f91a39ef1422b3e0490311ac6df3602
+
+Cipher = DES-EDE3
+Key = 1ff1a7f4839d484e308d9b8c2c052b126def413d5fb8e0c5
+Plaintext = 4f28ef6683d36c80556ff240b247a3967aec23f859e3afb93aefad93b1e9964b
+Ciphertext = 87a8f3fb4c51b3caf19c4ac51363d92025acc053e538c1502d347a618314a4bd
+
+Cipher = DES-EDE3
+Key = 5642c4d1859a85b342e3f253fd8bd835e856c451e63673e5
+Plaintext = 687af9b298db752b47982f64ad9bff52a9ae487aa5e5c08f902035b0633225bf
+Ciphertext = ca2ed48392ba5d70879ac8772180c3028ef946b6ac1df0348f206ce16bc449bd
+
+Cipher = DES-EDE3
+Key = 30f9d27472f9deee309dbca76ba29ca174c39d0631084735
+Plaintext = 85db2c266902932c8e46d0207459b203f90955adcd7506b49bc82e2796de764f
+Ciphertext = bbb5940b45add7c587cc9fcfc40674bac7e081baf71285891c65ed9573947a07
+
+Cipher = DES-EDE3
+Key = ebc5a73005b77a812c3f4f61669ba859939852580fa61cbc
+Plaintext = 808d22c60b883a986dcb0860e8d92a75441cca0a2a4b06dd78dbcbec198b38d9
+Ciphertext = 75d39d30862431ab07227e22b4c8218f1fbc2a3816daebc555c1b999c86d15c9
+
+Cipher = DES-EDE3
+Key = 2e8eb05dd8a2b7a5a61a6b8a3830b12da2c4b1bea1e884d5
+Plaintext = cc7569d005afd1a365f5c5836c14475fc15091199902af4a78460d56c16f91ca
+Ciphertext = 64db8af7a30363051a017cc92ed67ac6c0e2e1ffda0c94bbf0eeb803ba6b3d22
+
+
 # DES EDE3 CBC tests (from destest)
 Cipher = DES-EDE3-CBC
 Key = 0123456789abcdeff1e0d3c2b5a49786fedcba9876543210
diff --git a/include/openssl/cipher.h b/include/openssl/cipher.h
index 2ee74ef..f93f4cb 100644
--- a/include/openssl/cipher.h
+++ b/include/openssl/cipher.h
@@ -77,6 +77,7 @@
 OPENSSL_EXPORT const EVP_CIPHER *EVP_des_cbc(void);
 OPENSSL_EXPORT const EVP_CIPHER *EVP_des_ecb(void);
 OPENSSL_EXPORT const EVP_CIPHER *EVP_des_ede(void);
+OPENSSL_EXPORT const EVP_CIPHER *EVP_des_ede3(void);
 OPENSSL_EXPORT const EVP_CIPHER *EVP_des_ede_cbc(void);
 OPENSSL_EXPORT const EVP_CIPHER *EVP_des_ede3_cbc(void);