2015-04-23 13:18:27 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- SHA256 and SHA224 Hash Functions
|
|
|
|
*
|
|
|
|
* (c) 2015 CZ.NIC z.s.p.o.
|
|
|
|
*
|
|
|
|
* Based on the code from libgcrypt-1.6.0, which is
|
|
|
|
* (c) 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2015-04-28 07:08:43 +00:00
|
|
|
#ifndef _BIRD_SHA256_H_
|
|
|
|
#define _BIRD_SHA256_H_
|
2015-04-23 13:18:27 +00:00
|
|
|
|
2015-04-29 06:50:02 +00:00
|
|
|
#include "sysdep/config.h"
|
|
|
|
|
2015-04-23 13:18:27 +00:00
|
|
|
#define SHA224_SIZE 28
|
|
|
|
#define SHA224_HEX_SIZE 57
|
2015-04-29 11:39:32 +00:00
|
|
|
#define SHA224_BLOCK_SIZE 64
|
|
|
|
|
|
|
|
#define SHA256_SIZE 32
|
|
|
|
#define SHA256_HEX_SIZE 65
|
|
|
|
#define SHA256_BLOCK_SIZE 64
|
2015-04-23 13:18:27 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 h0,h1,h2,h3,h4,h5,h6,h7;
|
2015-04-29 11:39:32 +00:00
|
|
|
byte buf[128]; /* 128 is for SHA384 and SHA512 support, otherwise for SHA224 and SHA256 is 64 enough */
|
2015-04-23 13:18:27 +00:00
|
|
|
u32 nblocks;
|
|
|
|
u32 nblocks_high;
|
|
|
|
int count;
|
2015-04-28 13:02:37 +00:00
|
|
|
u32 blocksize;
|
2015-04-23 13:18:27 +00:00
|
|
|
} sha256_context;
|
|
|
|
typedef sha256_context sha224_context;
|
|
|
|
|
|
|
|
void sha256_init(sha256_context *ctx);
|
2015-04-28 07:08:43 +00:00
|
|
|
void sha224_init(sha224_context *ctx);
|
2015-04-23 13:18:27 +00:00
|
|
|
|
|
|
|
void sha256_update(sha256_context *ctx, const byte *in_buf, size_t in_len);
|
|
|
|
void sha224_update(sha224_context *ctx, const byte *in_buf, size_t in_len)
|
|
|
|
{
|
|
|
|
sha256_update(ctx, in_buf, in_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte* sha256_final(sha256_context *ctx);
|
|
|
|
byte* sha224_final(sha224_context *ctx)
|
|
|
|
{
|
|
|
|
return sha256_final(ctx);
|
|
|
|
}
|
|
|
|
|
2015-04-28 10:43:03 +00:00
|
|
|
/**
|
2015-04-29 11:39:32 +00:00
|
|
|
* HMAC-SHA256, HMAC-SHA224
|
2015-04-28 08:05:25 +00:00
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-04-29 11:39:32 +00:00
|
|
|
sha256_context ictx;
|
|
|
|
sha256_context octx;
|
2015-04-28 08:05:25 +00:00
|
|
|
} sha256_hmac_context;
|
2015-04-28 10:43:03 +00:00
|
|
|
typedef sha256_hmac_context sha224_hmac_context;
|
2015-04-28 08:05:25 +00:00
|
|
|
|
2015-04-29 11:39:32 +00:00
|
|
|
void sha256_hmac_init(sha256_hmac_context *ctx, const byte *key, size_t keylen);
|
|
|
|
void sha224_hmac_init(sha224_hmac_context *ctx, const byte *key, size_t keylen);
|
2015-04-28 10:43:03 +00:00
|
|
|
|
2015-04-29 11:39:32 +00:00
|
|
|
void sha256_hmac_update(sha256_hmac_context *ctx, const byte *buf, size_t buflen);
|
|
|
|
void sha224_hmac_update(sha224_hmac_context *ctx, const byte *buf, size_t buflen);
|
2015-04-28 10:43:03 +00:00
|
|
|
|
2015-04-28 13:02:37 +00:00
|
|
|
byte *sha256_hmac_final(sha256_hmac_context *ctx);
|
2015-04-29 11:39:32 +00:00
|
|
|
byte *sha224_hmac_final(sha224_hmac_context *ctx);
|
2015-04-28 08:05:25 +00:00
|
|
|
|
2015-04-28 07:08:43 +00:00
|
|
|
#endif /* _BIRD_SHA256_H_ */
|