diff --git a/.gitattributes b/.gitattributes index fa7081d30e076baa6e44d7f74a632a6713658ea5..4e49b8f58c99476f0bdb4cf9b0000faebe96a2c6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,6 +13,7 @@ testfont binary /src/modules/_Crypto/des.c foreign_ident /src/modules/_Crypto/des.pike foreign_ident /src/modules/_Crypto/idea.c foreign_ident +/src/modules/_Crypto/invert.c foreign_ident /src/modules/_Crypto/md2.c foreign_ident /src/modules/_Crypto/md5.c foreign_ident /src/modules/_Crypto/md5.pike foreign_ident diff --git a/src/modules/_Crypto/invert.c b/src/modules/_Crypto/invert.c new file mode 100644 index 0000000000000000000000000000000000000000..78deb6de8c1a6c486f0c1ea1e799b61ee74709ad --- /dev/null +++ b/src/modules/_Crypto/invert.c @@ -0,0 +1,163 @@ +/* + * $Id: invert.c,v 1.1 1996/11/08 22:28:42 grubba Exp $ + * + * INVERT crypto module for Pike + * + * /precompiled/crypto/invert + * + * Henrik Grubbstr�m 1996-11-08 + */ + +/* + * Includes + */ + +/* From the Pike distribution */ +#include "global.h" +#include "stralloc.h" +#include "interpret.h" +#include "svalue.h" +#include "constants.h" +#include "macros.h" +#include "threads.h" +#include "object.h" +#include "stralloc.h" +#include "builtin_functions.h" + +/* Module specific includes */ +#include "precompiled_crypto.h" + +/* + * Globals + */ + +struct program *pike_invert_program; + +/* + * Functions + */ + +void init_pike_invert(struct object *o) +{ +} + +void exit_pike_invert(struct object *o) +{ +} + +/* + * efuns and the like + */ + +/* int query_block_size(void) */ +static void f_query_block_size(INT32 args) +{ + if (args) { + error("Too many arguments to invert->query_block_size()\n"); + } + push_int(8); +} + +/* int query_key_length(void) */ +static void f_query_key_length(INT32 args) +{ + if (args) { + error("Too many arguments to invert->query_key_length()\n"); + } + push_int(8); +} + +/* void set_key(string) */ +static void f_set_key(INT32 args) +{ + if (args != 1) { + error("Wrong number of args to invert->set_key()\n"); + } + if (sp[-1].type != T_STRING) { + error("Bad argument 1 to invert->set_key()\n"); + } + + pop_n_elems(args); +} + +/* string encrypt(string) */ +/* string decrypt(string) */ +/* string dencrypt(string) */ +static void f_dencrypt(INT32 args) +{ + char buffer[8]; + int i; + + if (args != 1) { + error("Wrong number of arguments to invert->dencrypt()\n"); + } + if (sp[-1].type != T_STRING) { + error("Bad argument 1 to invert->dencrypt()\n"); + } + if (sp[-1].u.string->len != 8) { + error("Bad length of argument 1 to invert->dencrypt()\n"); + } + + for (i=0; i<8; i++) { + buffer[i] = ~sp[-1].u.string->str[i]; + } + + pop_n_elems(args); + + push_string(make_shared_binary_string(buffer, 8)); + + MEMSET(buffer, 0, 8); +} + +/* + * Module linkage + */ + +void init_invert_efuns(void) +{ + /* add_efun()s */ +} + +void init_invert_programs(void) +{ + /* + * start_new_program(); + * + * add_storage(); + * + * add_function(); + * add_function(); + * ... + * + * set_init_callback(); + * set_exit_callback(); + * + * program = end_c_program(); + * program->refs++; + * + */ + + /* /precompiled/crypto/invert */ + start_new_program(); + + add_function("query_block_size", f_query_block_size, "function(void:int)", OPT_TRY_OPTIMIZE); + add_function("query_key_length", f_query_key_length, "function(void:int)", OPT_TRY_OPTIMIZE); + add_function("set_key", f_set_key, "function(string:void)", OPT_SIDE_EFFECT); + add_function("encrypt", f_dencrypt, "function(string:string)", OPT_SIDE_EFFECT); + add_function("decrypt", f_dencrypt, "function(string:string)", OPT_SIDE_EFFECT); + add_function("dencrypt", f_dencrypt, "function(string:string)", OPT_SIDE_EFFECT); + + set_init_callback(init_pike_invert); + set_exit_callback(exit_pike_invert); + + pike_invert_program = end_c_program("/precompiled/crypto/invert"); + pike_invert_program->refs++; +} + +void exit_invert(void) +{ + /* free_program()s */ + free_program(pike_invert_program); +} + + diff --git a/src/modules/_Crypto/precompiled_crypto.h b/src/modules/_Crypto/precompiled_crypto.h index eb706c659a0b9bb5442786da1777283996085db2..a250a7d302a30569768d6910e8964d39c1625172 100644 --- a/src/modules/_Crypto/precompiled_crypto.h +++ b/src/modules/_Crypto/precompiled_crypto.h @@ -107,4 +107,9 @@ void init_des_efuns(void); void init_des_programs(void); void exit_des(void); +/* /precompiled/crypto/invert */ +void init_invert_efuns(void); +void init_invert_programs(void); +void exit_invert(void); + #endif /* PRECOMPILED_X_H */