summaryrefslogtreecommitdiff
path: root/lib/sha256.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/sha256.h
parent12d752ef24ab507d249a60098ec98dcf28b70036 (diff)
Minor changes to SHA hash functions
Diffstat (limited to 'lib/sha256.h')
-rw-r--r--lib/sha256.h42
1 files changed, 22 insertions, 20 deletions
diff --git a/lib/sha256.h b/lib/sha256.h
index 848d2176..381200a9 100644
--- a/lib/sha256.h
+++ b/lib/sha256.h
@@ -15,6 +15,7 @@
#include "nest/bird.h"
+
#define SHA224_SIZE 28
#define SHA224_HEX_SIZE 57
#define SHA224_BLOCK_SIZE 64
@@ -23,44 +24,44 @@
#define SHA256_HEX_SIZE 65
#define SHA256_BLOCK_SIZE 64
+
struct sha256_context {
- u32 h0,h1,h2,h3,h4,h5,h6,h7;
- byte buf[128]; /* 128 is for SHA384 and SHA512 support, otherwise for SHA224 and SHA256 is 64 enough */
- u32 nblocks;
- u32 nblocks_high;
- int count;
- u32 blocksize;
- uint (*transform)(void *c, const byte *blks, size_t nblks);
+ u32 h0, h1, h2, h3, h4, h5, h6, h7;
+ byte buf[SHA256_BLOCK_SIZE];
+ uint nblocks;
+ uint count;
};
-#define sha224_context sha256_context /* aliasing 'struct sha224_context' to 'struct sha256_context' */
+
+#define sha224_context sha256_context
+
void sha256_init(struct sha256_context *ctx);
void sha224_init(struct sha224_context *ctx);
-void sha256_update(struct sha256_context *ctx, const byte *in_buf, size_t in_len);
-static inline void sha224_update(struct sha224_context *ctx, const byte *in_buf, size_t in_len)
-{
- sha256_update(ctx, in_buf, in_len);
-}
+void sha256_update(struct sha256_context *ctx, const byte *buf, size_t len);
+static inline void sha224_update(struct sha224_context *ctx, const byte *buf, size_t len)
+{ sha256_update(ctx, buf, len); }
+
+byte *sha256_final(struct sha256_context *ctx);
+static inline byte *sha224_final(struct sha224_context *ctx)
+{ return sha256_final(ctx); }
-byte* sha256_final(struct sha256_context *ctx);
-static inline byte* sha224_final(struct sha224_context *ctx)
-{
- return sha256_final(ctx);
-}
/*
* HMAC-SHA256, HMAC-SHA224
*/
+
struct sha256_hmac_context
{
struct sha256_context ictx;
struct sha256_context octx;
};
-#define sha224_hmac_context sha256_hmac_context /* aliasing 'struct sha224_hmac_context' to 'struct sha256_hmac_context' */
+
+#define sha224_hmac_context sha256_hmac_context
+
void sha256_hmac_init(struct sha256_hmac_context *ctx, const byte *key, size_t keylen);
-void sha224_hmac_init(struct sha224_hmac_context *ctx, const byte *key, size_t keylen);
+void sha224_hmac_init(struct sha224_hmac_context *ctx, const byte *key, size_t keylen);
void sha256_hmac_update(struct sha256_hmac_context *ctx, const byte *buf, size_t buflen);
void sha224_hmac_update(struct sha224_hmac_context *ctx, const byte *buf, size_t buflen);
@@ -68,4 +69,5 @@ void sha224_hmac_update(struct sha224_hmac_context *ctx, const byte *buf, size_t
byte *sha256_hmac_final(struct sha256_hmac_context *ctx);
byte *sha224_hmac_final(struct sha224_hmac_context *ctx);
+
#endif /* _BIRD_SHA256_H_ */