From d6e1c724e59a0b01b7ed23ba3cbfc1accdc11035 Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Wed, 21 Jul 2010 19:11:32 +0000 Subject: Remove built-in AES code and use optional_api instead Review: https://reviewboard.asterisk.org/r/793/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@278538 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/crypto.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'include/asterisk/crypto.h') diff --git a/include/asterisk/crypto.h b/include/asterisk/crypto.h index c84728618..1f87811f4 100644 --- a/include/asterisk/crypto.h +++ b/include/asterisk/crypto.h @@ -28,6 +28,16 @@ extern "C" { #endif #include "asterisk/optional_api.h" +#include "asterisk/logger.h" + +#ifdef HAVE_CRYPTO +#include "openssl/aes.h" +typedef AES_KEY ast_aes_encrypt_key; +typedef AES_KEY ast_aes_decrypt_key; +#else /* !HAVE_CRYPTO */ +typedef char ast_aes_encrypt_key; +typedef char ast_aes_decrypt_key; +#endif /* HAVE_CRYPTO */ #define AST_KEY_PUBLIC (1 << 0) #define AST_KEY_PRIVATE (1 << 1) @@ -122,6 +132,50 @@ AST_OPTIONAL_API(int, ast_encrypt_bin, (unsigned char *dst, const unsigned char */ AST_OPTIONAL_API(int, ast_decrypt_bin, (unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key), { return -1; }); +/*! + * \brief Set an encryption key + * \param key a 16 char key + * \param ctx address of an aes encryption context + * + * \retval 0 success + * \retval nonzero failure + */ +AST_OPTIONAL_API(int, ast_aes_set_encrypt_key, + (const unsigned char *key, ast_aes_encrypt_key *ctx), + { ast_log(LOG_WARNING, "AES encryption disabled. Install OpenSSL.\n"); return -1; }); + +/*! + * \brief Set a decryption key + * \param key a 16 char key + * \param ctx address of an aes encryption context + * + * \retval 0 success + * \retval nonzero failure + */ +AST_OPTIONAL_API(int, ast_aes_set_decrypt_key, + (const unsigned char *key, ast_aes_decrypt_key *ctx), + { ast_log(LOG_WARNING, "AES encryption disabled. Install OpenSSL.\n"); return -1; }); + +/*! + * \brief AES encrypt data + * \param in data to be encrypted + * \param out pointer to a buffer to hold the encrypted output + * \param ctx address of an aes encryption context filled in with ast_aes_set_encrypt_key + */ +AST_OPTIONAL_API(void, ast_aes_encrypt, + (const unsigned char *in, unsigned char *out, const ast_aes_encrypt_key *ctx), + { ast_log(LOG_WARNING, "AES encryption disabled. Install OpenSSL.\n");return; }); + +/*! + * \brief AES decrypt data + * \param in encrypted data + * \param out pointer to a buffer to hold the decrypted output + * \param ctx address of an aes encryption context filled in with ast_aes_set_decrypt_key + */ +AST_OPTIONAL_API(void, ast_aes_decrypt, + (const unsigned char *in, unsigned char *out, const ast_aes_decrypt_key *ctx), + { ast_log(LOG_WARNING, "AES encryption disabled. Install OpenSSL.\n");return; }); + AST_OPTIONAL_API(int, ast_crypto_loaded, (void), { return 0; }); #if defined(__cplusplus) || defined(c_plusplus) -- cgit v1.2.3