aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/crypto.h
diff options
context:
space:
mode:
authortwilson <twilson@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-21 19:11:32 +0000
committertwilson <twilson@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-21 19:11:32 +0000
commit15f42844eff69ae1f2576497c2653a7423f42395 (patch)
tree702c8203da791c3e168d1a0ef5d07dbafea3dd54 /include/asterisk/crypto.h
parentfe09035019d8f513addec09466170dfc180a1de3 (diff)
Remove built-in AES code and use optional_api instead
Review: https://reviewboard.asterisk.org/r/793/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@278538 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/crypto.h')
-rw-r--r--include/asterisk/crypto.h54
1 files changed, 54 insertions, 0 deletions
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)