summaryrefslogtreecommitdiff
path: root/lib/sha1.h
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2015-11-24 13:47:28 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2015-11-24 13:47:28 +0100
commit5126380beace4e39578f005fe115917b8e8b8ff3 (patch)
tree123ac5af08d02855e1719a891dc0f7340f0329cb /lib/sha1.h
parent12d752ef24ab507d249a60098ec98dcf28b70036 (diff)
Minor changes to SHA hash functions
Diffstat (limited to 'lib/sha1.h')
-rw-r--r--lib/sha1.h72
1 files changed, 36 insertions, 36 deletions
diff --git a/lib/sha1.h b/lib/sha1.h
index 425160a0..c019bb49 100644
--- a/lib/sha1.h
+++ b/lib/sha1.h
@@ -17,70 +17,70 @@
#include "nest/bird.h"
+
+#define SHA1_SIZE 20 /* Size of the SHA1 hash in its binary representation */
+#define SHA1_HEX_SIZE 41 /* Buffer length for a string containing SHA1 in hexadecimal format. */
+#define SHA1_BLOCK_SIZE 64 /* SHA1 splits input to blocks of this size. */
+
+
/*
* Internal SHA1 state.
* You should use it just as an opaque handle only.
*/
struct sha1_context {
- u32 h0,h1,h2,h3,h4;
- u32 nblocks;
- byte buf[64];
- int count;
-} ;
+ u32 h0, h1, h2, h3, h4;
+ byte buf[SHA1_BLOCK_SIZE];
+ uint nblocks;
+ uint count;
+};
+
-void sha1_init(struct sha1_context *hd); /* Initialize new algorithm run in the @hd context. **/
+void sha1_init(struct sha1_context *ctx); /* Initialize new algorithm run in the @ctx context. **/
/*
- * Push another @inlen bytes of data pointed to by @inbuf onto the
- * SHA1 hash currently in @hd. You can call this any times you want on
- * the same hash (and you do not need to reinitialize it by
- * @sha1_init()). It has the same effect as concatenating all the data
- * together and passing them at once.
+ * Push another @len bytes of data pointed to by @buf onto the SHA1 hash
+ * currently in @ctx. You can call this any times you want on the same hash (and
+ * you do not need to reinitialize it by @sha1_init()). It has the same effect
+ * as concatenating all the data together and passing them at once.
*/
-void sha1_update(struct sha1_context *hd, const byte *inbuf, uint inlen);
+void sha1_update(struct sha1_context *ctx, const byte *buf, uint len);
/*
- * No more @sha1_update() calls will be done. This terminates the hash
- * and returns a pointer to it.
- *
- * Note that the pointer points into data in the @hd context. If it ceases
- * to exist, the pointer becomes invalid.
+ * No more @sha1_update() calls will be done. This terminates the hash and
+ * returns a pointer to it.
*
- * To convert the hash to its usual hexadecimal representation, see
- * <<string:mem_to_hex()>>.
+ * Note that the pointer points into data in the @ctx context. If it ceases to
+ * exist, the pointer becomes invalid.
*/
-byte *sha1_final(struct sha1_context *hd);
+byte *sha1_final(struct sha1_context *ctx);
/*
- * A convenience one-shot function for SHA1 hash.
- * It is equivalent to this snippet of code:
+ * A convenience one-shot function for SHA1 hash. It is equivalent to this
+ * snippet of code:
*
- * sha1_context hd;
- * sha1_init(&hd);
- * sha1_update(&hd, buffer, length);
- * memcpy(outbuf, sha1_final(&hd), SHA1_SIZE);
+ * sha1_context ctx;
+ * sha1_init(&ctx);
+ * sha1_update(&ctx, buffer, length);
+ * memcpy(outbuf, sha1_final(&ctx), SHA1_SIZE);
*/
void sha1_hash_buffer(byte *outbuf, const byte *buffer, uint length);
/*
- * SHA1 HMAC message authentication. If you provide @key and @data,
- * the result will be stored in @outbuf.
+ * SHA1 HMAC message authentication. If you provide @key and @data, the result
+ * will be stored in @outbuf.
*/
void sha1_hmac(byte *outbuf, const byte *key, uint keylen, const byte *data, uint datalen);
/*
- * The HMAC also exists in a stream version in a way analogous to the
- * plain SHA1. Pass this as a context.
+ * The HMAC also exists in a stream version in a way analogous to the plain
+ * SHA1. Pass this as a context.
*/
struct sha1_hmac_context {
struct sha1_context ictx;
struct sha1_context octx;
};
-void sha1_hmac_init(struct sha1_hmac_context *hd, const byte *key, uint keylen); /* Initialize HMAC with context @hd and the given key. See sha1_init(). */
-void sha1_hmac_update(struct sha1_hmac_context *hd, const byte *data, uint datalen); /* Hash another @datalen bytes of data. See sha1_update(). */
-byte *sha1_hmac_final(struct sha1_hmac_context *hd); /* Terminate the HMAC and return a pointer to the allocated hash. See sha1_final(). */
+void sha1_hmac_init(struct sha1_hmac_context *ctx, const byte *key, uint keylen); /* Initialize HMAC with context @ctx and the given key. See sha1_init(). */
+void sha1_hmac_update(struct sha1_hmac_context *ctx, const byte *data, uint datalen); /* Hash another @datalen bytes of data. See sha1_update(). */
+byte *sha1_hmac_final(struct sha1_hmac_context *ctx); /* Terminate the HMAC and return a pointer to the allocated hash. See sha1_final(). */
-#define SHA1_SIZE 20 /* Size of the SHA1 hash in its binary representation **/
-#define SHA1_HEX_SIZE 41 /* Buffer length for a string containing SHA1 in hexadecimal format. **/
-#define SHA1_BLOCK_SIZE 64 /* SHA1 splits input to blocks of this size. **/
#endif /* _BIRD_SHA1_H_ */