-/* ripemd160.c
+/* ripemd160.c - RIPE-MD160 */
- RIPE-MD160
-
- Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
- Copyright (C) 2011 Niels Möller
-
- This file is part of GNU Nettle.
-
- GNU Nettle is free software: you can redistribute it and/or
- modify it under the terms of either:
-
- * the GNU Lesser General Public License as published by the Free
- Software Foundation; either version 3 of the License, or (at your
- option) any later version.
-
- or
-
- * the GNU General Public License as published by the Free
- Software Foundation; either version 2 of the License, or (at your
- option) any later version.
-
- or both in parallel, as here.
-
- GNU Nettle 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
- General Public License for more details.
-
- You should have received copies of the GNU General Public License and
- the GNU Lesser General Public License along with this program. If
- not, see http://www.gnu.org/licenses/.
-*/
+/* nettle, low-level cryptographics library
+ *
+ * Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2011 Niels Möller
+ *
+ * The nettle library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The nettle library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the nettle library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02111-1301, USA.
+ */
#if HAVE_CONFIG_H
# include "config.h"
0xC3D2E1F0,
};
memcpy(ctx->state, iv, sizeof(ctx->state));
- ctx->count = 0;
+ ctx->count_low = ctx->count_high = 0;
ctx->index = 0;
}
* of DATA with length LENGTH.
*/
void
-ripemd160_update(struct ripemd160_ctx *ctx, size_t length, const uint8_t *data)
+ripemd160_update(struct ripemd160_ctx *ctx, unsigned length, const uint8_t *data)
{
- MD_UPDATE(ctx, length, data, COMPRESS, ctx->count++);
+ MD_UPDATE(ctx, length, data, COMPRESS, MD_INCR(ctx));
}
void
-ripemd160_digest(struct ripemd160_ctx *ctx, size_t length, uint8_t *digest)
+ripemd160_digest(struct ripemd160_ctx *ctx, unsigned length, uint8_t *digest)
{
- uint64_t bit_count;
+ uint32_t high, low;
assert(length <= RIPEMD160_DIGEST_SIZE);
MD_PAD(ctx, 8, COMPRESS);
/* There are 2^9 bits in one block */
- bit_count = (ctx->count << 9) | (ctx->index << 3);
+ high = (ctx->count_high << 9) | (ctx->count_low >> 23);
+ low = (ctx->count_low << 9) | (ctx->index << 3);
\
/* append the 64 bit count */
- LE_WRITE_UINT64(ctx->block + 56, bit_count);
+ LE_WRITE_UINT32(ctx->block + 56, low);
+ LE_WRITE_UINT32(ctx->block + 60, high);
_nettle_ripemd160_compress(ctx->state, ctx->block);
_nettle_write_le32(length, digest, ctx->state);