| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: has160.h,v 1.2 2004/04/08 01:36:15 mdw Exp $ |
| 4 | * |
| 5 | * The HAS160 message digest function |
| 6 | * |
| 7 | * (c) 2004 Straylight/Edgeware |
| 8 | */ |
| 9 | |
| 10 | /*----- Licensing notice --------------------------------------------------* |
| 11 | * |
| 12 | * This file is part of Catacomb. |
| 13 | * |
| 14 | * Catacomb is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU Library General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of the |
| 17 | * License, or (at your option) any later version. |
| 18 | * |
| 19 | * Catacomb is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU Library General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU Library General Public |
| 25 | * License along with Catacomb; if not, write to the Free |
| 26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 27 | * MA 02111-1307, USA. |
| 28 | */ |
| 29 | |
| 30 | /*----- Notes on the HAS160 hash function ---------------------------------* |
| 31 | * |
| 32 | * HAS160 was designed by Chae Hoon Lim and the Korean Information Security |
| 33 | * Agency (KISA). It's recommended for use with KCDSA (though I think I'm |
| 34 | * happer with RIPEMD-160 or SHA1). It's here so I can check KCDSA test |
| 35 | * vectors. |
| 36 | */ |
| 37 | |
| 38 | #ifndef CATACOMB_HAS160_H |
| 39 | #define CATACOMB_HAS160_H |
| 40 | |
| 41 | #ifdef __cplusplus |
| 42 | extern "C" { |
| 43 | #endif |
| 44 | |
| 45 | /*----- Header files ------------------------------------------------------*/ |
| 46 | |
| 47 | #include <mLib/bits.h> |
| 48 | |
| 49 | #ifndef CATACOMB_GHASH_H |
| 50 | # include "ghash.h" |
| 51 | #endif |
| 52 | |
| 53 | /*----- Magic numbers -----------------------------------------------------*/ |
| 54 | |
| 55 | #define HAS160_BUFSZ 64 |
| 56 | #define HAS160_HASHSZ 20 |
| 57 | #define HAS160_STATESZ 20 |
| 58 | |
| 59 | /*----- Data structures ---------------------------------------------------*/ |
| 60 | |
| 61 | typedef struct has160_ctx { |
| 62 | uint32 a, b, c, d, e; /* Chaining variables */ |
| 63 | uint32 nl, nh; /* Byte count so far */ |
| 64 | unsigned off; /* Offset into buffer */ |
| 65 | octet buf[HAS160_BUFSZ]; /* Accumulation buffer */ |
| 66 | } has160_ctx; |
| 67 | |
| 68 | /*----- Functions provided ------------------------------------------------*/ |
| 69 | |
| 70 | /* --- @has160_compress@ --- * |
| 71 | * |
| 72 | * Arguments: @has160_ctx *ctx@ = pointer to context block |
| 73 | * @const void *sbuf@ = pointer to buffer of appropriate size |
| 74 | * |
| 75 | * Returns: --- |
| 76 | * |
| 77 | * Use: HAS160 compression function. |
| 78 | */ |
| 79 | |
| 80 | extern void has160_compress(has160_ctx */*ctx*/, const void */*sbuf*/); |
| 81 | |
| 82 | /* --- @has160_init@ --- * |
| 83 | * |
| 84 | * Arguments: @has160_ctx *ctx@ = pointer to context block to initialize |
| 85 | * |
| 86 | * Returns: --- |
| 87 | * |
| 88 | * Use: Initializes a context block ready for hashing. |
| 89 | */ |
| 90 | |
| 91 | extern void has160_init(has160_ctx */*ctx*/); |
| 92 | |
| 93 | /* --- @has160_set@ --- * |
| 94 | * |
| 95 | * Arguments: @has160_ctx *ctx@ = pointer to context block |
| 96 | * @const void *buf@ = pointer to state buffer |
| 97 | * @unsigned long count@ = current count of bytes processed |
| 98 | * |
| 99 | * Returns: --- |
| 100 | * |
| 101 | * Use: Initializes a context block from a given state. This is |
| 102 | * useful in cases where the initial hash state is meant to be |
| 103 | * secret, e.g., for NMAC and HMAC support. |
| 104 | */ |
| 105 | |
| 106 | extern void has160_set(has160_ctx */*ctx*/, const void */*buf*/, |
| 107 | unsigned long /*count*/); |
| 108 | |
| 109 | /* --- @has160_hash@ --- * |
| 110 | * |
| 111 | * Arguments: @has160_ctx *ctx@ = pointer to context block |
| 112 | * @const void *buf@ = buffer of data to hash |
| 113 | * @size_t sz@ = size of buffer to hash |
| 114 | * |
| 115 | * Returns: --- |
| 116 | * |
| 117 | * Use: Hashes a buffer of data. The buffer may be of any size and |
| 118 | * alignment. |
| 119 | */ |
| 120 | |
| 121 | extern void has160_hash(has160_ctx */*ctx*/, |
| 122 | const void */*buf*/, size_t /*sz*/); |
| 123 | |
| 124 | /* --- @has160_done@ --- * |
| 125 | * |
| 126 | * Arguments: @has160_ctx *ctx@ = pointer to context block |
| 127 | * @void *hash@ = pointer to output buffer |
| 128 | * |
| 129 | * Returns: --- |
| 130 | * |
| 131 | * Use: Returns the hash of the data read so far. |
| 132 | */ |
| 133 | |
| 134 | extern void has160_done(has160_ctx */*ctx*/, void */*hash*/); |
| 135 | |
| 136 | /* --- @has160_state@ --- * |
| 137 | * |
| 138 | * Arguments: @has160_ctx *ctx@ = pointer to context |
| 139 | * @void *state@ = pointer to buffer for current state |
| 140 | * |
| 141 | * Returns: Number of bytes written to the hash function so far. |
| 142 | * |
| 143 | * Use: Returns the current state of the hash function such that |
| 144 | * it can be passed to @has160_set@. |
| 145 | */ |
| 146 | |
| 147 | extern unsigned long has160_state(has160_ctx */*ctx*/, void */*state*/); |
| 148 | |
| 149 | /*----- Generic hash interface --------------------------------------------*/ |
| 150 | |
| 151 | extern const gchash has160; |
| 152 | |
| 153 | /*----- That's all, folks -------------------------------------------------*/ |
| 154 | |
| 155 | #ifdef __cplusplus |
| 156 | } |
| 157 | #endif |
| 158 | |
| 159 | #endif |