/* * 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) #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)) /* TCL interface */ #else /* AOL server interfacee */ #define TCL82 1 #include "ns.h" static Ns_TclInterpInitProc ns_mhash_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_mhash" #define PKG_NAME "nsmhash" #define PKG_VERSION "1.1" #define MAX_SALTSIZE 128 #define MAX_KEYGEN_HASH_ALGO 2 #define STR_HASH "ns:mhash:hash" #define STR_HMAC "ns:mhash:hmac" /* STATIC FUNCTIONS */ static Tcl_ObjCmdProc ns_mhash_TclCmdRegister; static void ns_mhash_HashAlgo(Tcl_Interp *interp, char *type); static int ns_mhash_HashNew(Tcl_Interp *interp, char *name); static MHASH ns_mhash_HashCreate(char *name); static Tcl_Obj * ns_mhash_NewHashObj(MHASH td, char *name); static int ns_mhash_DestroyHashObj(Tcl_Obj *obj, char *type); static int ns_mhash_PutShareHashObj(Tcl_Interp *interp,Tcl_Obj *obj, char *type); static int ns_mhash_GetShareHashObj(Tcl_Interp *interp,Tcl_Obj *obj, char *type); static int ns_mhash_SerializeHashObj(Tcl_Interp *interp,Tcl_Obj *obj, char *type); static int ns_mhash_UnserializeHashObj(Tcl_Interp *interp,Tcl_Obj *obj, char *type); static int ns_mhash_CopyHashObj(Tcl_Interp *interp,Tcl_Obj *obj,char *type); static int ns_mhash_DigestPrintFromHash(Tcl_Interp *interp,Tcl_Obj *obj,int bin,char *type); static char *ns_mhash_DeleteHashObj(Tcl_Obj *obj, char *type); static int ns_mhash_UpdateHash(Tcl_Interp *interp, Tcl_Obj *obj, char *txt,int len,char *type); static void ns_mhash_DestroyHashPtr(MHASH td, char *type); static int ns_mhash_HmacNew(Tcl_Interp *interp, char *name, char *keyword, int key_size); static MHASH ns_mhash_HmacCreate(char *name,char *keyword,int key_size); static int ns_mhash_KeygenAlgo(Tcl_Interp *interp); static int ns_mhash_KeygenCapa(Tcl_Interp *interp, char *name); static int ns_mhash_KeygenCreate(Tcl_Interp *interp,int bin,char *algoname,char *pass,mutils_word32 keysize,char *salt,int count,int hashc,Tcl_Obj * hashv[]); static int ns_mhash_GetKeygenId(char *name); static int ns_mhash_GetHashId(char *name); static int ns_mhash_IsHashObj(Tcl_Obj *obj,char *name); static void FreeMhashInternalRep(Tcl_Obj *obj); static void DupMhashInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr); static void UpdateStringOfMhash(Tcl_Obj *obj); static int SetMhashFromAny( Tcl_Interp *interp, Tcl_Obj *objPtr); Tcl_ObjType tclMhashType = { "mhash", FreeMhashInternalRep, /* freeIntRepProc */ DupMhashInternalRep, /* dupIntRepProc */ UpdateStringOfMhash, /* updateStringProc */ SetMhashFromAny /* setFromAnyProc */ };