summaryrefslogtreecommitdiff
path: root/lib/sha512.h
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2016-10-25 17:04:17 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2016-11-02 16:23:53 +0100
commitde2a27e255b6ec834d11c005909b28a150c7c0db (patch)
tree9b6f61fa7f9d3cb05abf5e72b9fdb8d5ba9bdef7 /lib/sha512.h
parent7eec3988758cb4c19a0ab3bf90cab2a4914165be (diff)
Add generic message authentication interface
Add generic interface for generating and verifying MACs (message authentication codes). Replace multiple HMAC implementation with a generic one.
Diffstat (limited to 'lib/sha512.h')
-rw-r--r--lib/sha512.h44
1 files changed, 10 insertions, 34 deletions
diff --git a/lib/sha512.h b/lib/sha512.h
index 1614a3ac..02220c93 100644
--- a/lib/sha512.h
+++ b/lib/sha512.h
@@ -1,6 +1,5 @@
/*
- * BIRD Library -- SHA-512 and SHA-384 Hash Functions,
- * HMAC-SHA-512 and HMAC-SHA-384 Functions
+ * BIRD Library -- SHA-512 and SHA-384 Hash Functions
*
* (c) 2015 CZ.NIC z.s.p.o.
*
@@ -25,8 +24,10 @@
#define SHA512_BLOCK_SIZE 128
+struct hash_context;
+
struct sha512_context {
- u64 h0, h1, h2, h3, h4, h5, h6, h7;
+ u64 h0, h1, h2, h3, h4, h5, h6, h7;
byte buf[SHA512_BLOCK_SIZE];
uint nblocks;
uint count;
@@ -35,39 +36,14 @@ struct sha512_context {
#define sha384_context sha512_context
-void sha512_init(struct sha512_context *ctx);
-void sha384_init(struct sha384_context *ctx);
-
-void sha512_update(struct sha512_context *ctx, const byte *buf, size_t len);
-static inline void sha384_update(struct sha384_context *ctx, const byte *buf, size_t len)
-{ sha512_update(ctx, buf, len); }
-
-byte *sha512_final(struct sha512_context *ctx);
-static inline byte *sha384_final(struct sha384_context *ctx)
-{ return sha512_final(ctx); }
-
-
-/*
- * HMAC-SHA512, HMAC-SHA384
- */
-
-struct sha512_hmac_context
-{
- struct sha512_context ictx;
- struct sha512_context octx;
-};
-
-#define sha384_hmac_context sha512_hmac_context
-
-
-void sha512_hmac_init(struct sha512_hmac_context *ctx, const byte *key, size_t keylen);
-void sha384_hmac_init(struct sha384_hmac_context *ctx, const byte *key, size_t keylen);
+void sha512_init(struct hash_context *ctx);
+void sha384_init(struct hash_context *ctx);
-void sha512_hmac_update(struct sha512_hmac_context *ctx, const byte *buf, size_t buflen);
-void sha384_hmac_update(struct sha384_hmac_context *ctx, const byte *buf, size_t buflen);
+void sha512_update(struct hash_context *ctx, const byte *buf, uint len);
+#define sha384_update sha512_update
-byte *sha512_hmac_final(struct sha512_hmac_context *ctx);
-byte *sha384_hmac_final(struct sha384_hmac_context *ctx);
+byte *sha512_final(struct hash_context *ctx);
+#define sha384_final sha512_final
#endif /* _BIRD_SHA512_H_ */