[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS shishi/gl
From: |
shishi-commit |
Subject: |
CVS shishi/gl |
Date: |
Sun, 23 Oct 2005 22:53:39 +0200 |
Update of /home/cvs/shishi/gl
In directory dopio:/tmp/cvs-serv27641/gl
Modified Files:
gc-gnulib.c md4.h md5.c md5.h
Log Message:
Update.
--- /home/cvs/shishi/gl/gc-gnulib.c 2005/10/22 15:54:48 1.2
+++ /home/cvs/shishi/gl/gc-gnulib.c 2005/10/23 20:53:39 1.3
@@ -537,6 +537,195 @@
/* Hashes. */
+#define MAX_DIGEST_SIZE 20
+
+typedef struct _gc_hash_ctx {
+ Gc_hash alg;
+ Gc_hash_mode mode;
+ char hash[MAX_DIGEST_SIZE];
+#ifdef GC_USE_MD5
+ struct md5_ctx md5Context;
+#endif
+#ifdef GC_USE_MD4
+ struct md4_ctx md4Context;
+#endif
+#ifdef GC_USE_SHA1
+ struct sha1_ctx sha1Context;
+#endif
+} _gc_hash_ctx;
+
+Gc_rc
+gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
+{
+ _gc_hash_ctx *ctx;
+ Gc_rc rc = GC_OK;
+
+ ctx = calloc (sizeof (*ctx), 1);
+
+ ctx->alg = hash;
+ ctx->mode = mode;
+
+ switch (hash)
+ {
+#ifdef GC_USE_MD4
+ case GC_MD4:
+ md4_init_ctx (&ctx->md4Context);
+ break;
+#endif
+
+#ifdef GC_USE_MD5
+ case GC_MD5:
+ md5_init_ctx (&ctx->md5Context);
+ break;
+#endif
+
+#ifdef GC_USE_SHA1
+ case GC_SHA1:
+ sha1_init_ctx (&ctx->sha1Context);
+ break;
+#endif
+
+ default:
+ rc = GC_INVALID_HASH;
+ break;
+ }
+
+ switch (mode)
+ {
+ case 0:
+ break;
+
+ default:
+ rc = GC_INVALID_HASH;
+ break;
+ }
+
+ if (rc == GC_OK)
+ *outhandle = ctx;
+ else
+ free (ctx);
+
+ return GC_OK;
+}
+
+Gc_rc
+gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
+{
+ _gc_hash_ctx *in = handle;
+ _gc_hash_ctx *out;
+ Gc_rc rc = GC_OK;
+
+ *outhandle = out = calloc (sizeof (*out), 1);
+ if (!out)
+ return GC_MALLOC_ERROR;
+
+ memcpy (out, in, sizeof (*out));
+
+ return GC_OK;
+}
+
+size_t
+gc_hash_digest_length (Gc_hash hash)
+{
+ size_t len;
+
+ switch (hash)
+ {
+ case GC_MD4:
+ len = GC_MD4_DIGEST_SIZE;
+ break;
+
+ case GC_MD5:
+ len = GC_MD5_DIGEST_SIZE;
+ break;
+
+ case GC_SHA1:
+ len = GC_SHA1_DIGEST_SIZE;
+ break;
+
+ default:
+ return 0;
+ }
+
+ return len;
+}
+
+void
+gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
+{
+ _gc_hash_ctx *ctx = handle;
+ Gc_rc rc = GC_OK;
+
+ switch (ctx->alg)
+ {
+#ifdef GC_USE_MD4
+ case GC_MD4:
+ md4_process_bytes (data, len, &ctx->md4Context);
+ break;
+#endif
+
+#ifdef GC_USE_MD5
+ case GC_MD5:
+ md5_process_bytes (data, len, &ctx->md5Context);
+ break;
+#endif
+
+#ifdef GC_USE_SHA1
+ case GC_SHA1:
+ sha1_process_bytes (data, len, &ctx->sha1Context);
+ break;
+#endif
+
+ default:
+ break;
+ }
+}
+
+const char *
+gc_hash_read (gc_hash_handle handle)
+{
+ _gc_hash_ctx *ctx = handle;
+ const char *ret = NULL;
+ Gc_rc rc;
+
+ switch (ctx->alg)
+ {
+#ifdef GC_USE_MD4
+ case GC_MD4:
+ md4_finish_ctx (&ctx->md4Context, ctx->hash);
+ ret = ctx->hash;
+ break;
+#endif
+
+#ifdef GC_USE_MD5
+ case GC_MD5:
+ md5_finish_ctx (&ctx->md5Context, ctx->hash);
+ ret = ctx->hash;
+ break;
+#endif
+
+#ifdef GC_USE_SHA1
+ case GC_SHA1:
+ sha1_finish_ctx (&ctx->sha1Context, ctx->hash);
+ ret = ctx->hash;
+ break;
+#endif
+
+ default:
+ return NULL;
+ }
+
+ return ret;
+}
+
+void
+gc_hash_close (gc_hash_handle handle)
+{
+ _gc_hash_ctx *ctx = handle;
+
+ free (ctx);
+}
+
Gc_rc
gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
{
--- /home/cvs/shishi/gl/md4.h 2005/10/22 15:54:48 1.1
+++ /home/cvs/shishi/gl/md4.h 2005/10/23 20:53:39 1.2
@@ -34,7 +34,7 @@
uint32_t total[2];
uint32_t buflen;
- uint32_t buffer[128];
+ uint32_t buffer[32];
};
--- /home/cvs/shishi/gl/md5.c 2005/10/22 15:54:48 1.1
+++ /home/cvs/shishi/gl/md5.c 2005/10/23 20:53:39 1.2
@@ -116,12 +116,12 @@
++ctx->total[1];
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
- memcpy (&ctx->buffer[bytes], fillbuf, pad);
+ memcpy (&((char*)ctx->buffer)[bytes], fillbuf, pad);
/* Put the 64-bit file length in *bits* at the end of the buffer. */
- *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
- *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
- (ctx->total[0] >> 29));
+ ctx->buffer[(bytes + pad) / 4] = SWAP (ctx->total[0] << 3);
+ ctx->buffer[(bytes + pad) / 4 + 1] = SWAP ((ctx->total[1] << 3) |
+ (ctx->total[0] >> 29));
/* Process last bytes. */
md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
@@ -225,7 +225,7 @@
size_t left_over = ctx->buflen;
size_t add = 128 - left_over > len ? len : 128 - left_over;
- memcpy (&ctx->buffer[left_over], buffer, add);
+ memcpy (&((char*)ctx->buffer)[left_over], buffer, add);
ctx->buflen += add;
if (ctx->buflen > 64)
@@ -234,7 +234,7 @@
ctx->buflen &= 63;
/* The regions in the following copy operation cannot overlap. */
- memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
+ memcpy (ctx->buffer, &((char*)ctx->buffer)[(left_over + add) & ~63],
ctx->buflen);
}
@@ -275,13 +275,13 @@
{
size_t left_over = ctx->buflen;
- memcpy (&ctx->buffer[left_over], buffer, len);
+ memcpy (&((char*)ctx->buffer)[left_over], buffer, len);
left_over += len;
if (left_over >= 64)
{
md5_process_block (ctx->buffer, 64, ctx);
left_over -= 64;
- memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+ memcpy (ctx->buffer, &ctx->buffer[16], left_over);
}
ctx->buflen = left_over;
}
--- /home/cvs/shishi/gl/md5.h 2005/10/22 15:55:03 1.1
+++ /home/cvs/shishi/gl/md5.h 2005/10/23 20:53:39 1.2
@@ -70,7 +70,7 @@
uint32_t total[2];
uint32_t buflen;
- char buffer[128] __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
+ uint32_t buffer[32];
};
/*
- CVS shishi/gl, shishi-commit, 2005/10/12
- CVS shishi/gl, shishi-commit, 2005/10/22
- CVS shishi/gl, shishi-commit, 2005/10/22
- CVS shishi/gl, shishi-commit, 2005/10/22
- CVS shishi/gl, shishi-commit, 2005/10/22
- CVS shishi/gl, shishi-commit, 2005/10/22
- CVS shishi/gl, shishi-commit, 2005/10/22
- CVS shishi/gl,
shishi-commit <=