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

@ -40,7 +40,7 @@
#endif
#if USE_DL_MALLOC || (USE_SYSTEM_MALLOC && HAVE_MALLINFO)
#ifndef HeapUsed
#define HeapUsed Yap_givemallinfo()
#define HeapUsed Yap_givemallinfo()
#endif
#else
@ -94,7 +94,6 @@
CHTYPE_MODULE = AtomTermAdjust(CHTYPE_MODULE);
TERMS_MODULE = AtomTermAdjust(TERMS_MODULE);
SYSTEM_MODULE = AtomTermAdjust(SYSTEM_MODULE);
OPERATING_SYSTEM_MODULE = AtomTermAdjust(OPERATING_SYSTEM_MODULE);
READUTIL_MODULE = AtomTermAdjust(READUTIL_MODULE);
HACKS_MODULE = AtomTermAdjust(HACKS_MODULE);
ARG_MODULE = AtomTermAdjust(ARG_MODULE);

View File

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

View File

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