From f2e4bb875741843f17c0061756e4aea56968ec21 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 19 Jan 2011 17:21:07 -0700 Subject: [PATCH] Add arc4 hashing --- include/arc4.c | 13 +++++++++++++ include/arc4.h | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/arc4.c b/include/arc4.c index 63306ad..32d706b 100644 --- a/include/arc4.c +++ b/include/arc4.c @@ -51,3 +51,16 @@ arc4_crypt_buffer(uint8_t const *key, size_t keylen, arc4_init(&ctx, key, keylen); arc4_crypt(&ctx, buf, buf, buflen); } + +void +arc4_hash(uint8_t const *buf, size_t buflen, + uint8_t *hash) +{ + struct arc4_ctx ctx; + int i; + + arc4_init(&ctx, buf, buflen); + for (i = 0; i < ARC4_HASHLEN; i += 1) { + hash[i] = arc4_pad(&ctx); + } +} diff --git a/include/arc4.h b/include/arc4.h index 7aa7428..c917184 100644 --- a/include/arc4.h +++ b/include/arc4.h @@ -4,6 +4,8 @@ #include #include +#define ARC4_HASHLEN 16 + struct arc4_ctx { uint8_t S[256]; uint8_t i; @@ -16,5 +18,6 @@ void arc4_crypt(struct arc4_ctx *ctx, uint8_t *obuf, uint8_t const *ibuf, size_t buflen); void arc4_crypt_buffer(uint8_t const *key, size_t keylen, uint8_t *buf, size_t buflen); - +void arc4_hash(uint8_t const *buf, size_t buflen, + uint8_t *hash); #endif