X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/d2aac2de9982a1969fd6699e12ef1304deaa7768..1c64c8e2eafc1085d80485dc5104a73818373773:/rmd256.h?ds=sidebyside diff --git a/rmd256.h b/rmd256.h new file mode 100644 index 00000000..cc7d4f69 --- /dev/null +++ b/rmd256.h @@ -0,0 +1,169 @@ +/* -*-c-*- + * + * $Id: rmd256.h,v 1.1 2000/07/09 21:30:31 mdw Exp $ + * + * The RIPEMD-256 message digest function + * + * (c) 1998 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of Catacomb. + * + * Catacomb is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Catacomb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with Catacomb; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: rmd256.h,v $ + * Revision 1.1 2000/07/09 21:30:31 mdw + * New RIPEMD variants. + * + */ + +/*----- Notes on the RIPEMD-256 hash function -----------------------------* + * + * RIPEMD-256 was invented by Hans Dobbertin, Antoon Bosselaers and Bart + * Preneel. It's a double-width version of RIPEMD-128, constructed simply by + * not gluing together the two parallel computations which RIPEMD-128 usually + * does in its compression function. The authors warn that, while its output + * is twice as wide as that of RIPEMD-128, they don't expect it to offer any + * more security. + */ + +#ifndef CATACOMB_RMD256_H +#define CATACOMB_RMD256_H + +#ifdef __cplusplus + extern "C" { +#endif + +/*----- Header files ------------------------------------------------------*/ + +#include + +#ifndef CATACOMB_GHASH_H +# include "ghash.h" +#endif + +/*----- Magic numbers -----------------------------------------------------*/ + +#define RMD256_BUFSZ 64 +#define RMD256_HASHSZ 32 + +/*----- Data structures ---------------------------------------------------*/ + +typedef struct rmd256_ctx { + uint32 a, b, c, d; /* Chaining variables */ + uint32 A, B, C, D; /* More chaining variables */ + uint32 nl, nh; /* Byte count so far */ + unsigned off; /* Offset into buffer */ + octet buf[RMD256_BUFSZ]; /* Accumulation buffer */ +} rmd256_ctx; + +/*----- Functions provided ------------------------------------------------*/ + +/* --- @rmd256_compress@ --- * + * + * Arguments: @rmd256_ctx *ctx@ = pointer to context block + * @const void *sbuf@ = pointer to buffer of appropriate size + * + * Returns: --- + * + * Use: RIPEMD-256 compression function. + */ + +extern void rmd256_compress(rmd256_ctx */*ctx*/, const void */*sbuf*/); + +/* --- @rmd256_init@ --- * + * + * Arguments: @rmd256_ctx *ctx@ = pointer to context block to initialize + * + * Returns: --- + * + * Use: Initializes a context block ready for hashing. + */ + +extern void rmd256_init(rmd256_ctx */*ctx*/); + +/* --- @rmd256_set@ --- * + * + * Arguments: @rmd256_ctx *ctx@ = pointer to context block + * @const void *buf@ = pointer to state buffer + * @unsigned long count@ = current count of bytes processed + * + * Returns: --- + * + * Use: Initializes a context block from a given state. This is + * useful in cases where the initial hash state is meant to be + * secret, e.g., for NMAC and HMAC support. + */ + +extern void rmd256_set(rmd256_ctx */*ctx*/, + const void */*buf*/, unsigned long /*count*/); + +/* --- @rmd256_hash@ --- * + * + * Arguments: @rmd256_ctx *ctx@ = pointer to context block + * @const void *buf@ = buffer of data to hash + * @size_t sz@ = size of buffer to hash + * + * Returns: --- + * + * Use: Hashes a buffer of data. The buffer may be of any size and + * alignment. + */ + +extern void rmd256_hash(rmd256_ctx */*ctx*/, + const void */*buf*/, size_t /*sz*/); + +/* --- @rmd256_done@ --- * + * + * Arguments: @rmd256_ctx *ctx@ = pointer to context block + * @void *hash@ = pointer to output buffer + * + * Returns: --- + * + * Use: Returns the hash of the data read so far. + */ + +extern void rmd256_done(rmd256_ctx */*ctx*/, void */*hash*/); + +/* --- @rmd256_state@ --- * + * + * Arguments: @rmd256_ctx *ctx@ = pointer to context + * @void *state@ = pointer to buffer for current state + * + * Returns: Number of bytes written to the hash function so far. + * + * Use: Returns the current state of the hash function such that + * it can be passed to @rmd256_set@. + */ + +extern unsigned long rmd256_state(rmd256_ctx */*ctx*/, void */*state*/); + +/*----- Generic hash interface --------------------------------------------*/ + +extern const gchash rmd256; + +/*----- That's all, folks -------------------------------------------------*/ + +#ifdef __cplusplus + } +#endif + +#endif