38 #define AES_BLOCK_SIZE 16
86 static int aes_helper(
struct ast_channel *chan,
const char *cmd,
char *data,
87 char *buf,
size_t len)
89 unsigned char curblock[AES_BLOCK_SIZE] = { 0, };
92 int data_len, encrypt;
103 if (ast_strlen_zero(args.data) || ast_strlen_zero(args.key)) {
104 ast_log(LOG_WARNING,
"Syntax: %s(<key>,<data>) - missing argument!\n", cmd);
108 if (strlen(args.key) != AES_BLOCK_SIZE) {
109 ast_log(LOG_WARNING,
"Syntax: %s(<key>,<data>) - <key> parameter must be exactly 16 characters!\n", cmd);
113 ast_aes_set_encrypt_key((
unsigned char *) args.key, &ecx);
114 ast_aes_set_decrypt_key((
unsigned char *) args.key, &dcx);
117 ast_log(LOG_ERROR,
"Unable to allocate memory for data\n");
121 encrypt = strcmp(
"AES_DECRYPT", cmd);
125 data_len = strlen(tmp);
130 if (data_len >= len) {
131 ast_log(LOG_WARNING,
"Syntax: %s(<keys>,<data>) - <data> exceeds buffer length. Result may be truncated!\n", cmd);
135 while (data_len > 0) {
136 memset(curblock, 0, AES_BLOCK_SIZE);
137 memcpy(curblock, tmpP, (data_len < AES_BLOCK_SIZE) ? data_len : AES_BLOCK_SIZE);
139 ast_aes_encrypt(curblock, (
unsigned char *) tmpP, &ecx);
141 ast_aes_decrypt(curblock, (
unsigned char *) tmpP, &dcx);
143 tmpP += AES_BLOCK_SIZE;
144 data_len -= AES_BLOCK_SIZE;
150 memcpy(buf, tmp, len);
158 .
name =
"AES_ENCRYPT",
163 .
name =
"AES_DECRYPT",
167 static int unload_module(
void)
173 static int load_module(
void)
180 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"AES dialplan functions",
181 .support_level = AST_MODULE_SUPPORT_CORE,
183 .unload = unload_module,
184 .requires =
"res_crypto",
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Provide cryptographic signature routines.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
Data structure associated with a custom dialplan function.
Core PBX routines and definitions.
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
#define ast_calloc(num, len)
A wrapper for calloc()
Module has failed to load, may be in an inconsistent state.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
#define AST_APP_ARG(name)
Define an application argument.