* harbour/include/hbvm.h
* harbour/include/hbrdddbf.h
* harbour/include/hbapidbg.h
* harbour/include/hbset.h
* harbour/include/hbcomp.h
* harbour/include/hbapirdd.h
* harbour/include/hbstack.h
* harbour/include/hbsxfunc.h
* harbour/include/hbapilng.h
* harbour/include/hbgtcore.h
* harbour/include/hbapifs.h
* harbour/include/hbdbsort.h
* harbour/include/hbapigt.h
* harbour/include/hbapi.h
* harbour/include/hbapierr.h
* harbour/include/hbapiitm.h
* harbour/include/hbrddfpt.h
* harbour/contrib/hbmysql/mysql.c
* harbour/contrib/hbct/bitnum.c
* harbour/contrib/hbct/token2.c
* harbour/contrib/hbct/charsprd.c
* harbour/contrib/hbct/ctnet.c
* harbour/contrib/hbct/charonly.c
* harbour/contrib/hbct/atadjust.c
* harbour/contrib/hbct/ctwin.c
* harbour/contrib/hbct/charsort.c
* harbour/contrib/hbct/ctwin.h
* harbour/contrib/hbct/charmix.c
* harbour/contrib/hbct/charevod.c
* harbour/contrib/hbct/maxline.c
* harbour/contrib/hbct/wordrepl.c
* harbour/contrib/hbct/charrepl.c
* harbour/contrib/hbct/files.c
* harbour/contrib/hbct/video.c
* harbour/contrib/hbct/charswap.c
* harbour/contrib/hbct/dattime3.c
* harbour/contrib/hbct/charop.c
* harbour/contrib/hbct/misc2.c
* harbour/contrib/hbct/charone.c
* harbour/contrib/hbct/ctstr.c
* harbour/contrib/hbct/screen1.c
* harbour/contrib/hbct/token1.c
* harbour/contrib/hbct/ctstr.h
* harbour/contrib/hbct/charmirr.c
* harbour/contrib/hbct/relation.c
* harbour/contrib/hbct/atnum.c
* harbour/contrib/hbct/like.c
* harbour/contrib/hbct/count.c
* harbour/contrib/hbct/disk.c
* harbour/contrib/hbct/ctstrfil.c
* harbour/contrib/hbct/posdiff.c
* harbour/contrib/hbct/addascii.c
* harbour/contrib/hbct/tab.c
* harbour/contrib/hbct/numline.c
* harbour/contrib/hbct/dattime2.c
* harbour/contrib/hbct/asciisum.c
* harbour/contrib/hbct/expand.c
* harbour/contrib/hbct/pos2.c
* harbour/contrib/hbct/numat.c
* harbour/contrib/hbct/atrepl.c
* harbour/contrib/hbct/wordtoch.c
* harbour/contrib/hbct/print.c
* harbour/contrib/hbct/justify.c
* harbour/contrib/xhb/hbxml.c
* harbour/contrib/xhb/dbf2txt.c
* harbour/contrib/xhb/xhbis.c
* harbour/contrib/xhb/fparse.c
* harbour/contrib/xhb/xstrdel.c
* harbour/contrib/xhb/hbcomprs.c
* harbour/contrib/xhb/datesxhb.c
* harbour/contrib/xhb/xhbmsgs.c
* harbour/contrib/xhb/freadlin.c
* harbour/contrib/xhb/txtline.c
* harbour/contrib/xhb/xhbtrim.c
* harbour/contrib/xhb/xhbcopyf.c
* harbour/contrib/xhb/cstructc.c
* harbour/contrib/xhb/xhbfunc.c
* harbour/contrib/hbtpathy/tplinux.c
* harbour/contrib/hbgt/charmixg.c
* harbour/contrib/hbgt/strexpan.c
* harbour/contrib/hbgt/charodd.c
* harbour/contrib/hbgt/strright.c
* harbour/contrib/hbgt/asciisgt.c
* harbour/contrib/hbgt/strdiffg.c
* harbour/contrib/hbgt/chrtotal.c
* harbour/contrib/hbgt/strcount.c
* harbour/contrib/hbgt/strleft.c
* harbour/contrib/hbgt/ascposgt.c
* harbour/contrib/hbgt/chrfirst.c
* harbour/contrib/hbgt/chrcount.c
* harbour/contrib/hbgt/strpbrk.c
* harbour/contrib/hbgt/chareven.c
* harbour/contrib/hbgt/strcspn.c
* harbour/contrib/hbgt/atdiff.c
* harbour/contrib/hbsqlit3/hbsqlit3.c
* harbour/contrib/hbmzip/hbmzip.c
* harbour/contrib/hbnf/proper.c
* harbour/contrib/hbnf/fttext.c
* harbour/contrib/hbnf/chdir.c
* harbour/contrib/hbnf/getver.c
* harbour/contrib/hbnf/ftattr.c
* harbour/contrib/hbnf/mkdir.c
* harbour/contrib/hbnf/rmdir.c
* harbour/contrib/Makefile
* harbour/contrib/hbcurl/hbcurl.c
* harbour/contrib/rddsql/sddmy/mysqldd.c
* harbour/contrib/rddsql/sddpg/pgsqldd.c
* harbour/contrib/rddsql/sddfb/fbirddd.c
* harbour/contrib/rddsql/sddodbc/odbcdd.c
* harbour/contrib/rddsql/sqlmix.c
* harbour/contrib/hbhpdf/harupdf.c
* harbour/contrib/rddads/adsx.c
* harbour/contrib/rddads/adsfunc.c
* harbour/contrib/rddads/rddads.h
* harbour/contrib/rddads/ads1.c
* harbour/contrib/hbmisc/hb_f.c
* harbour/contrib/hbmisc/strfmt.c
* harbour/contrib/hbmisc/stringsx.c
* harbour/contrib/hbmisc/spd.c
* harbour/contrib/hbtip/utils.c
* harbour/contrib/hbwin/wapi_winbase.c
* harbour/contrib/hbwin/win_misc.c
* harbour/contrib/hbbtree/hb_btree.h
* harbour/contrib/hbbtree/hb_btree.c
* harbour/source/pp/hbpp.c
* harbour/source/vm/runner.c
* harbour/source/vm/estack.c
* harbour/source/vm/itemapi.c
* harbour/source/vm/hvm.c
* harbour/source/vm/cmdarg.c
* harbour/source/vm/memvars.c
* harbour/source/vm/dynlibhb.c
* harbour/source/vm/set.c
* harbour/source/main/harbour.c
* harbour/source/debug/dbgentry.c
* harbour/source/common/hbfsapi.c
* harbour/source/common/hbfopen.c
* harbour/source/rtl/gtdos/gtdos.c
* harbour/source/rtl/diskspac.c
* harbour/source/rtl/console.c
* harbour/source/rtl/chrasc.c
* harbour/source/rtl/fscopy.c
* harbour/source/rtl/run.c
* harbour/source/rtl/spfiles.c
* harbour/source/rtl/defpath.c
* harbour/source/rtl/philes.c
* harbour/source/rtl/oldbox.c
* harbour/source/rtl/math.c
* harbour/source/rtl/hbgtcore.c
* harbour/source/rtl/cdpapi.c
* harbour/source/rtl/gtcrs/gtcrs.c
* harbour/source/rtl/dirdrive.c
* harbour/source/rtl/hbi18n1.c
* harbour/source/rtl/trim.c
* harbour/source/rtl/hbzlibgz.c
* harbour/source/rtl/philesx.c
* harbour/source/rtl/mlcfunc.c
* harbour/source/rtl/filehb.c
* harbour/source/rtl/fstemp.c
* harbour/source/rtl/is.c
* harbour/source/rtl/hbrunfun.c
* harbour/source/rtl/ampm.c
* harbour/source/rtl/setcolor.c
* harbour/source/rtl/oemansi.c
* harbour/source/rtl/disksphb.c
* harbour/source/rtl/hbzlib.c
* harbour/source/rtl/strpeek.c
* harbour/source/rtl/replic.c
* harbour/source/rtl/stuff.c
* harbour/source/rtl/hbstrfmt.c
* harbour/source/rtl/transfrm.c
* harbour/source/rtl/hbhex.c
* harbour/source/rtl/trace.c
* harbour/source/rtl/hbadler.c
* harbour/source/rtl/samples.c
* harbour/source/rtl/filebuf.c
* harbour/source/rtl/hbcrc.c
* harbour/source/rtl/gete.c
* harbour/source/rtl/hbmd5.c
* harbour/source/rtl/langapi.c
* harbour/source/rtl/gtcgi/gtcgi.c
* harbour/source/rtl/errapi.c
* harbour/source/rtl/hbregexc.c
* harbour/source/rtl/natmsg.c
* harbour/source/rtl/fssize.c
* harbour/source/rtl/hbinet.c
* harbour/source/rtl/colorind.c
* harbour/source/rtl/copyfile.c
* harbour/source/rtl/mouseapi.c
* harbour/source/rtl/soundex.c
* harbour/source/rtl/memofile.c
* harbour/source/rtl/hbffind.c
* harbour/source/rtl/gtapi.c
* harbour/source/rtl/direct.c
* harbour/source/rtl/filesys.c
* harbour/source/rtl/file.c
* harbour/source/rtl/val.c
* harbour/source/rtl/hbregex.c
* harbour/source/rtl/rat.c
* harbour/source/rtl/isprint.c
* harbour/source/rdd/dbfntx/dbfntx1.c
* harbour/source/rdd/dbsql.c
* harbour/source/rdd/workarea.c
* harbour/source/rdd/wacore.c
* harbour/source/rdd/sdf1.c
* harbour/source/rdd/dbdetach.c
* harbour/source/rdd/dbcmdx.c
* harbour/source/rdd/dbfnsx/dbfnsx1.c
* harbour/source/rdd/dbcmd.c
* harbour/source/rdd/dbfcdx/dbfcdx1.c
* harbour/source/rdd/delim1.c
* harbour/source/rdd/dbf1.c
* harbour/source/rdd/hsx/hsx.c
* harbour/source/rdd/dbcmd53.c
* harbour/source/rdd/usrrdd/usrrdd.c
* harbour/source/rdd/wafunc.c
* harbour/source/rdd/dbffpt/dbffpt1.c
* harbour/source/rdd/hbsix/sxsem.c
* harbour/source/rdd/hbsix/sxord.c
* harbour/source/rdd/hbsix/sxfname.c
* harbour/source/rdd/hbsix/sxtable.c
* harbour/source/rdd/hbsix/sxdate.c
* harbour/source/rdd/hbsix/sxutil.c
* harbour/source/rdd/hbsix/sxcompr.c
* harbour/source/compiler/hbmain.c
* harbour/source/compiler/cmdcheck.c
* harbour/source/compiler/hbpcode.c
* harbour/source/compiler/genc.c
* harbour/source/compiler/gencc.c
* harbour/source/compiler/hbcmplib.c
* harbour/source/compiler/ppcomp.c
* changed 'char *' and changed 'BYTE *' to 'const char *' in
the following functions:
const char * hb_vmFindModuleSymbolName( PHB_SYMB pSym );
void hb_vmInitSymbolGroup( void * hNewDynLib, int argc,
const char * argv[] );
void hb_dbgEntry( int nMode, int nLine, const char *szName,
int nIndex, PHB_ITEM pFrame );
void hb_dbgAddBreak( void *handle, const char *cModule,
int nLine, const char *szFunction );
void hb_dbgAddWatch( void *handle, const char *szExpr, BOOL bTrace );
PHB_ITEM hb_dbgGetExpressionValue( void *handle,
const char *expression );
BOOL hb_dbgIsValidStopLine( void *handle, const char *szModule,
int nLine );
void hb_dbgSetToCursor( void *handle, const char *szModule,
int nLine );
void hb_dbgSetWatch( void *handle, int nWatch,
const char *szExpr, BOOL bTrace );
const char * hb_setGetCPtr( HB_set_enum set_specifier );
const char * hb_setGetAltFile( void );
const char * hb_setGetDateFormat( void );
const char * hb_setGetTimeFormat( void );
const char * hb_setGetDefault( void );
const char * hb_setGetDelimChars( void );
const char * hb_setGetDevice( void );
const char * hb_setGetExtraFile( void );
const char * hb_setGetPath( void );
const char * hb_setGetMFileExt( void );
const char * hb_setGetPrintFile( void );
const char * hb_setGetEOL( void );
const char * hb_setGetHBOUTLOG( void );
const char * hb_setGetHBOUTLOGINFO( void );
const char * hb_setGetOSCODEPAGE( void );
void hb_compInitPP( HB_COMP_DECL, int argc,
const char * const argv[] );
void hb_compGenPCodeN( const BYTE * pBuffer, ULONG ulSize,
HB_COMP_DECL );
int hb_compMain( int argc, const char * const argv[],
BYTE ** pBufPtr, ULONG * pulSize,
const char * szSource );
void hb_compChkCompilerSwitch( HB_COMP_DECL, int,
const char * const args[] );
void hb_compChkDefines( HB_COMP_DECL, int iArg,
const char * const args[] );
void hb_compGenCString( FILE * yyc, const BYTE * pText, ULONG ulLen );
AREAP hb_rddRequestArea( const char * szAlias, PHB_ITEM pCargo,
BOOL fNewArea, BOOL fWait );
char * hb_stackDirBuffer( void );
LONG hb_sxPtoD( const char * pDate );
const char * hb_langID( void );
const char * hb_langSelectID( const char * pszID );
const char * hb_langDGetItem( int iIndex );
const char * hb_langDGetErrorDesc( ULONG ulIndex );
BOOL hb_fsChDir( const char * pszDirName );
HB_FHANDLE hb_fsCreate( const char * pszFileName, ULONG ulAttr );
HB_FHANDLE hb_fsCreateEx( const char * pszFilename, ULONG ulAttr,
USHORT uiFlags );
HB_FHANDLE hb_fsCreateTemp( const char * pszDir,
const char * pszPrefix,
ULONG ulAttr, char * pszName );
HB_FHANDLE hb_fsCreateTempEx( char * pszName, const char * pszDir,
const char * pszPrefix,
const char * pszExt, ULONG ulAttr );
const char * hb_fsCurDir( USHORT uiDrive );
USHORT hb_fsCurDirBuff( USHORT uiDrive, char * pbyBuffer,
ULONG ulLen );
void hb_fsBaseDirBuff( char * pbyBuffer );
BOOL hb_fsDelete( const char * pszFileName );
BOOL hb_fsFile( const char * pszFileName );
BOOL hb_fsIsDirectory( const char * pszFilename );
HB_FOFFSET hb_fsFSize( const char * pszFileName, BOOL bUseDirEntry );
HB_FHANDLE hb_fsExtOpen( const char * pszFileName,
const char * pDefExt,
char * hb_fsExtName( const char * pFilename,
const char * pDefExt, USHORT uiExFlags,
const char * pPaths );
BOOL hb_fsMkDir( const char * pszDirName );
HB_FHANDLE hb_fsOpen( const char * pszFileName, USHORT uiFlags );
BOOL hb_fsRmDir( const char * pszDirName );
BOOL hb_fsRename( const char * pszOldName,
const char * pszNewName );
BOOL hb_fsGetFileTime( const char * pszFileName,
LONG * plJulian, LONG * plMillisec );
BOOL hb_fsSetFileTime( const char * pszFileName,
LONG lJulian, LONG lMillisec );
BOOL hb_fsGetAttr( const char * pszFileName, ULONG * pulAttr );
BOOL hb_fsSetAttr( const char * pszFileName, ULONG ulAttr );
HB_FHANDLE hb_fsPOpen( const char * pFilename, const char * pMode );
BOOL hb_fsCopy( const char * pSource, const char * pDest );
BOOL hb_spFile( const char * pFilename, char * pRetPath );
BOOL hb_spFileExists( const char * pFilename, char * pRetPath );
HB_FHANDLE hb_spOpen( const char * pFilename, USHORT uiFlags );
HB_FHANDLE hb_spCreate( const char * pFilename, ULONG ulAttr );
HB_FHANDLE hb_spCreateEx( const char * pFilename,
ULONG ulAttr, USHORT uiFlags );
PHB_FILE hb_fileExtOpen( const char * pFilename,
const char * pDefExt, USHORT uiExFlags,
const char * pPaths, PHB_ITEM pError );
PHB_FILE hb_fileCreateTemp( const char * pszDir,
const char * pszPrefix,
ULONG ulAttr, char * pszName );
PHB_FILE hb_fileCreateTempEx( char * pszName, const char * pszDir,
const char * pszPrefix,
const char * pszExt, ULONG ulAttr );
HB_ERRCODE hb_gtBox( SHORT uiTop, SHORT uiLeft, SHORT uiBottom,
SHORT uiRight, const BYTE * pbyFrame );
HB_ERRCODE hb_gtDrawBox( SHORT uiTop, SHORT uiLeft, SHORT uiBottom,
SHORT uiRight, const BYTE * pbyFrame,
int iColor );
HB_ERRCODE hb_gtWrite( const BYTE * pbyStr, ULONG ulLen );
HB_ERRCODE hb_gtWriteAt( USHORT uiRow, USHORT uiCol,
const BYTE * pbyStr, ULONG ulLen );
HB_ERRCODE hb_gtWriteCon( const BYTE * pbyStr, ULONG ulLen );
HB_ERRCODE hb_gtPutText( USHORT uiRow, USHORT uiCol,
const BYTE * pStr, ULONG ulLength,
int iColor );
HB_ERRCODE hb_gtOutStd( const BYTE * pbyStr, ULONG ulLen );
HB_ERRCODE hb_gtOutErr( const BYTE * pbyStr, ULONG ulLen );
HB_ERRCODE hb_gtBoxEx( int iTop, int iLeft, int iBottom, int iRight,
const BYTE * pbyFrame, int iColor );
void hb_mouseRestoreState( const BYTE * pBuffer );
const char * hb_strLTrim( const char * szText, ULONG * ulLen );
const char * hb_conNewLine( void );
const char * hb_conSetColor( const char * szColor );
const char * hb_errGetDescription( PHB_ITEM pError );
const char * hb_errGetFileName( PHB_ITEM pError );
const char * hb_errGetOperation( PHB_ITEM pError );
const char * hb_errGetSubSystem( PHB_ITEM pError );
int hb_ctwAddWindowBox( int iWindow, const BYTE * szBox, int iColor );
const char *ct_at_exact_forward
( const char *pcString, size_t sStrLen,
const char *pcMatch, size_t sMatchLen,
size_t *psMatchStrLen );
const char *ct_at_exact_backward
( const char *pcString, size_t sStrLen,
const char *pcMatch, size_t sMatchLen,
size_t *psMatchStrLen );
const char *ct_at_wildcard_forward
( const char *pcString, size_t sStrLen,
const char *pcMatch, size_t sMatchLen,
char cWildCard, size_t *psMatchStrLen );
const char *ct_at_wildcard_backward
( const char *pcString, size_t sStrLen,
const char *pcMatch, size_t sMatchLen,
char cWildCard, size_t *psMatchStrLen );
const char *ct_at_charset_forward
( const char *pcString, size_t sStrLen,
const char *pcCharSet, size_t sCharSetLen,
size_t *psMatchedCharPos );
const char *ct_at_charset_backward
( const char *pcString, size_t sStrLen,
const char *pcCharSet, size_t sCharSetLen,
size_t *psMatchedCharPos );
char * hb_adsOemToAnsi( const char * pcString, ULONG ulLen );
char * hb_adsAnsiToOem( const char * pcString, ULONG ulLen );
struct hb_BTree * hb_BTreeNew( const char *FileName,
USHORT usPageSize, USHORT usKeySize,
ULONG ulFlags, USHORT usBuffers );
struct hb_BTree * hb_BTreeOpen( const char *FileName, ULONG lFlags,
USHORT usBuffers );
BOOL hb_BTreeInsert( struct hb_BTree * pBTree, const char * szKey,
PHB_ITEM pData );
BOOL hb_BTreeDelete( struct hb_BTree * pBTree, const char * szKey,
LONG lData );
BOOL hb_BTreeSeek( struct hb_BTree * pBTree, const char * szKey,
LONG lData, BOOL bSoftSeek );
const char * hb_BTreeKey( struct hb_BTree * pBTree );
* modified RDD methods:
HB_ERRCODE PUTVALUEFILE( AREAP, USHORT, const char *, USHORT );
HB_ERRCODE GETVALUEFILE( AREAP, USHORT, const char *, USHORT );
* modified GT methods:
void REST( HB_GT_PTR, int, int, int, int, const BYTE * );
void PUTTEXT( HB_GT_PTR, int, int, BYTE, const BYTE *, ULONG );
void WRITEAT( HB_GT_PTR, int, int, const BYTE *, ULONG );
void WRITE( HB_GT_PTR, const BYTE *, ULONG );
void WRITECON( HB_GT_PTR, const BYTE *, ULONG );
void BOX( HB_GT_PTR, int, int, int, int, const BYTE *, BYTE );
void BOXD( HB_GT_PTR, int, int, int, int, const BYTE *, BYTE );
void BOXS( HB_GT_PTR, int, int, int, int, const BYTE *, BYTE );
void OUTSTD( HB_GT_PTR, BYTE *, ULONG );
void OUTERR( HB_GT_PTR, BYTE *, ULONG );
void MOUSERESTORESTATE( HB_GT_PTR, const BYTE * );
* modified RDD structers:
DBFIELDINFO, DBOPENINFO, DBORDERCONDINFO, DBCONSTRAINTINFO,
DBORDERCREATEINFO
+ modified parameters and behevior:
const char * hb_fsNameConv( const char * szFileName, char ** pszFree );
const char * hb_osEncode( const char * szFileName, char ** pszFree );
const char * hb_osDecode( const char * szFileName, char ** pszFree );
Please look at implementation and current usage of these functions.
+ added new function:
BOOL hb_itemGetWriteCL( PHB_ITEM pItem,
char ** pszValue, ULONG * pulLen );
which converts item string buffer to writable state to use with
functions like FREAD() instead of hb_itemUnShare*()
* updatd other code to respect above modifications
! fixed bugs (also GPF traps) located by above modifications
TODO: please make build tests. Especially in OS2 - not tested at all.
411 lines
12 KiB
C
411 lines
12 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* Harbour MD5 Support
|
|
*
|
|
* Copyright 2004 Dmitry V. Korzhov <dk@april26.spb.ru>
|
|
*
|
|
* Copyright 2007 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
|
* updated for current Harbour code, other then x86@32 machines,
|
|
* files and buffers longer then 2^32 and some fixes
|
|
*
|
|
* www - http://www.harbour-project.org
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
|
*
|
|
* As a special exception, the Harbour Project gives permission for
|
|
* additional uses of the text contained in its release of Harbour.
|
|
*
|
|
* The exception is that, if you link the Harbour libraries with other
|
|
* files to produce an executable, this does not by itself cause the
|
|
* resulting executable to be covered by the GNU General Public License.
|
|
* Your use of that executable is in no way restricted on account of
|
|
* linking the Harbour library code into it.
|
|
*
|
|
* This exception does not however invalidate any other reasons why
|
|
* the executable file might be covered by the GNU General Public License.
|
|
*
|
|
* This exception applies only to the code released by the Harbour
|
|
* Project under the name Harbour. If you copy code from other
|
|
* Harbour Project or Free Software Foundation releases into a copy of
|
|
* Harbour, as the General Public License permits, the exception does
|
|
* not apply to the code that you add in this way. To avoid misleading
|
|
* anyone as to the status of such modified files, you must delete
|
|
* this exception notice from them.
|
|
*
|
|
* If you write modifications of your own for Harbour, it is your choice
|
|
* whether to permit this exception to apply to your modifications.
|
|
* If you do not wish that, delete this exception notice.
|
|
*
|
|
*/
|
|
|
|
/*
|
|
MD5 digest (based on RFC 1321 only). [x]Harbour implementation
|
|
|
|
PRG functions:
|
|
|
|
HB_MD5( <cString> ) -> <cMD5>
|
|
Calculates RFC 1321 MD5 digest (128-bit checksum)
|
|
Parameters:
|
|
<cString> - string variable to calculate MD5
|
|
Returns:
|
|
ASCII hex MD5 digest as 32-byte string
|
|
empty string on error
|
|
|
|
HB_MD5FILE( <cFileName> ) -> <cMD5>
|
|
Calculates RFC 1321 MD5 digest (128-bit checksum) of a file contents
|
|
(file size is limited by OS limits only)
|
|
Parameters:
|
|
<cFileName> - file name
|
|
Returns:
|
|
ASCII hex MD5 digest as 32-byte string
|
|
empty string on error
|
|
|
|
C functions:
|
|
|
|
void hb_md5( BYTE * data, ULONG datalen, BYTE * digest )
|
|
Parameters:
|
|
data - input byte stream
|
|
datalen - input stream length
|
|
digest - raw (unformatted) MD5 digest buffer
|
|
(at least 16 bytes long)
|
|
|
|
void hb_md5file( HB_FHANDLE hFile, BYTE * digest )
|
|
Parameters:
|
|
hFile - file handle
|
|
digest - raw (unformatted) MD5 digest buffer
|
|
(at least 16 bytes long)
|
|
|
|
*/
|
|
|
|
#include "hbapi.h"
|
|
#include "hbapifs.h"
|
|
#include "hbchksum.h"
|
|
|
|
/* MD5 buffer */
|
|
typedef struct
|
|
{
|
|
UINT32 accum[ 4 ];
|
|
BYTE buf[ 64 ];
|
|
} MD5_BUF;
|
|
|
|
/*
|
|
Pseudofunctions;
|
|
A[x] - accumulators[4]
|
|
T[x] - Value table[64]
|
|
X[x] - buffer[16]
|
|
*/
|
|
#define ROTL(x,n) ((x << n) | (x >> (32 - n)))
|
|
#define PF1(a,b,c,d,k,s,i) \
|
|
A[a] = A[a] + ((A[b] & A[c]) | ((~A[b]) & A[d])) + X[k] + T[i]; \
|
|
A[a] = ROTL(A[a], s) + A[b]
|
|
#define PF2(a,b,c,d,k,s,i) \
|
|
A[a] = A[a] + ((A[b] & A[d]) | (A[c] & (~A[d]))) + X[k] + T[i]; \
|
|
A[a] = ROTL(A[a], s) + A[b]
|
|
#define PF3(a,b,c,d,k,s,i) \
|
|
A[a] = A[a] + (A[b] ^ A[c] ^ A[d]) + X[k] + T[i]; \
|
|
A[a] = ROTL(A[a], s) + A[b]
|
|
#define PF4(a,b,c,d,k,s,i) \
|
|
A[a] = A[a] + (A[c] ^(A[b] | (~A[d]))) + X[k] + T[i]; \
|
|
A[a] = ROTL(A[a], s) + A[b]
|
|
|
|
/* Defines for file ops */
|
|
#define MAX_FBUF 0x20000 /* file read buffer size, MUST be 64*n */
|
|
|
|
/* Static data */
|
|
static const UINT32 T[ 64 ] = {
|
|
0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE,
|
|
0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501,
|
|
0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE,
|
|
0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821,
|
|
0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA,
|
|
0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8,
|
|
0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED,
|
|
0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A,
|
|
0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C,
|
|
0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70,
|
|
0x289b7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05,
|
|
0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665,
|
|
0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039,
|
|
0x655b59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1,
|
|
0x6Fa87E4F, 0xFE2CE6e0, 0xA3014314, 0x4E0811A1,
|
|
0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391
|
|
};
|
|
|
|
static const BYTE pad[ 64 ] = {
|
|
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
};
|
|
|
|
static void hb_md5go( MD5_BUF * md5 )
|
|
{
|
|
UINT32 X[ 16 ], A[ 4 ];
|
|
BYTE * ptr;
|
|
int i;
|
|
|
|
/* copy accumulators first */
|
|
memcpy( A, md5->accum, sizeof( A ) );
|
|
|
|
/* fill buffer */
|
|
for( i = 0, ptr = md5->buf; i < 16; i++, ptr += 4 )
|
|
X[ i ] = HB_GET_LE_UINT32( ptr );
|
|
|
|
/* process buffer */
|
|
PF1( 0, 1, 2, 3, 0, 7, 0 );
|
|
PF1( 3, 0, 1, 2, 1, 12, 1 );
|
|
PF1( 2, 3, 0, 1, 2, 17, 2 );
|
|
PF1( 1, 2, 3, 0, 3, 22, 3 );
|
|
PF1( 0, 1, 2, 3, 4, 7, 4 );
|
|
PF1( 3, 0, 1, 2, 5, 12, 5 );
|
|
PF1( 2, 3, 0, 1, 6, 17, 6 );
|
|
PF1( 1, 2, 3, 0, 7, 22, 7 );
|
|
PF1( 0, 1, 2, 3, 8, 7, 8 );
|
|
PF1( 3, 0, 1, 2, 9, 12, 9 );
|
|
PF1( 2, 3, 0, 1, 10, 17, 10 );
|
|
PF1( 1, 2, 3, 0, 11, 22, 11 );
|
|
PF1( 0, 1, 2, 3, 12, 7, 12 );
|
|
PF1( 3, 0, 1, 2, 13, 12, 13 );
|
|
PF1( 2, 3, 0, 1, 14, 17, 14 );
|
|
PF1( 1, 2, 3, 0, 15, 22, 15 );
|
|
PF2( 0, 1, 2, 3, 1, 5, 16 );
|
|
PF2( 3, 0, 1, 2, 6, 9, 17 );
|
|
PF2( 2, 3, 0, 1, 11, 14, 18 );
|
|
PF2( 1, 2, 3, 0, 0, 20, 19 );
|
|
PF2( 0, 1, 2, 3, 5, 5, 20 );
|
|
PF2( 3, 0, 1, 2, 10, 9, 21 );
|
|
PF2( 2, 3, 0, 1, 15, 14, 22 );
|
|
PF2( 1, 2, 3, 0, 4, 20, 23 );
|
|
PF2( 0, 1, 2, 3, 9, 5, 24 );
|
|
PF2( 3, 0, 1, 2, 14, 9, 25 );
|
|
PF2( 2, 3, 0, 1, 3, 14, 26 );
|
|
PF2( 1, 2, 3, 0, 8, 20, 27 );
|
|
PF2( 0, 1, 2, 3, 13, 5, 28 );
|
|
PF2( 3, 0, 1, 2, 2, 9, 29 );
|
|
PF2( 2, 3, 0, 1, 7, 14, 30 );
|
|
PF2( 1, 2, 3, 0, 12, 20, 31 );
|
|
PF3( 0, 1, 2, 3, 5, 4, 32 );
|
|
PF3( 3, 0, 1, 2, 8, 11, 33 );
|
|
PF3( 2, 3, 0, 1, 11, 16, 34 );
|
|
PF3( 1, 2, 3, 0, 14, 23, 35 );
|
|
PF3( 0, 1, 2, 3, 1, 4, 36 );
|
|
PF3( 3, 0, 1, 2, 4, 11, 37 );
|
|
PF3( 2, 3, 0, 1, 7, 16, 38 );
|
|
PF3( 1, 2, 3, 0, 10, 23, 39 );
|
|
PF3( 0, 1, 2, 3, 13, 4, 40 );
|
|
PF3( 3, 0, 1, 2, 0, 11, 41 );
|
|
PF3( 2, 3, 0, 1, 3, 16, 42 );
|
|
PF3( 1, 2, 3, 0, 6, 23, 43 );
|
|
PF3( 0, 1, 2, 3, 9, 4, 44 );
|
|
PF3( 3, 0, 1, 2, 12, 11, 45 );
|
|
PF3( 2, 3, 0, 1, 15, 16, 46 );
|
|
PF3( 1, 2, 3, 0, 2, 23, 47 );
|
|
PF4( 0, 1, 2, 3, 0, 6, 48 );
|
|
PF4( 3, 0, 1, 2, 7, 10, 49 );
|
|
PF4( 2, 3, 0, 1, 14, 15, 50 );
|
|
PF4( 1, 2, 3, 0, 5, 21, 51 );
|
|
PF4( 0, 1, 2, 3, 12, 6, 52 );
|
|
PF4( 3, 0, 1, 2, 3, 10, 53 );
|
|
PF4( 2, 3, 0, 1, 10, 15, 54 );
|
|
PF4( 1, 2, 3, 0, 1, 21, 55 );
|
|
PF4( 0, 1, 2, 3, 8, 6, 56 );
|
|
PF4( 3, 0, 1, 2, 15, 10, 57 );
|
|
PF4( 2, 3, 0, 1, 6, 15, 58 );
|
|
PF4( 1, 2, 3, 0, 13, 21, 59 );
|
|
PF4( 0, 1, 2, 3, 4, 6, 60 );
|
|
PF4( 3, 0, 1, 2, 11, 10, 61 );
|
|
PF4( 2, 3, 0, 1, 2, 15, 62 );
|
|
PF4( 1, 2, 3, 0, 9, 21, 63 );
|
|
|
|
/* Update accumulators */
|
|
md5->accum[ 0 ] += A[ 0 ];
|
|
md5->accum[ 1 ] += A[ 1 ];
|
|
md5->accum[ 2 ] += A[ 2 ];
|
|
md5->accum[ 3 ] += A[ 3 ];
|
|
}
|
|
|
|
static void hb_md5accinit( UINT32 accum[] )
|
|
{
|
|
/* fill initial accumulator state */
|
|
accum[ 0 ] = 0x67452301;
|
|
accum[ 1 ] = 0xEFCDAB89;
|
|
accum[ 2 ] = 0x98BADCFE;
|
|
accum[ 3 ] = 0x10325476;
|
|
}
|
|
|
|
static void hb_md5val( UINT32 accum[], BYTE * md5val )
|
|
{
|
|
int i, n;
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
{
|
|
for( n = 0; n < 4; n++ )
|
|
*md5val++ = ( BYTE ) ( ( accum[ i ] >> ( n << 3 ) ) & 0xFF );
|
|
}
|
|
}
|
|
|
|
static void hb_md5digest( BYTE * md5val, char * digest )
|
|
{
|
|
int i, b;
|
|
|
|
for( i = 0; i < 16; i++ )
|
|
{
|
|
b = ( md5val[ i ] >> 4 ) & 0x0F;
|
|
*digest++ = ( char ) ( b + ( b > 9 ? 'a' - 10 : '0' ) );
|
|
b = md5val[ i ] & 0x0F;
|
|
*digest++ = ( char ) ( b + ( b > 9 ? 'a' - 10 : '0' ) );
|
|
}
|
|
}
|
|
|
|
void hb_md5( BYTE * ucData, ULONG ulLen, BYTE * ucDigest )
|
|
{
|
|
UCHAR buf[ 128 ];
|
|
MD5_BUF md5;
|
|
int i, n;
|
|
|
|
/* perform startup procedures */
|
|
hb_md5accinit( md5.accum );
|
|
/* count full 512bit blocks in data*/
|
|
n = ulLen >> 6;
|
|
/* process full blocks */
|
|
for( i = 0; i < n; i++, ucData += 64 )
|
|
{
|
|
memcpy( md5.buf, ucData, 64 );
|
|
hb_md5go( &md5 );
|
|
}
|
|
/* prepare additional block(s) */
|
|
n = ulLen & 63;
|
|
if( n )
|
|
memcpy( buf, ucData, n );
|
|
memcpy( buf + n, pad, 64 );
|
|
/* count bits length */
|
|
i = 56;
|
|
if( n >= 56 )
|
|
{
|
|
i += 64;
|
|
memcpy( md5.buf, buf, 64 );
|
|
hb_md5go( &md5 );
|
|
}
|
|
buf[ i++ ] = ( UCHAR ) ( ( ulLen << 3 ) & 0xF8 );
|
|
ulLen >>= 5;
|
|
for( n = 7; n; --n )
|
|
{
|
|
buf[ i++ ] = ( UCHAR ) ( ulLen & 0xFF );
|
|
ulLen >>= 8;
|
|
}
|
|
memcpy( md5.buf, buf + i - 64, 64 );
|
|
hb_md5go( &md5 );
|
|
/* write digest */
|
|
hb_md5val( md5.accum, ucDigest );
|
|
}
|
|
|
|
void hb_md5file( HB_FHANDLE hFile, BYTE * ucDigest )
|
|
{
|
|
MD5_BUF md5;
|
|
ULONG n;
|
|
int i;
|
|
HB_FOFFSET flen = 0;
|
|
UCHAR buf[ 128 ], * readbuf = ( UCHAR * ) hb_xgrab( MAX_FBUF );
|
|
|
|
hb_md5accinit( md5.accum );
|
|
n = hb_fsReadLarge( hFile, ( BYTE * ) readbuf, MAX_FBUF );
|
|
flen += n;
|
|
while( n == MAX_FBUF )
|
|
{
|
|
for( i = 0; i < ( MAX_FBUF >> 6 ); i++ )
|
|
{
|
|
memcpy( md5.buf, readbuf + ( i << 6 ), 64 );
|
|
hb_md5go( &md5 );
|
|
}
|
|
n = hb_fsReadLarge( hFile, ( BYTE * ) readbuf, MAX_FBUF );
|
|
flen += n;
|
|
}
|
|
hb_fsClose( hFile );
|
|
i = 0;
|
|
while( n > 64 )
|
|
{
|
|
memcpy( md5.buf, readbuf + i, 64 );
|
|
hb_md5go( &md5 );
|
|
i += 64;
|
|
n -= 64;
|
|
}
|
|
if( n )
|
|
memcpy( buf, readbuf + i, n );
|
|
memcpy( buf + n, pad, 64 );
|
|
i = 56;
|
|
if( n >= 56 )
|
|
{
|
|
i += 64;
|
|
memcpy( md5.buf, buf, 64 );
|
|
hb_md5go( &md5 );
|
|
}
|
|
buf[ i++ ] = ( UCHAR ) ( ( flen << 3 ) & 0xF8 );
|
|
flen >>= 5;
|
|
for( n = 7; n; --n )
|
|
{
|
|
buf[ i++ ] = ( UCHAR ) ( flen & 0xFF );
|
|
flen >>= 8;
|
|
}
|
|
memcpy( md5.buf, buf + i - 64, 64 );
|
|
hb_md5go( &md5 );
|
|
hb_md5val( md5.accum, ucDigest );
|
|
hb_xfree( readbuf );
|
|
}
|
|
|
|
HB_FUNC( HB_MD5 )
|
|
{
|
|
const char * pszStr = hb_parc( 1 );
|
|
|
|
if( pszStr )
|
|
{
|
|
ULONG ulLen = hb_parclen( 1 );
|
|
BYTE dststr[ 16 ];
|
|
char digest[ 33 ];
|
|
|
|
hb_md5( ( BYTE * ) pszStr, ulLen, dststr );
|
|
hb_md5digest( dststr, digest );
|
|
hb_retclen( digest, 32 );
|
|
}
|
|
else
|
|
hb_retc( NULL ); /* return empty string on wrong call */
|
|
}
|
|
|
|
HB_FUNC( HB_MD5FILE )
|
|
{
|
|
const char * pszFile = hb_parc( 1 );
|
|
|
|
if( pszFile )
|
|
{
|
|
HB_FHANDLE hFile = hb_fsOpen( pszFile, FO_READ );
|
|
|
|
if( hFile != FS_ERROR )
|
|
{
|
|
BYTE dststr[ 16 ];
|
|
char digest[ 33 ];
|
|
|
|
hb_md5file( hFile, dststr );
|
|
hb_md5digest( dststr, digest );
|
|
hb_retclen( digest, 32 );
|
|
return;
|
|
}
|
|
}
|
|
hb_retc( NULL ); /* return empty string on wrong call */
|
|
}
|