From 704453fa9c2b62cafe2e5455bf2f0147d5f7230b Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Tue, 23 Sep 2014 16:19:16 -0700 Subject: [PATCH] Add deprecated functions for tcpdump. This reduces the delta for getting Android to compile and avoids having Android carry around diffs to upstream versions of tcpdump. Change-Id: I7f4cbb22b7a0f246bbebe960ca2139f0f42e14a0 Reviewed-on: https://boringssl-review.googlesource.com/1830 Reviewed-by: Adam Langley --- crypto/cipher/cipher.c | 58 +++++++++++++++++++++++++++++++++------- include/openssl/cipher.h | 26 ++++++++++++++++++ 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/crypto/cipher/cipher.c b/crypto/cipher/cipher.c index cdb8f436..fd613a63 100644 --- a/crypto/cipher/cipher.c +++ b/crypto/cipher/cipher.c @@ -56,8 +56,9 @@ #include -#include #include +#include +#include #include #include @@ -93,14 +94,6 @@ EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) { return ctx; } -int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, - const unsigned char *key, const unsigned char *iv, int enc) { - if (cipher) { - EVP_CIPHER_CTX_init(ctx); - } - return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); -} - int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) { if (c->cipher != NULL && c->cipher->cleanup && !c->cipher->cleanup(c)) { return 0; @@ -613,3 +606,50 @@ uint32_t EVP_CIPHER_flags(const EVP_CIPHER *cipher) { uint32_t EVP_CIPHER_mode(const EVP_CIPHER *cipher) { return cipher->flags & EVP_CIPH_MODE_MASK; } + +int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const uint8_t *key, const uint8_t *iv, int enc) { + if (cipher) { + EVP_CIPHER_CTX_init(ctx); + } + return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); +} + +int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const uint8_t *key, const uint8_t *iv) { + return EVP_CipherInit(ctx, cipher, key, iv, 1); +} + +int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const uint8_t *key, const uint8_t *iv) { + return EVP_CipherInit(ctx, cipher, key, iv, 0); +} + +int EVP_add_cipher_alias(const char *a, const char *b) { + return 1; +} + +const EVP_CIPHER *EVP_get_cipherbyname(const char *name) { + if (strcasecmp(name, "rc4") == 0) { + return EVP_rc4(); + } else if (strcasecmp(name, "des-cbc") == 0) { + return EVP_des_cbc(); + } else if (strcasecmp(name, "3des-cbc") == 0 || + strcasecmp(name, "3des") == 0) { + return EVP_des_ede3_cbc(); + } else if (strcasecmp(name, "aes-128-cbc") == 0) { + return EVP_aes_128_cbc(); + } else if (strcasecmp(name, "aes-256-cbc") == 0) { + return EVP_aes_256_cbc(); + } else if (strcasecmp(name, "aes-128-ctr") == 0) { + return EVP_aes_128_ctr(); + } else if (strcasecmp(name, "aes-256-ctr") == 0) { + return EVP_aes_256_ctr(); + } else if (strcasecmp(name, "aes-128-ecb") == 0) { + return EVP_aes_128_ecb(); + } else if (strcasecmp(name, "aes-256-ecb") == 0) { + return EVP_aes_256_ecb(); + } + + return NULL; +} diff --git a/include/openssl/cipher.h b/include/openssl/cipher.h index 4eae33b5..021c6821 100644 --- a/include/openssl/cipher.h +++ b/include/openssl/cipher.h @@ -356,6 +356,32 @@ OPENSSL_EXPORT int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, #define EVP_CIPH_CUSTOM_COPY 0x1000 +/* Deprecated functions */ + +/* EVP_CipherInit acts like EVP_CipherInit_ex except that |EVP_CIPHER_CTX_init| + * is called on |cipher| first, if |cipher| is not NULL. */ +OPENSSL_EXPORT int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const uint8_t *key, const uint8_t *iv, + int enc); + +/* EVP_EncryptInit calls |EVP_CipherInit| with |enc| equal to one. */ +OPENSSL_EXPORT int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, const uint8_t *key, + const uint8_t *iv); + +/* EVP_DecryptInit calls |EVP_CipherInit| with |enc| equal to zero. */ +OPENSSL_EXPORT int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, const uint8_t *key, + const uint8_t *iv); + +/* EVP_add_cipher_alias does nothing and returns one. */ +OPENSSL_EXPORT int EVP_add_cipher_alias(const char *a, const char *b); + +/* EVP_get_cipherbyname returns an |EVP_CIPHER| given a human readable name in + * |name|, or NULL if the name is unknown. */ +OPENSSL_EXPORT const EVP_CIPHER *EVP_get_cipherbyname(const char *name); + + /* Private functions. */ /* EVP_CIPH_NO_PADDING disables padding in block ciphers. */