1 #ifndef CCAN_CRYPTO_RIPEMD160_H
2 #define CCAN_CRYPTO_RIPEMD160_H
3 /* BSD-MIT - see LICENSE file for details */
8 /* Uncomment this to use openssl's RIPEMD160 routines (and link with -lcrypto) */
9 /*#define CCAN_CRYPTO_RIPEMD160_USE_OPENSSL 1*/
11 #ifdef CCAN_CRYPTO_RIPEMD160_USE_OPENSSL
12 #include <openssl/ripemd.h>
16 * struct ripemd160 - structure representing a completed RIPEMD160.
17 * @u.u8: an unsigned char array.
18 * @u.u32: a 32-bit integer array.
20 * Other fields may be added to the union in future.
26 /* Array of uint32_t */
32 * ripemd160 - return ripemd160 of an object.
33 * @ripemd160: the ripemd160 to fill in
34 * @p: pointer to memory,
35 * @size: the number of bytes pointed to by @p
37 * The bytes pointed to by @p is RIPEMD160 hashed into @ripemd160. This is
38 * equivalent to ripemd160_init(), ripemd160_update() then ripemd160_done().
40 void ripemd160(struct ripemd160 *sha, const void *p, size_t size);
43 * struct ripemd160_ctx - structure to store running context for ripemd160
45 struct ripemd160_ctx {
46 #ifdef CCAN_CRYPTO_RIPEMD160_USE_OPENSSL
59 * ripemd160_init - initialize an RIPEMD160 context.
60 * @ctx: the ripemd160_ctx to initialize
62 * This must be called before ripemd160_update or ripemd160_done, or
63 * alternately you can assign RIPEMD160_INIT.
65 * If it was already initialized, this forgets anything which was
69 * static void hash_all(const char **arr, struct ripemd160 *hash)
72 * struct ripemd160_ctx ctx;
74 * ripemd160_init(&ctx);
75 * for (i = 0; arr[i]; i++)
76 * ripemd160_update(&ctx, arr[i], strlen(arr[i]));
77 * ripemd160_done(&ctx, hash);
80 void ripemd160_init(struct ripemd160_ctx *ctx);
83 * RIPEMD160_INIT - initializer for an RIPEMD160 context.
85 * This can be used to staticly initialize an RIPEMD160 context (instead
86 * of ripemd160_init()).
89 * static void hash_all(const char **arr, struct ripemd160 *hash)
92 * struct ripemd160_ctx ctx = RIPEMD160_INIT;
94 * for (i = 0; arr[i]; i++)
95 * ripemd160_update(&ctx, arr[i], strlen(arr[i]));
96 * ripemd160_done(&ctx, hash);
99 #ifdef CCAN_CRYPTO_RIPEMD160_USE_OPENSSL
100 #define RIPEMD160_INIT \
101 { { 0x67452301ul, 0xEFCDAB89ul, 0x98BADCFEul, 0x10325476ul, \
104 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \
107 #define RIPEMD160_INIT \
108 { { 0x67452301ul, 0xEFCDAB89ul, 0x98BADCFEul, 0x10325476ul, \
113 * ripemd160_update - include some memory in the hash.
114 * @ctx: the ripemd160_ctx to use
115 * @p: pointer to memory,
116 * @size: the number of bytes pointed to by @p
118 * You can call this multiple times to hash more data, before calling
121 void ripemd160_update(struct ripemd160_ctx *ctx, const void *p, size_t size);
124 * ripemd160_done - finish RIPEMD160 and return the hash
125 * @ctx: the ripemd160_ctx to complete
126 * @res: the hash to return.
128 * Note that @ctx is *destroyed* by this, and must be reinitialized.
129 * To avoid that, pass a copy instead.
131 void ripemd160_done(struct ripemd160_ctx *ripemd160, struct ripemd160 *res);
133 /* Add various types to an RIPEMD160 hash */
134 void ripemd160_u8(struct ripemd160_ctx *ctx, uint8_t v);
135 void ripemd160_u16(struct ripemd160_ctx *ctx, uint16_t v);
136 void ripemd160_u32(struct ripemd160_ctx *ctx, uint32_t v);
137 void ripemd160_u64(struct ripemd160_ctx *ctx, uint64_t v);
139 /* Add as little-endian */
140 void ripemd160_le16(struct ripemd160_ctx *ctx, uint16_t v);
141 void ripemd160_le32(struct ripemd160_ctx *ctx, uint32_t v);
142 void ripemd160_le64(struct ripemd160_ctx *ctx, uint64_t v);
144 /* Add as big-endian */
145 void ripemd160_be16(struct ripemd160_ctx *ctx, uint16_t v);
146 void ripemd160_be32(struct ripemd160_ctx *ctx, uint32_t v);
147 void ripemd160_be64(struct ripemd160_ctx *ctx, uint64_t v);
148 #endif /* CCAN_CRYPTO_RIPEMD160_H */