/* * Copyright (C) 2006 Richard Kotal * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published * by the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #define _GNU_SOURCE #include #include #if defined(NO_AOLSERVER) /* TCL interface */ #include "tcl.h" #define NS_OK TCL_OK #define NS_ERROR TCL_ERROR #define Ns_Malloc Tcl_Alloc #define Ns_Free Tcl_Free #define NS_TRUE 1 #define NS_FALSE 0 #define STREQ(a,b) (((*a) == (*b)) && (strcmp((a),(b)) == 0)) #else /* AOL server interfacee */ #define TCL82 1 #include "ns.h" static Ns_TclInterpInitProc ns_mcrypt_TclInterpInit; #endif /* end TCL interface */ #if (defined(NS_MAJOR_VERSION) && NS_MAJOR_VERSION >= 4) || defined(NO_AOLSERVER) typedef Tcl_Obj * SF_TYPE; #undef CONST2 #define CONST2 CONST #else #include "tclInt.h" typedef char * SF_TYPE; #define CONST2 #endif /* AOL VARIABLES */ int Ns_ModuleVersion = 1; /* CONSTANTS */ #define TCLCMD "ns_mcrypt" #define PKG_NAME "nsmcrypt" #define PKG_VERSION "1.1" #define STR_MCRYPT "ns:mcrypt" #define STR_ALGO "algo" #define STR_MODES "modes" #define CRYPT 1 #define DECRYPT 0 /* STATIC FUNCTIONS */ static Tcl_ObjCmdProc ns_mcrypt_TclCmdRegister; unsigned char ns_mcrypt_utils_val2char(unsigned char x); int ns_mcrypt_utils_ishexstring(char *x, int insize); char * ns_mcrypt_utils_asciify(char *in, long len); char * ns_mcrypt_utils_unasciify(char *in, int insize); static int ns_mcrypt_Min(int i1, int i2); static void ns_mcrypt_AlgoModes(Tcl_Interp *interp, char *type, char *dir); static int ns_mcrypt_Capability(Tcl_Interp *interp, char *name, char *dir, char *type); static int ns_mcrypt_NewObj(Tcl_Interp *interp, char *algo, char *mode, char *algodir, char *algomode); static int ns_mcrypt_InitObj(Tcl_Interp *interp, Tcl_Obj *obj,char *key, int keysize); static int ns_mcrypt_FlushObj(Tcl_Interp *interp, Tcl_Obj *obj); static int ns_mcrypt_DestroyObj(Tcl_Obj *obj); static int ns_mcrypt_CryptObj(Tcl_Interp *interp, Tcl_Obj *obj, int type, char *text, int textsize,int in_bin, int out_bin); static int ns_mcrypt_IsMcryptObj(Tcl_Obj *obj,char *name); static Tcl_Obj * ns_mcrypt_CreateObj(MCRYPT td); static int ns_mcrypt_SetIV(Tcl_Interp *interp,Tcl_Obj *obj,int bin, char *IV, int size); static int ns_mcrypt_GetIV(Tcl_Interp *interp,Tcl_Obj *obj,int bin); static int ns_mcrypt_PutShareCryptObj(Tcl_Interp *interp,Tcl_Obj *obj); static int ns_mcrypt_GetShareCryptObj(Tcl_Interp *interp,Tcl_Obj *obj); static void FreeMcryptInternalRep(Tcl_Obj *obj); static void DupMcryptInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr); static void UpdateStringOfMcrypt(Tcl_Obj *obj); static int SetMcryptFromAny( Tcl_Interp *interp, Tcl_Obj *objPtr); static char * Ns_StrCopy2 (char *src, int len); Tcl_ObjType tclMcryptType = { "mcrypt", FreeMcryptInternalRep, /* freeIntRepProc */ DupMcryptInternalRep, /* dupIntRepProc */ UpdateStringOfMcrypt, /* updateStringProc */ SetMcryptFromAny /* setFromAnyProc */ };