|
From: <cre...@us...> - 2007-02-23 20:58:05
|
Revision: 1622
http://svn.sourceforge.net/frontierkernel/?rev=1622&view=rev
Author: creecode
Date: 2007-02-23 12:57:58 -0800 (Fri, 23 Feb 2007)
Log Message:
-----------
created md5 function, broke out from cryptfunctionvalue function case md5func
formatting tweaks
Modified Paths:
--------------
Frontier/branches/Frontier_Long_File_Paths/Common/source/langcrypt.c
Modified: Frontier/branches/Frontier_Long_File_Paths/Common/source/langcrypt.c
===================================================================
--- Frontier/branches/Frontier_Long_File_Paths/Common/source/langcrypt.c 2007-02-23 19:47:25 UTC (rev 1621)
+++ Frontier/branches/Frontier_Long_File_Paths/Common/source/langcrypt.c 2007-02-23 20:57:58 UTC (rev 1622)
@@ -62,9 +62,11 @@
static boolean cryptfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- /*
- 2006-03-07 creedon: created, cribbed from htmlfunctionvalue
- */
+ //
+ // 2006-03-10 creedon: added md5func case, cribbed from stringverbs.c
+ //
+ // 2006-03-07 creedon: created, cribbed from htmlfunctionvalue
+ //
hdltreenode hp1 = hparam1;
tyvaluerecord *v = vreturned;
@@ -129,6 +131,7 @@
}
return (true);
+
} /* whirlpoolfunc */
case hmacmd5func: { /* 2006-03-05 creedon: keyed-hashing for message authentication using md5 */
@@ -167,8 +170,10 @@
Handle hresult;
for (ix = 0; ix < 16; ix++) {
+
setstringcharacter (bs, 2 * ix, enc [(int) ((digest [ix]) / 16)]);
setstringcharacter (bs, 2 * ix + 1, enc [(int) ((digest [ix]) % 16)]);
+
} /* for */
setstringlength (bs, 32);
@@ -180,76 +185,47 @@
}
else { /* return a binary of unknown type */
+
Handle hresult;
if (!newfilledhandle (digest, 16, &hresult))
return (false);
return (setbinaryvalue (hresult, typeunknown, v));
+
}
return (true);
+
} /* hmacmd5func */
- case md5func: { /* 2006-03-10 creedon: cribbed from stringverbs.c */
- Handle x;
- MD5_CTX hashcontext; /* MD5 context. */
- unsigned char checksum [16];
- short ctconsumed = 1;
- short ctpositional = 1;
+ case md5func: {
+
+ Handle h, x;
+ boolean flHex;
+ short ctconsumed = 1, ctpositional = 1;
tyvaluerecord vtranslate;
-
- if (!getreadonlytextvalue (hp1, 1, &x))
- return (false);
+
+ if ( ! getreadonlytextvalue ( hp1, 1, &x ) )
+ return ( false );
- setbooleanvalue (true, &vtranslate);
+ setbooleanvalue ( true, &vtranslate );
flnextparamislast = true;
- if (!getoptionalparamvalue (hp1, &ctconsumed, &ctpositional, BIGSTRING ("\x0b""flTranslate"), &vtranslate))
- return (false);
-
- lockhandle (x);
-
- MD5Init (&hashcontext);
+ if ( ! getoptionalparamvalue ( hp1, &ctconsumed, &ctpositional, BIGSTRING ( "\x0b""flTranslate" ), &vtranslate ) )
+ return ( false );
+
+ if ( ! md5 ( x, vtranslate.data.flvalue, &h, &flHex ) )
+ return ( false );
+
+ if ( flHex )
+ return ( setheapvalue ( h, stringvaluetype, v ) );
+ else
+ return ( setbinaryvalue ( h, typeunknown, v ) ); // return a binary of unknown type
+
+ } // md5func
- MD5Update (&hashcontext, (unsigned char *)(*x), gethandlesize (x));
-
- MD5Final (checksum, &hashcontext);
-
- unlockhandle (x);
-
- if (vtranslate.data.flvalue) { /* return a hex string */
- bigstring bs;
- unsigned char enc [] = "0123456789abcdef";
- long ix;
- Handle h;
-
- for(ix = 0; ix < 16; ix++) {
- setstringcharacter (bs, 2 * ix, enc [(int)((checksum [ix]) / 16)]);
- setstringcharacter (bs, 2 * ix + 1, enc [(int)((checksum [ix]) % 16)]);
- } /* for */
-
- setstringlength (bs, 32);
-
- if (!newtexthandle (bs, &h))
- return (false);
-
- return (setheapvalue (h, stringvaluetype, v));
- }
-
- else { /* return a binary of unknown type */
- Handle h;
-
- if (!newfilledhandle (checksum, 16, &h))
- return (false);
-
- return (setbinaryvalue (h, typeunknown, v));
- }
-
- return (true);
- } /* md5func */
-
case sha1func: { /* 2006-03-11 creedon: SHA1 hash */
Handle h;
SHA_CTX hashcontext; /* SHA context */
@@ -307,6 +283,7 @@
}
return (true);
+
} /* sha1func */
case hmacsha1func: { /* 2006-03-11 creedon: keyed-hashing for message authentication using sha1 */
@@ -367,14 +344,17 @@
}
return (true);
+
} /* hmacsha1func */
default:
getstringlist (langerrorlist, unimplementedverberror, bserror);
return (false);
- } /* switch */
- } /* cryptfunctionvalue */
+
+ } // switch
+
+ } // cryptfunctionvalue
boolean cryptinitverbs (void) {
@@ -525,3 +505,58 @@
return (true);
} /* hmacsha1 */
+
+boolean md5 ( Handle handleText, boolean flTranslate, Handle *handleHash, boolean *flHex ) {
+
+ //
+ // 2006-12-02 creedon: broke out from cryptfunctionvalue function case md5func
+ //
+
+ MD5_CTX hashcontext; // MD5 context
+ unsigned char checksum [ 16 ];
+
+ lockhandle ( handleText );
+
+ MD5Init ( &hashcontext );
+
+ MD5Update ( &hashcontext, ( unsigned char * ) ( *handleText ), gethandlesize ( handleText ) );
+
+ MD5Final ( checksum, &hashcontext );
+
+ unlockhandle ( handleText );
+
+ if ( flTranslate ) { // return a hex string
+
+ bigstring bs;
+ long ix;
+ unsigned char enc [ ] = "0123456789abcdef";
+
+ for ( ix = 0; ix < 16; ix++ ) {
+
+ setstringcharacter ( bs, 2 * ix, enc [ ( int ) ( ( checksum [ ix ] ) / 16 ) ] );
+
+ setstringcharacter ( bs, 2 * ix + 1, enc [ ( int ) ( ( checksum [ ix ] ) % 16 ) ] );
+
+ } // for
+
+ setstringlength ( bs, 32 );
+
+ if ( ! newtexthandle ( bs, handleHash ) )
+ return ( false );
+
+ *flHex = true;
+
+ }
+ else { // return a binary of unknown type
+
+ if ( ! newfilledhandle ( checksum, 16, handleHash ) )
+ return ( false );
+
+ *flHex = false;
+
+ }
+
+ return ( true );
+
+ } // md5
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|