~ubuntu-branches/ubuntu/utopic/nettle/utopic

« back to all changes in this revision

Viewing changes to sha2.h

  • Committer: Package Import Robot
  • Author(s): Magnus Holmgren
  • Date: 2013-05-07 22:57:14 UTC
  • mfrom: (8.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130507225714-s331yr8ov53dtt17
Tags: 2.7-2
Tag some (ECC related) symbols that only exist on some architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* sha2.h
 
2
 *
 
3
 * The sha2 family of hash functions.
 
4
 */
 
5
 
 
6
/* nettle, low-level cryptographics library
 
7
 *
 
8
 * Copyright (C) 2001, 2012 Niels Möller
 
9
 *  
 
10
 * The nettle library is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU Lesser General Public License as published by
 
12
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 
13
 * option) any later version.
 
14
 * 
 
15
 * The nettle library is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
17
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
18
 * License for more details.
 
19
 * 
 
20
 * You should have received a copy of the GNU Lesser General Public License
 
21
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
 
22
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
23
 * MA 02111-1301, USA.
 
24
 */
 
25
 
 
26
#ifndef NETTLE_SHA2_H_INCLUDED
 
27
#define NETTLE_SHA2_H_INCLUDED
 
28
 
 
29
#include "nettle-types.h"
 
30
 
 
31
#ifdef __cplusplus
 
32
extern "C" {
 
33
#endif
 
34
 
 
35
/* Name mangling */
 
36
#define sha224_init nettle_sha224_init
 
37
#define sha224_digest nettle_sha224_digest
 
38
#define sha256_init nettle_sha256_init
 
39
#define sha256_update nettle_sha256_update
 
40
#define sha256_digest nettle_sha256_digest
 
41
#define sha384_init nettle_sha384_init
 
42
#define sha384_digest nettle_sha384_digest
 
43
#define sha512_init nettle_sha512_init
 
44
#define sha512_update nettle_sha512_update
 
45
#define sha512_digest nettle_sha512_digest
 
46
 
 
47
/* SHA256 */
 
48
 
 
49
#define SHA256_DIGEST_SIZE 32
 
50
#define SHA256_DATA_SIZE 64
 
51
 
 
52
/* Digest is kept internally as 8 32-bit words. */
 
53
#define _SHA256_DIGEST_LENGTH 8
 
54
 
 
55
struct sha256_ctx
 
56
{
 
57
  uint32_t state[_SHA256_DIGEST_LENGTH];    /* State variables */
 
58
  uint32_t count_low, count_high;           /* 64-bit block count */
 
59
  uint8_t block[SHA256_DATA_SIZE];          /* SHA256 data buffer */
 
60
  unsigned int index;                       /* index into buffer */
 
61
};
 
62
 
 
63
void
 
64
sha256_init(struct sha256_ctx *ctx);
 
65
 
 
66
void
 
67
sha256_update(struct sha256_ctx *ctx,
 
68
              unsigned length,
 
69
              const uint8_t *data);
 
70
 
 
71
void
 
72
sha256_digest(struct sha256_ctx *ctx,
 
73
              unsigned length,
 
74
              uint8_t *digest);
 
75
 
 
76
/* Internal compression function. STATE points to 8 uint32_t words,
 
77
   DATA points to 64 bytes of input data, possibly unaligned, and K
 
78
   points to the table of constants. */
 
79
void
 
80
_nettle_sha256_compress(uint32_t *state, const uint8_t *data, const uint32_t *k);
 
81
 
 
82
 
 
83
/* SHA224, a truncated SHA256 with different initial state. */
 
84
 
 
85
#define SHA224_DIGEST_SIZE 28
 
86
#define SHA224_DATA_SIZE SHA256_DATA_SIZE
 
87
#define sha224_ctx sha256_ctx
 
88
 
 
89
void
 
90
sha224_init(struct sha256_ctx *ctx);
 
91
 
 
92
#define sha224_update nettle_sha256_update
 
93
 
 
94
void
 
95
sha224_digest(struct sha256_ctx *ctx,
 
96
              unsigned length,
 
97
              uint8_t *digest);
 
98
 
 
99
 
 
100
/* SHA512 */
 
101
 
 
102
#define SHA512_DIGEST_SIZE 64
 
103
#define SHA512_DATA_SIZE 128
 
104
 
 
105
/* Digest is kept internally as 8 64-bit words. */
 
106
#define _SHA512_DIGEST_LENGTH 8
 
107
 
 
108
struct sha512_ctx
 
109
{
 
110
  uint64_t state[_SHA512_DIGEST_LENGTH];    /* State variables */
 
111
  uint64_t count_low, count_high;           /* 128-bit block count */
 
112
  uint8_t block[SHA512_DATA_SIZE];          /* SHA512 data buffer */
 
113
  unsigned int index;                       /* index into buffer */
 
114
};
 
115
 
 
116
void
 
117
sha512_init(struct sha512_ctx *ctx);
 
118
 
 
119
void
 
120
sha512_update(struct sha512_ctx *ctx,
 
121
              unsigned length,
 
122
              const uint8_t *data);
 
123
 
 
124
void
 
125
sha512_digest(struct sha512_ctx *ctx,
 
126
              unsigned length,
 
127
              uint8_t *digest);
 
128
 
 
129
/* Internal compression function. STATE points to 8 uint64_t words,
 
130
   DATA points to 128 bytes of input data, possibly unaligned, and K
 
131
   points to the table of constants. */
 
132
void
 
133
_nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k);
 
134
 
 
135
 
 
136
/* SHA384, a truncated SHA512 with different initial state. */
 
137
 
 
138
#define SHA384_DIGEST_SIZE 48
 
139
#define SHA384_DATA_SIZE SHA512_DATA_SIZE
 
140
#define sha384_ctx sha512_ctx
 
141
 
 
142
void
 
143
sha384_init(struct sha512_ctx *ctx);
 
144
 
 
145
#define sha384_update nettle_sha512_update
 
146
 
 
147
void
 
148
sha384_digest(struct sha512_ctx *ctx,
 
149
              unsigned length,
 
150
              uint8_t *digest);
 
151
 
 
152
#ifdef __cplusplus
 
153
}
 
154
#endif
 
155
 
 
156
#endif /* NETTLE_SHA2_H_INCLUDED */