Skip to content
Snippets Groups Projects
Commit 4b85c94c authored by Niels Möller's avatar Niels Möller
Browse files

Changed padding method. Now pads the same way SSL does.

Rev: src/modules/_Crypto/crypto.c:1.14
parent 7d8d9196
No related branches found
No related tags found
No related merge requests found
/* /*
* $Id: crypto.c,v 1.13 1997/02/15 22:03:03 nisse Exp $ * $Id: crypto.c,v 1.14 1997/02/27 13:51:54 nisse Exp $
* *
* A pike module for getting access to some common cryptos. * A pike module for getting access to some common cryptos.
* *
...@@ -367,15 +367,17 @@ static void f_crypt(INT32 args) ...@@ -367,15 +367,17 @@ static void f_crypt(INT32 args)
static void f_pad(INT32 args) static void f_pad(INT32 args)
{ {
int i; int i;
int len;
if (args) { if (args) {
error("Too many arguments to crypto->pad()\n"); error("Too many arguments to crypto->pad()\n");
} }
for (i=THIS->backlog_len; i < (THIS->block_size - 1); i++) { len = THIS->block_size - 1 - THIS->backlog_len;
THIS->backlog[i] = my_rand() & 0xff; for (i=0; i < len; i++)
} THIS->backlog[THIS->backlog_len + i] = my_rand() & 0xff;
THIS->backlog[i] = THIS->backlog_len;
THIS->backlog[i] = len;
push_string(make_shared_binary_string((const char *)THIS->backlog, push_string(make_shared_binary_string((const char *)THIS->backlog,
THIS->block_size)); THIS->block_size));
...@@ -392,29 +394,26 @@ static void f_unpad(INT32 args) ...@@ -392,29 +394,26 @@ static void f_unpad(INT32 args)
int len; int len;
struct pike_string *str; struct pike_string *str;
if (args != 1) { if (args != 1)
error("Wrong number of arguments to crypto->unpad()\n"); error("Wrong number of arguments to crypto->unpad()\n");
}
if (sp[-1].type != T_STRING) { if (sp[-1].type != T_STRING)
error("Bad argument 1 to crypto->unpad()\n"); error("Bad argument 1 to crypto->unpad()\n");
}
str = sp[-1].u.string; str = sp[-1].u.string;
len = str->len; len = str->len;
len += str->str[len - 1] - THIS->block_size; if (str->str[len - 1] > (THIS->block_size - 1))
error("crypto->unpad(): Invalid padding\n");
if (len < 0) { len -= (str->str[len - 1] + 1);
if (len < 0)
error("crypto->unpad(): String to short to unpad\n"); error("crypto->unpad(): String to short to unpad\n");
}
str->refs++; str->refs++;
pop_stack(); pop_stack();
push_string(make_shared_binary_string(str->str, len)); push_string(make_shared_binary_string(str->str, len));
free_string(str); free_string(str);
} }
...@@ -491,9 +490,9 @@ void pike_module_init(void) ...@@ -491,9 +490,9 @@ void pike_module_init(void)
add_function("hex_to_string", f_hex_to_string, "function(string:string)", OPT_TRY_OPTIMIZE); add_function("hex_to_string", f_hex_to_string, "function(string:string)", OPT_TRY_OPTIMIZE);
#if 0 #if 0
MOD_INIT(md2)(); MOD_INIT(md2)();
MOD_INIT(md5)();
#endif #endif
#if 1 #if 1
MOD_INIT(md5)();
MOD_INIT(crypto)(); MOD_INIT(crypto)();
MOD_INIT(idea)(); MOD_INIT(idea)();
MOD_INIT(des)(); MOD_INIT(des)();
...@@ -510,9 +509,9 @@ void pike_module_exit(void) ...@@ -510,9 +509,9 @@ void pike_module_exit(void)
/* free_program()s */ /* free_program()s */
#if 0 #if 0
MOD_EXIT(md2)(); MOD_EXIT(md2)();
MOD_EXIT(md5)();
#endif #endif
#if 1 #if 1
MOD_EXIT(md5)();
MOD_EXIT(crypto)(); MOD_EXIT(crypto)();
MOD_EXIT(idea)(); MOD_EXIT(idea)();
MOD_EXIT(des)(); MOD_EXIT(des)();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment