X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d03ab969116fe715d569304c1c474749b2f64529..813390c45f438f411662b1a55678e63f11681eb4:/sha.c diff --git a/sha.c b/sha.c index a5a3bf3..157b81b 100644 --- a/sha.c +++ b/sha.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: sha.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: sha.c,v 1.4 2004/04/08 01:36:15 mdw Exp $ * * Implementation of the SHA-1 hash function * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,30 +15,24 @@ * 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: sha.c,v $ - * Revision 1.1 1999/09/03 08:41:12 mdw - * Initial import. - * - */ - /*----- Header files ------------------------------------------------------*/ #include +#include "ghash.h" +#include "ghash-def.h" #include "hash.h" #include "sha.h" @@ -209,7 +203,7 @@ void sha_init(sha_ctx *ctx) ctx->d = 0x10325476; ctx->e = 0xc3d2e1f0; ctx->off = 0; - ctx->count = 0; + ctx->nl = ctx->nh = 0; } /* --- @sha_set@ --- * @@ -234,7 +228,8 @@ void sha_set(sha_ctx *ctx, const void *buf, unsigned long count) ctx->d = LOAD32(p + 12); ctx->e = LOAD32(p + 16); ctx->off = 0; - ctx->count = count; + ctx->nl = U32(count); + ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); } /* --- @sha_hash@ --- * @@ -268,8 +263,8 @@ void sha_done(sha_ctx *ctx, void *hash) { octet *p = hash; HASH_PAD(SHA, sha, ctx, 0x80, 0, 8); - STORE32(ctx->buf + SHA_BUFSZ - 8, ctx->count >> 29); - STORE32(ctx->buf + SHA_BUFSZ - 4, ctx->count << 3); + STORE32(ctx->buf + SHA_BUFSZ - 8, (ctx->nl >> 29) | (ctx->nh << 3)); + STORE32(ctx->buf + SHA_BUFSZ - 4, ctx->nl << 3); sha_compress(ctx, ctx->buf); STORE32(p + 0, ctx->a); STORE32(p + 4, ctx->b); @@ -297,9 +292,13 @@ unsigned long sha_state(sha_ctx *ctx, void *state) STORE32(p + 8, ctx->c); STORE32(p + 12, ctx->d); STORE32(p + 16, ctx->e); - return (ctx->count); + return (ctx->nl | ((ctx->nh << 16) << 16)); } +/* --- Generic interface --- */ + +GHASH_DEF(SHA, sha) + /* --- Test code --- */ HASH_TEST(SHA, sha)