[asterisk-commits] dvossell: branch dvossel/func_aes_trunk r170146 - /team/dvossel/func_aes_trun...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 22 10:47:35 CST 2009


Author: dvossell
Date: Thu Jan 22 10:47:34 2009
New Revision: 170146

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=170146
Log:
Adding func_aes.c

Added:
    team/dvossel/func_aes_trunk/funcs/func_aes.c   (with props)

Added: team/dvossel/func_aes_trunk/funcs/func_aes.c
URL: http://svn.digium.com/svn-view/asterisk/team/dvossel/func_aes_trunk/funcs/func_aes.c?view=auto&rev=170146
==============================================================================
--- team/dvossel/func_aes_trunk/funcs/func_aes.c (added)
+++ team/dvossel/func_aes_trunk/funcs/func_aes.c Thu Jan 22 10:47:34 2009
@@ -1,0 +1,159 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999-2009, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief AES encryption/decryption dialplan functions
+ * 
+ * \ingroup functions
+ */
+
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/pbx.h"
+#include "asterisk/app.h"
+#include "asterisk/aes.h"
+
+
+static int aes_encrypt_read(struct ast_channel *chan, const char *cmd, char *data,
+	       char *buf, size_t len)
+{
+
+        unsigned char curblock[16];
+	char *src;
+	char *dst;
+        int x, data_len; 
+
+        AST_DECLARE_APP_ARGS(args,  
+                           AST_APP_ARG(key);
+                           AST_APP_ARG(data);
+	);
+
+        AST_STANDARD_APP_ARGS(args, data);
+
+        if (ast_strlen_zero(args.data) || ast_strlen_zero(args.key)) {
+                ast_log(LOG_WARNING, "Syntax: AES_ENCRYPT(<key>, <data>) - missing argument!\n");
+                return -1;
+        }
+        
+        if (strlen(args.key) != 16 ) {         /* key must be of 16 characters in length, 128 bits */
+                ast_log(LOG_WARNING, "Syntax: AES_ENCRYPT(<key>, <data>) - <key> parameter must be exactly 16 characters!\n");
+                return -1;
+        }
+
+        ast_aes_encrypt_key ecx;                       /*  AES 128 Encryption context */
+        ast_aes_encrypt_key(args.key, &ecx);
+       
+        dst = buf;
+        src = args.data; 
+	data_len = strlen(args.data);
+        memset(curblock, '\0', sizeof(curblock));
+
+	if(data_len >= len){                           /* make sure to not go over buffer len */
+                data_len = (len-1);
+        }
+
+        while(data_len > 0) {
+                for (x=0;x<16;x++)
+                        curblock[x] = src[x];
+                ast_aes_encrypt(curblock, dst, &ecx);
+                memcpy(curblock, dst, sizeof(curblock));
+                dst += 16;
+                src += 16;
+                data_len -= 16;
+        }
+
+        return 0;
+}
+static int aes_decrypt_read(struct ast_channel *chan, const char *cmd, char *data,
+	       char *buf, size_t len)
+{
+
+        unsigned char curblock[16];
+	char *src;
+	char *dst;
+        int x, data_len; 
+
+        AST_DECLARE_APP_ARGS(args,  
+                           AST_APP_ARG(key);
+                           AST_APP_ARG(data);
+	);
+
+        AST_STANDARD_APP_ARGS(args, data);
+
+        if (ast_strlen_zero(args.data) || ast_strlen_zero(args.key)) {
+                ast_log(LOG_WARNING, "Syntax: AES_DECRYPT(<key>, <data>) - missing argument!\n");
+                return -1;
+        }
+
+        if (strlen(args.key) != 16 ) {         /* key must be of 16 characters in length, 128 bits */
+                ast_log(LOG_WARNING, "Syntax: AES_DECRYPT(<key>, <data>) - <key> parameter must be exactly 16 characters!\n");
+                return -1;
+        }
+
+        ast_aes_decrypt_key dcx;                       /*!< AES 128 Encryption context */
+        ast_aes_decrypt_key(args.key, &dcx);
+       
+        dst = buf;
+        src = args.data; 
+	data_len = strlen(args.data);
+        memset(curblock, '\0', sizeof(curblock));
+
+	if(data_len >= len){                       /* make sure to not go over buffer len */
+                data_len = (len-1);
+        }
+
+        while(data_len > 0) {
+                for (x=0;x<16;x++)
+                        curblock[x] = src[x];
+                ast_aes_decrypt(curblock, dst, &dcx);
+                memcpy(curblock, dst, sizeof(curblock));
+                dst += 16;
+                src += 16;
+                data_len -= 16;
+        }
+
+        return 0;
+}
+
+static struct ast_custom_function aes_encrypt_function = {
+	.name = "AES_ENCRYPT",
+	.read = aes_encrypt_read,
+};
+
+static struct ast_custom_function aes_decrypt_function = {
+	.name = "AES_DECRYPT",
+	.read = aes_decrypt_read,
+};
+
+
+static int unload_module(void)
+{
+	int res = ast_custom_function_unregister(&aes_decrypt_function);
+	return res |= ast_custom_function_unregister(&aes_encrypt_function);
+}
+
+static int load_module(void)
+{
+        int res = ast_custom_function_register(&aes_decrypt_function);
+	return res |= ast_custom_function_register(&aes_encrypt_function);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "AES dialplan functions");

Propchange: team/dvossel/func_aes_trunk/funcs/func_aes.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/func_aes_trunk/funcs/func_aes.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/func_aes_trunk/funcs/func_aes.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list