summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto-sources.mk2
-rw-r--r--src/crypto/cipher/cipher_test.cc2
-rw-r--r--src/crypto/cipher/e_des.c24
-rw-r--r--src/crypto/cipher/test/cipher_test.txt37
-rw-r--r--src/include/openssl/cipher.h1
5 files changed, 65 insertions, 1 deletions
diff --git a/crypto-sources.mk b/crypto-sources.mk
index 78194f2..6583ff2 100644
--- a/crypto-sources.mk
+++ b/crypto-sources.mk
@@ -1,7 +1,7 @@
LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/sources.mk
include $(LOCAL_PATH)/sources.mk
-LOCAL_CFLAGS += -I$(LOCAL_PATH)/src/include -I$(LOCAL_PATH)/src/crypto -Wno-unused-parameter
+LOCAL_CFLAGS += -I$(LOCAL_PATH)/src/include -I$(LOCAL_PATH)/src/crypto -Wno-unused-parameter -std=gnu11
# Do not add in the architecture-specific files if we don't want to build assembly
ifeq (,$(filter -DOPENSSL_NO_ASM,$(LOCAL_CFLAGS)))
LOCAL_SRC_FILES_x86 = $(linux_x86_sources)
diff --git a/src/crypto/cipher/cipher_test.cc b/src/crypto/cipher/cipher_test.cc
index 97a84e0..35bb82f 100644
--- a/src/crypto/cipher/cipher_test.cc
+++ b/src/crypto/cipher/cipher_test.cc
@@ -69,6 +69,8 @@
static const EVP_CIPHER *GetCipher(const std::string &name) {
if (name == "DES-CBC") {
return EVP_des_cbc();
+ } else if (name == "DES-ECB") {
+ return EVP_des_ecb();
} else if (name == "DES-EDE3-CBC") {
return EVP_des_ede3_cbc();
} else if (name == "RC4") {
diff --git a/src/crypto/cipher/e_des.c b/src/crypto/cipher/e_des.c
index 74e1fce..d7bef92 100644
--- a/src/crypto/cipher/e_des.c
+++ b/src/crypto/cipher/e_des.c
@@ -96,6 +96,30 @@ static const EVP_CIPHER des_cbc = {
const EVP_CIPHER *EVP_des_cbc(void) { return &des_cbc; }
+static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
+ size_t in_len) {
+ if (in_len < ctx->cipher->block_size) {
+ return 1;
+ }
+ in_len -= ctx->cipher->block_size;
+
+ EVP_DES_KEY *dat = (EVP_DES_KEY *) ctx->cipher_data;
+ for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
+ DES_ecb_encrypt((DES_cblock *) (in + i), (DES_cblock *) (out + i),
+ &dat->ks.ks, ctx->encrypt);
+ }
+ return 1;
+}
+
+static const EVP_CIPHER des_ecb = {
+ NID_des_ecb, 8 /* block_size */, 8 /* key_size */,
+ 0 /* iv_len */, sizeof(EVP_DES_KEY), EVP_CIPH_ECB_MODE,
+ NULL /* app_data */, des_init_key, des_ecb_cipher,
+ NULL /* cleanup */, NULL /* ctrl */, };
+
+const EVP_CIPHER *EVP_des_ecb(void) { return &des_ecb; }
+
+
typedef struct {
union {
double align;
diff --git a/src/crypto/cipher/test/cipher_test.txt b/src/crypto/cipher/test/cipher_test.txt
index 93cb8f3..88d4147 100644
--- a/src/crypto/cipher/test/cipher_test.txt
+++ b/src/crypto/cipher/test/cipher_test.txt
@@ -535,3 +535,40 @@ Cipher = AES-192-ECB
Key = 8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B
Plaintext = F69F2445DF4F9B17AD2B417BE66C3710
Ciphertext = 9A4B41BA738D6C72FB16691603C18E0E
+
+# DES ECB tests
+
+Cipher = DES-ECB
+Key = 0000000000000000
+Plaintext = 0000000000000000
+Ciphertext = 8CA64DE9C1B123A7
+
+Cipher = DES-ECB
+Key = FFFFFFFFFFFFFFFF
+Plaintext = FFFFFFFFFFFFFFFF
+Ciphertext = 7359B2163E4EDC58
+
+Cipher = DES-ECB
+Key = 3000000000000000
+Plaintext = 1000000000000001
+Ciphertext = 958E6E627A05557B
+
+Cipher = DES-ECB
+Key = 1111111111111111
+Plaintext = 1111111111111111
+Ciphertext = F40379AB9E0EC533
+
+Cipher = DES-ECB
+Key = 0123456789ABCDEF
+Plaintext = 1111111111111111
+Ciphertext = 17668DFC7292532D
+
+Cipher = DES-ECB
+Key = 1111111111111111
+Plaintext = 0123456789ABCDEF
+Ciphertext = 8A5AE1F81AB8F2DD
+
+Cipher = DES-ECB
+Key = FEDCBA9876543210
+Plaintext = 0123456789ABCDEF
+Ciphertext = ED39D950FA74BCC4
diff --git a/src/include/openssl/cipher.h b/src/include/openssl/cipher.h
index 7f5fe04..3e496f1 100644
--- a/src/include/openssl/cipher.h
+++ b/src/include/openssl/cipher.h
@@ -75,6 +75,7 @@ extern "C" {
OPENSSL_EXPORT const EVP_CIPHER *EVP_rc4(void);
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_ede3_cbc(void);
OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_128_ecb(void);