chiark
/
gitweb
/
~ianmdlvl
/
secnet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make-secnet-sites: Without --pubkeys-install, write appropriate key
[secnet.git]
/
md5.c
diff --git
a/md5.c
b/md5.c
index 71fb4f1272c9ad95cdf7a2e3c33b454597396bfe..ca9ddb1ad7069b4850e59e96949c1db32f62efbf 100644
(file)
--- a/
md5.c
+++ b/
md5.c
@@
-3,6
+3,7
@@
* The algorithm is due to Ron Rivest. This code was
* written by Colin Plumb in 1993, no copyright is claimed.
* This code is in the public domain; do with it what you wish.
* The algorithm is due to Ron Rivest. This code was
* written by Colin Plumb in 1993, no copyright is claimed.
* This code is in the public domain; do with it what you wish.
+ * [I interpet this as a blanket permision -iwj.]
*
* Equivalent code is available from RSA Data Security, Inc.
* This code has been tested against that, and is equivalent,
*
* Equivalent code is available from RSA Data Security, Inc.
* This code has been tested against that, and is equivalent,
@@
-21,12
+22,13
@@
*/
#include "secnet.h"
*/
#include "secnet.h"
+#include "util.h"
#include <string.h> /* for memcpy() */
#include "md5.h"
#ifdef WORDS_BIGENDIAN
static void
#include <string.h> /* for memcpy() */
#include "md5.h"
#ifdef WORDS_BIGENDIAN
static void
-byteSwap(uint32_t *buf,
unsigned
words)
+byteSwap(uint32_t *buf,
int
words)
{
md5byte *p = (md5byte *)buf;
{
md5byte *p = (md5byte *)buf;
@@
-129,7
+131,7
@@
MD5Final(md5byte digest[16], struct MD5Context *ctx)
byteSwap(ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
byteSwap(ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
- memset(ctx, 0, sizeof
(ctx)
); /* In case it's sensitive */
+ memset(ctx, 0, sizeof
*ctx
); /* In case it's sensitive */
}
#ifndef ASM_MD5
}
#ifndef ASM_MD5
@@
-237,17
+239,14
@@
MD5Transform(uint32_t buf[4], uint32_t const in[16])
#endif
#endif
-static void
*md5_init(void
)
+static void
md5_init(void *sst
)
{
{
- struct MD5Context *ctx;
+ struct MD5Context *ctx
=sst
;
- ctx=safe_malloc(sizeof(*ctx),"md5_init");
MD5Init(ctx);
MD5Init(ctx);
-
- return ctx;
}
}
-static void md5_update(void *sst,
uint8_t const *buf, u
int32_t len)
+static void md5_update(void *sst,
const void *buf,
int32_t len)
{
struct MD5Context *ctx=sst;
{
struct MD5Context *ctx=sst;
@@
-259,7
+258,6
@@
static void md5_final(void *sst, uint8_t *digest)
struct MD5Context *ctx=sst;
MD5Final(digest,ctx);
struct MD5Context *ctx=sst;
MD5Final(digest,ctx);
- free(ctx);
}
struct md5 {
}
struct md5 {
@@
-267,11
+265,9
@@
struct md5 {
struct hash_if ops;
};
struct hash_if ops;
};
-init_module md5_module;
void md5_module(dict_t *dict)
{
struct md5 *st;
void md5_module(dict_t *dict)
{
struct md5 *st;
- void *ctx;
cstring_t testinput="12345\n";
uint8_t expected[16]=
{0xd5,0x77,0x27,0x3f,0xf8,0x85,0xc3,0xf8,
cstring_t testinput="12345\n";
uint8_t expected[16]=
{0xd5,0x77,0x27,0x3f,0xf8,0x85,0xc3,0xf8,
@@
-279,21
+275,20
@@
void md5_module(dict_t *dict)
uint8_t digest[16];
int i;
uint8_t digest[16];
int i;
-
st=safe_malloc(sizeof(*st),"md5_module"
);
+
NEW(st
);
st->cl.description="md5";
st->cl.type=CL_HASH;
st->cl.apply=NULL;
st->cl.interface=&st->ops;
st->cl.description="md5";
st->cl.type=CL_HASH;
st->cl.apply=NULL;
st->cl.interface=&st->ops;
- st->ops.len=16;
+ st->ops.hlen=16;
+ st->ops.slen=sizeof(struct MD5Context);
st->ops.init=md5_init;
st->ops.update=md5_update;
st->ops.final=md5_final;
dict_add(dict,"md5",new_closure(&st->cl));
st->ops.init=md5_init;
st->ops.update=md5_update;
st->ops.final=md5_final;
dict_add(dict,"md5",new_closure(&st->cl));
- ctx=md5_init();
- md5_update(ctx,testinput,strlen(testinput));
- md5_final(ctx,digest);
+ hash_hash(&st->ops,testinput,strlen(testinput),digest);
for (i=0; i<16; i++) {
if (digest[i]!=expected[i]) {
fatal("md5 module failed self-test");
for (i=0; i<16; i++) {
if (digest[i]!=expected[i]) {
fatal("md5 module failed self-test");