Import MD5 support, Macs are weird

This commit is contained in:
Vítor Santos Costa 2015-11-05 15:38:39 +00:00
parent df26a7a84a
commit b0f3cda2d7
3 changed files with 39 additions and 15 deletions

View File

@ -94,7 +94,6 @@
CHTYPE_MODULE = AtomTermAdjust(CHTYPE_MODULE); CHTYPE_MODULE = AtomTermAdjust(CHTYPE_MODULE);
TERMS_MODULE = AtomTermAdjust(TERMS_MODULE); TERMS_MODULE = AtomTermAdjust(TERMS_MODULE);
SYSTEM_MODULE = AtomTermAdjust(SYSTEM_MODULE); SYSTEM_MODULE = AtomTermAdjust(SYSTEM_MODULE);
OPERATING_SYSTEM_MODULE = AtomTermAdjust(OPERATING_SYSTEM_MODULE);
READUTIL_MODULE = AtomTermAdjust(READUTIL_MODULE); READUTIL_MODULE = AtomTermAdjust(READUTIL_MODULE);
HACKS_MODULE = AtomTermAdjust(HACKS_MODULE); HACKS_MODULE = AtomTermAdjust(HACKS_MODULE);
ARG_MODULE = AtomTermAdjust(ARG_MODULE); ARG_MODULE = AtomTermAdjust(ARG_MODULE);

View File

@ -89,6 +89,7 @@
#include "config.h" #include "config.h"
#include "YapInterface.h" #include "YapInterface.h"
#include "crypto/md5.h"
#include <stdlib.h> #include <stdlib.h>
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
@ -1076,24 +1077,48 @@ p_kill(void)
/** md5( +Text, -Key, -Remaining keyq /** md5( +Text, -Key, -Remaining keyq
* encode text using OpenSSL * encode text using OpenSSL
* *
* arg Text as List of codes * arg Text is a List of ASCII codes
* arg2 and 3: difference list with character codes. * arg2 and 3: difference list with the character codes for the
* digest.
* *
* @return whether ARG1's md5 unifies with the difference liat. * @return whether ARG1's md5 unifies with the difference liat.
*/ */
static YAP_Bool static YAP_Bool
md5(void) md5(void)
{ {
#if HAVE_OPENSSL_RIPEMD_H unsigned char buf[64];
char buf[21]; md5_state_t pms;
const char *s;
size_t len = -1;
char *s = (char *) YAP_AllocSpaceFromYap(YAP_ListLength(YAP_ARG1)+1); if ( ! (s = YAP_StringToBuffer( YAP_ARG1 , NULL, len )) ||
YAP_StringToBuffer( YAP_ARG1 , s, 20 ) ; s[0] == 0)
RIPEMD160((const unsigned char *)s, strlen(s), (unsigned char *)buf); return false;
YAP_FreeSpaceFromYap(s);
return YAP_Unify( YAP_ARG2, YAP_BufferToDiffList( buf , YAP_ARG3 ) ); md5_init( & pms );
#endif /* defined(__MINGW32__) || _MSC_VER */ md5_append( & pms, (const unsigned char *)s, strlen(s));
return FALSE; md5_finish( & pms, buf );
//free((void *)s);
YAP_Term t = YAP_ARG3;
int i = 16;
while (i > 0)
{
int top, bop;
i--;
top = buf[i]>>4;
if (top > 9)
top = (top-10)+'a';
else
top = top+'0';
bop = buf[i] & 15;
if (bop > 9)
bop = (bop-10)+'a';
else
bop = bop+'0';
t = YAP_MkPairTerm(YAP_MkIntTerm(top),
YAP_MkPairTerm( YAP_MkIntTerm( bop ), t ));
}
return YAP_Unify( YAP_ARG2,t );
} }
static YAP_Bool static YAP_Bool
@ -1159,3 +1184,4 @@ int WINAPI win_sys(HANDLE hinst, DWORD reason, LPVOID reserved)
return 1; return 1;
} }
#endif #endif

View File

@ -97,7 +97,6 @@ Term charsio_module CHARSIO_MODULE MkAT AtomCharsio
Term chtype_module CHTYPE_MODULE MkAT AtomChType Term chtype_module CHTYPE_MODULE MkAT AtomChType
Term terms_module TERMS_MODULE MkAT AtomTerms Term terms_module TERMS_MODULE MkAT AtomTerms
Term system_module SYSTEM_MODULE MkAT AtomSystem Term system_module SYSTEM_MODULE MkAT AtomSystem
Term operating_system_module OPERATING_SYSTEM_MODULE MkAT AtomOperatingSystemSupport
Term readutil_module READUTIL_MODULE MkAT AtomReadutil Term readutil_module READUTIL_MODULE MkAT AtomReadutil
Term hacks_module HACKS_MODULE MkAT AtomYapHacks Term hacks_module HACKS_MODULE MkAT AtomYapHacks
Term arg_module ARG_MODULE MkAT AtomArg Term arg_module ARG_MODULE MkAT AtomArg