summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-08-29 18:42:26 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-09-01 22:44:45 -0400
commit9acba78004d4d4a149b9e1480d1d8c44b7a27cec (patch)
tree3bea723ccd1cccf43f9fcce550addb3c2c36da14 /libraries
parentcfab4abeaffa8b6a78a19bbfa485169a9c772741 (diff)
downloadhaskell-9acba78004d4d4a149b9e1480d1d8c44b7a27cec.tar.gz
Use C99 Fixed width types to avoid hack in base's configure
Define MD5Context in terms of `uint*_t` and don't use `HsFFI.h`.
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/cbits/md5.c30
-rw-r--r--libraries/base/configure.ac2
-rw-r--r--libraries/base/include/md5.h17
3 files changed, 22 insertions, 27 deletions
diff --git a/libraries/base/cbits/md5.c b/libraries/base/cbits/md5.c
index 0c019be290..0d93a8f1f1 100644
--- a/libraries/base/cbits/md5.c
+++ b/libraries/base/cbits/md5.c
@@ -20,9 +20,9 @@
#include <string.h>
void __hsbase_MD5Init(struct MD5Context *context);
-void __hsbase_MD5Update(struct MD5Context *context, byte const *buf, int len);
-void __hsbase_MD5Final(byte digest[16], struct MD5Context *context);
-void __hsbase_MD5Transform(word32 buf[4], word32 const in[16]);
+void __hsbase_MD5Update(struct MD5Context *context, uint8_t const *buf, int len);
+void __hsbase_MD5Final(uint8_t digest[16], struct MD5Context *context);
+void __hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16]);
/*
@@ -30,12 +30,12 @@ void __hsbase_MD5Transform(word32 buf[4], word32 const in[16]);
* MD5 spec. Note: this code works regardless of the byte order.
*/
static void
-byteSwap(word32 *buf, unsigned words)
+byteSwap(uint32_t *buf, unsigned words)
{
- byte *p = (byte *)buf;
+ uint8_t *p = (uint8_t *)buf;
do {
- *buf++ = (word32)((unsigned)p[3] << 8 | p[2]) << 16 |
+ *buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 |
((unsigned)p[1] << 8 | p[0]);
p += 4;
} while (--words);
@@ -62,9 +62,9 @@ __hsbase_MD5Init(struct MD5Context *ctx)
* of bytes.
*/
void
-__hsbase_MD5Update(struct MD5Context *ctx, byte const *buf, int len)
+__hsbase_MD5Update(struct MD5Context *ctx, uint8_t const *buf, int len)
{
- word32 t;
+ uint32_t t;
/* Update byte count */
@@ -74,11 +74,11 @@ __hsbase_MD5Update(struct MD5Context *ctx, byte const *buf, int len)
t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
if ((unsigned)t > len) {
- memcpy((byte *)ctx->in + 64 - (unsigned)t, buf, len);
+ memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, len);
return;
}
/* First chunk is an odd size */
- memcpy((byte *)ctx->in + 64 - (unsigned)t, buf, (unsigned)t);
+ memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, (unsigned)t);
byteSwap(ctx->in, 16);
__hsbase_MD5Transform(ctx->buf, ctx->in);
buf += (unsigned)t;
@@ -102,10 +102,10 @@ __hsbase_MD5Update(struct MD5Context *ctx, byte const *buf, int len)
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void
-__hsbase_MD5Final(byte digest[16], struct MD5Context *ctx)
+__hsbase_MD5Final(uint8_t digest[16], struct MD5Context *ctx)
{
int count = (int)(ctx->bytes[0] & 0x3f); /* Bytes in ctx->in */
- byte *p = (byte *)ctx->in + count; /* First unused byte */
+ uint8_t *p = (uint8_t *)ctx->in + count; /* First unused byte */
/* Set the first char of padding to 0x80. There is always room. */
*p++ = 0x80;
@@ -117,7 +117,7 @@ __hsbase_MD5Final(byte digest[16], struct MD5Context *ctx)
memset(p, 0, count+8);
byteSwap(ctx->in, 16);
__hsbase_MD5Transform(ctx->buf, ctx->in);
- p = (byte *)ctx->in;
+ p = (uint8_t *)ctx->in;
count = 56;
}
memset(p, 0, count+8);
@@ -153,9 +153,9 @@ __hsbase_MD5Final(byte digest[16], struct MD5Context *ctx)
*/
void
-__hsbase_MD5Transform(word32 buf[4], word32 const in[16])
+__hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16])
{
- register word32 a, b, c, d;
+ register uint32_t a, b, c, d;
a = buf[0];
b = buf[1];
diff --git a/libraries/base/configure.ac b/libraries/base/configure.ac
index a141a25a90..0fe2ca52c2 100644
--- a/libraries/base/configure.ac
+++ b/libraries/base/configure.ac
@@ -233,8 +233,6 @@ AS_IF([test "x$with_libcharset" != xno],
fi
-# Hack - md5.h needs HsFFI.h. Is there a better way to do this?
-CFLAGS="-I../.. -I../../../../includes $CFLAGS"
dnl Calling AC_CHECK_TYPE(T) makes AC_CHECK_SIZEOF(T) abort on failure
dnl instead of considering sizeof(T) as 0.
AC_CHECK_TYPE([struct MD5Context], [], [AC_MSG_ERROR([internal error])], [#include "include/md5.h"])
diff --git a/libraries/base/include/md5.h b/libraries/base/include/md5.h
index a1b6157075..8d3441617a 100644
--- a/libraries/base/include/md5.h
+++ b/libraries/base/include/md5.h
@@ -1,18 +1,15 @@
/* MD5 message digest */
#pragma once
-#include "HsFFI.h"
-
-typedef HsWord32 word32;
-typedef HsWord8 byte;
+#include <stdint.h>
struct MD5Context {
- word32 buf[4];
- word32 bytes[2];
- word32 in[16];
+ uint32_t buf[4];
+ uint32_t bytes[2];
+ uint32_t in[16];
};
void __hsbase_MD5Init(struct MD5Context *context);
-void __hsbase_MD5Update(struct MD5Context *context, byte const *buf, int len);
-void __hsbase_MD5Final(byte digest[16], struct MD5Context *context);
-void __hsbase_MD5Transform(word32 buf[4], word32 const in[16]);
+void __hsbase_MD5Update(struct MD5Context *context, uint8_t const *buf, int len);
+void __hsbase_MD5Final(uint8_t digest[16], struct MD5Context *context);
+void __hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16]);