Statistics
| Branch: | Revision:

iof-bird-daemon / lib / sha512.h @ 9b136840

History | View | Annotate | Download (1.82 KB)

1 f312a837 Pavel Tvrdík
/*
2
 *        BIRD Library -- SHA-512 and SHA-384 Hash Functions,
3
 *                        HMAC-SHA-512 and HMAC-SHA-384 Functions
4
 *
5
 *        (c) 2015 CZ.NIC z.s.p.o.
6
 *
7
 *        Based on the code from libgcrypt-1.6.0, which is
8
 *        (c) 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
9
 *
10
 *        Can be freely distributed and used under the terms of the GNU GPL.
11
 */
12
13
#ifndef _BIRD_SHA512_H_
14
#define _BIRD_SHA512_H_
15
16 5126380b Ondrej Zajicek (work)
#include "nest/bird.h"
17
18 f312a837 Pavel Tvrdík
19
#define SHA384_SIZE                 48
20
#define SHA384_HEX_SIZE                97
21
#define SHA384_BLOCK_SIZE        128
22
23
#define SHA512_SIZE                 64
24
#define SHA512_HEX_SIZE                129
25
#define SHA512_BLOCK_SIZE        128
26
27 5126380b Ondrej Zajicek (work)
28
struct sha512_context {
29 f312a837 Pavel Tvrdík
  u64 h0, h1, h2, h3, h4, h5, h6, h7;
30 5126380b Ondrej Zajicek (work)
  byte buf[SHA512_BLOCK_SIZE];
31
  uint nblocks;
32
  uint count;
33 f312a837 Pavel Tvrdík
};
34
35 5126380b Ondrej Zajicek (work)
#define sha384_context sha512_context
36 f312a837 Pavel Tvrdík
37
38
void sha512_init(struct sha512_context *ctx);
39
void sha384_init(struct sha384_context *ctx);
40
41 5126380b Ondrej Zajicek (work)
void sha512_update(struct sha512_context *ctx, const byte *buf, size_t len);
42
static inline void sha384_update(struct sha384_context *ctx, const byte *buf, size_t len)
43
{ sha512_update(ctx, buf, len); }
44
45
byte *sha512_final(struct sha512_context *ctx);
46
static inline byte *sha384_final(struct sha384_context *ctx)
47
{ return sha512_final(ctx); }
48 f312a837 Pavel Tvrdík
49
50
/*
51
 *        HMAC-SHA512, HMAC-SHA384
52
 */
53 5126380b Ondrej Zajicek (work)
54 f312a837 Pavel Tvrdík
struct sha512_hmac_context
55
{
56
  struct sha512_context ictx;
57
  struct sha512_context octx;
58 5126380b Ondrej Zajicek (work)
};
59
60
#define sha384_hmac_context sha512_hmac_context
61
62 f312a837 Pavel Tvrdík
63
void sha512_hmac_init(struct sha512_hmac_context *ctx, const byte *key, size_t keylen);
64
void sha384_hmac_init(struct sha384_hmac_context *ctx, const byte *key, size_t keylen);
65
66
void sha512_hmac_update(struct sha512_hmac_context *ctx, const byte *buf, size_t buflen);
67
void sha384_hmac_update(struct sha384_hmac_context *ctx, const byte *buf, size_t buflen);
68
69
byte *sha512_hmac_final(struct sha512_hmac_context *ctx);
70
byte *sha384_hmac_final(struct sha384_hmac_context *ctx);
71
72 5126380b Ondrej Zajicek (work)
73 f312a837 Pavel Tvrdík
#endif /* _BIRD_SHA512_H_ */