Browse Source

[crypto] Replace SHA-1 implementation

Replace SHA-1 implementation from AXTLS with a dedicated iPXE
implementation which is around 40% smaller.  This implementation has
been verified using the existing SHA-1 self-tests (including the NIST
SHA-1 test vectors).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
76f5939736
4 changed files with 337 additions and 276 deletions
  1. 0
    240
      src/crypto/axtls/sha1.c
  2. 0
    25
      src/crypto/axtls_sha1.c
  3. 270
    0
      src/crypto/sha1.c
  4. 67
    11
      src/include/ipxe/sha1.h

+ 0
- 240
src/crypto/axtls/sha1.c View File

@@ -1,240 +0,0 @@
1
-/*
2
- *  Copyright(C) 2006 Cameron Rich
3
- *
4
- *  This library is free software; you can redistribute it and/or modify
5
- *  it under the terms of the GNU Lesser General Public License as published by
6
- *  the Free Software Foundation; either version 2.1 of the License, or
7
- *  (at your option) any later version.
8
- *
9
- *  This library is distributed in the hope that it will be useful,
10
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
- *  GNU Lesser General Public License for more details.
13
- *
14
- *  You should have received a copy of the GNU Lesser General Public License
15
- *  along with this library; if not, write to the Free Software
16
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
- */
18
-
19
-/**
20
- * SHA1 implementation - as defined in FIPS PUB 180-1 published April 17, 1995.
21
- * This code was originally taken from RFC3174
22
- */
23
-
24
-#include <string.h>
25
-#include "crypto.h"
26
-
27
-/*
28
- *  Define the SHA1 circular left shift macro
29
- */
30
-#define SHA1CircularShift(bits,word) \
31
-                (((word) << (bits)) | ((word) >> (32-(bits))))
32
-
33
-/* ----- static functions ----- */
34
-static void SHA1PadMessage(SHA1_CTX *ctx);
35
-static void SHA1ProcessMessageBlock(SHA1_CTX *ctx);
36
-
37
-/**
38
- * Initialize the SHA1 context 
39
- */
40
-void SHA1Init(SHA1_CTX *ctx)
41
-{
42
-    ctx->Length_Low             = 0;
43
-    ctx->Length_High            = 0;
44
-    ctx->Message_Block_Index    = 0;
45
-    ctx->Intermediate_Hash[0]   = 0x67452301;
46
-    ctx->Intermediate_Hash[1]   = 0xEFCDAB89;
47
-    ctx->Intermediate_Hash[2]   = 0x98BADCFE;
48
-    ctx->Intermediate_Hash[3]   = 0x10325476;
49
-    ctx->Intermediate_Hash[4]   = 0xC3D2E1F0;
50
-}
51
-
52
-/**
53
- * Accepts an array of octets as the next portion of the message.
54
- */
55
-void SHA1Update(SHA1_CTX *ctx, const uint8_t *msg, int len)
56
-{
57
-    while (len--)
58
-    {
59
-        ctx->Message_Block[ctx->Message_Block_Index++] = (*msg & 0xFF);
60
-
61
-        ctx->Length_Low += 8;
62
-        if (ctx->Length_Low == 0)
63
-        {
64
-            ctx->Length_High++;
65
-        }
66
-
67
-        if (ctx->Message_Block_Index == 64)
68
-        {
69
-            SHA1ProcessMessageBlock(ctx);
70
-        }
71
-
72
-        msg++;
73
-    }
74
-}
75
-
76
-/**
77
- * Return the 160-bit message digest into the user's array
78
- */
79
-void SHA1Final(SHA1_CTX *ctx, uint8_t *digest)
80
-{
81
-    int i;
82
-
83
-    SHA1PadMessage(ctx);
84
-    memset(ctx->Message_Block, 0, 64);
85
-    ctx->Length_Low = 0;    /* and clear length */
86
-    ctx->Length_High = 0;
87
-
88
-    for  (i = 0; i < SHA1_SIZE; i++)
89
-    {
90
-        digest[i] = ctx->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) );
91
-    }
92
-}
93
-
94
-/**
95
- * Process the next 512 bits of the message stored in the array.
96
- */
97
-static void SHA1ProcessMessageBlock(SHA1_CTX *ctx)
98
-{
99
-    const uint32_t K[] =    {       /* Constants defined in SHA-1   */
100
-                            0x5A827999,
101
-                            0x6ED9EBA1,
102
-                            0x8F1BBCDC,
103
-                            0xCA62C1D6
104
-                            };
105
-    int        t;                 /* Loop counter                */
106
-    uint32_t      temp;              /* Temporary word value        */
107
-    uint32_t      W[80];             /* Word sequence               */
108
-    uint32_t      A, B, C, D, E;     /* Word buffers                */
109
-
110
-    /*
111
-     *  Initialize the first 16 words in the array W
112
-     */
113
-    for  (t = 0; t < 16; t++)
114
-    {
115
-        W[t] = ctx->Message_Block[t * 4] << 24;
116
-        W[t] |= ctx->Message_Block[t * 4 + 1] << 16;
117
-        W[t] |= ctx->Message_Block[t * 4 + 2] << 8;
118
-        W[t] |= ctx->Message_Block[t * 4 + 3];
119
-    }
120
-
121
-    for (t = 16; t < 80; t++)
122
-    {
123
-       W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
124
-    }
125
-
126
-    A = ctx->Intermediate_Hash[0];
127
-    B = ctx->Intermediate_Hash[1];
128
-    C = ctx->Intermediate_Hash[2];
129
-    D = ctx->Intermediate_Hash[3];
130
-    E = ctx->Intermediate_Hash[4];
131
-
132
-    for (t = 0; t < 20; t++)
133
-    {
134
-        temp =  SHA1CircularShift(5,A) +
135
-                ((B & C) | ((~B) & D)) + E + W[t] + K[0];
136
-        E = D;
137
-        D = C;
138
-        C = SHA1CircularShift(30,B);
139
-
140
-        B = A;
141
-        A = temp;
142
-    }
143
-
144
-    for (t = 20; t < 40; t++)
145
-    {
146
-        temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
147
-        E = D;
148
-        D = C;
149
-        C = SHA1CircularShift(30,B);
150
-        B = A;
151
-        A = temp;
152
-    }
153
-
154
-    for (t = 40; t < 60; t++)
155
-    {
156
-        temp = SHA1CircularShift(5,A) +
157
-               ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
158
-        E = D;
159
-        D = C;
160
-        C = SHA1CircularShift(30,B);
161
-        B = A;
162
-        A = temp;
163
-    }
164
-
165
-    for (t = 60; t < 80; t++)
166
-    {
167
-        temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
168
-        E = D;
169
-        D = C;
170
-        C = SHA1CircularShift(30,B);
171
-        B = A;
172
-        A = temp;
173
-    }
174
-
175
-    ctx->Intermediate_Hash[0] += A;
176
-    ctx->Intermediate_Hash[1] += B;
177
-    ctx->Intermediate_Hash[2] += C;
178
-    ctx->Intermediate_Hash[3] += D;
179
-    ctx->Intermediate_Hash[4] += E;
180
-    ctx->Message_Block_Index = 0;
181
-}
182
-
183
-/*
184
- * According to the standard, the message must be padded to an even
185
- * 512 bits.  The first padding bit must be a '1'.  The last 64
186
- * bits represent the length of the original message.  All bits in
187
- * between should be 0.  This function will pad the message
188
- * according to those rules by filling the Message_Block array
189
- * accordingly.  It will also call the ProcessMessageBlock function
190
- * provided appropriately.  When it returns, it can be assumed that
191
- * the message digest has been computed.
192
- *
193
- * @param ctx [in, out] The SHA1 context
194
- */
195
-static void SHA1PadMessage(SHA1_CTX *ctx)
196
-{
197
-    /*
198
-     *  Check to see if the current message block is too small to hold
199
-     *  the initial padding bits and length.  If so, we will pad the
200
-     *  block, process it, and then continue padding into a second
201
-     *  block.
202
-     */
203
-    if (ctx->Message_Block_Index > 55)
204
-    {
205
-        ctx->Message_Block[ctx->Message_Block_Index++] = 0x80;
206
-        while(ctx->Message_Block_Index < 64)
207
-        {
208
-            ctx->Message_Block[ctx->Message_Block_Index++] = 0;
209
-        }
210
-
211
-        SHA1ProcessMessageBlock(ctx);
212
-
213
-        while (ctx->Message_Block_Index < 56)
214
-        {
215
-            ctx->Message_Block[ctx->Message_Block_Index++] = 0;
216
-        }
217
-    }
218
-    else
219
-    {
220
-        ctx->Message_Block[ctx->Message_Block_Index++] = 0x80;
221
-        while(ctx->Message_Block_Index < 56)
222
-        {
223
-
224
-            ctx->Message_Block[ctx->Message_Block_Index++] = 0;
225
-        }
226
-    }
227
-
228
-    /*
229
-     *  Store the message length as the last 8 octets
230
-     */
231
-    ctx->Message_Block[56] = ctx->Length_High >> 24;
232
-    ctx->Message_Block[57] = ctx->Length_High >> 16;
233
-    ctx->Message_Block[58] = ctx->Length_High >> 8;
234
-    ctx->Message_Block[59] = ctx->Length_High;
235
-    ctx->Message_Block[60] = ctx->Length_Low >> 24;
236
-    ctx->Message_Block[61] = ctx->Length_Low >> 16;
237
-    ctx->Message_Block[62] = ctx->Length_Low >> 8;
238
-    ctx->Message_Block[63] = ctx->Length_Low;
239
-    SHA1ProcessMessageBlock(ctx);
240
-}

+ 0
- 25
src/crypto/axtls_sha1.c View File

@@ -1,25 +0,0 @@
1
-#include "crypto/axtls/crypto.h"
2
-#include <ipxe/crypto.h>
3
-#include <ipxe/sha1.h>
4
-
5
-static void sha1_init ( void *ctx ) {
6
-	SHA1Init ( ctx );
7
-}
8
-
9
-static void sha1_update ( void *ctx, const void *data, size_t len ) {
10
-	SHA1Update ( ctx, data, len );
11
-}
12
-
13
-static void sha1_final ( void *ctx, void *out ) {
14
-	SHA1Final ( ctx, out );
15
-}
16
-
17
-struct digest_algorithm sha1_algorithm = {
18
-	.name		= "sha1",
19
-	.ctxsize	= SHA1_CTX_SIZE,
20
-	.blocksize	= 64,
21
-	.digestsize	= SHA1_DIGEST_SIZE,
22
-	.init		= sha1_init,
23
-	.update		= sha1_update,
24
-	.final		= sha1_final,
25
-};

+ 270
- 0
src/crypto/sha1.c View File

@@ -0,0 +1,270 @@
1
+/*
2
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+/** @file
22
+ *
23
+ * SHA-1 algorithm
24
+ *
25
+ */
26
+
27
+#include <stdint.h>
28
+#include <string.h>
29
+#include <byteswap.h>
30
+#include <assert.h>
31
+#include <ipxe/crypto.h>
32
+#include <ipxe/sha1.h>
33
+
34
+/**
35
+ * Rotate dword left
36
+ *
37
+ * @v dword		Dword
38
+ * @v rotate		Amount of rotation
39
+ */
40
+static inline __attribute__ (( always_inline )) uint32_t
41
+rol32 ( uint32_t dword, unsigned int rotate ) {
42
+	return ( ( dword << rotate ) | ( dword >> ( 32 - rotate ) ) );
43
+}
44
+
45
+/** SHA-1 variables */
46
+struct sha1_variables {
47
+	/* This layout matches that of struct sha1_digest_data,
48
+	 * allowing for efficient endianness-conversion,
49
+	 */
50
+	uint32_t a;
51
+	uint32_t b;
52
+	uint32_t c;
53
+	uint32_t d;
54
+	uint32_t e;
55
+	uint32_t w[80];
56
+} __attribute__ (( packed ));
57
+
58
+/**
59
+ * f(a,b,c,d) for steps 0 to 19
60
+ *
61
+ * @v v		SHA-1 variables
62
+ * @ret f	f(a,b,c,d)
63
+ */
64
+static uint32_t sha1_f_0_19 ( struct sha1_variables *v ) {
65
+	return ( ( v->b & v->c ) | ( (~v->b) & v->d ) );
66
+}
67
+
68
+/**
69
+ * f(a,b,c,d) for steps 20 to 39 and 60 to 79
70
+ *
71
+ * @v v		SHA-1 variables
72
+ * @ret f	f(a,b,c,d)
73
+ */
74
+static uint32_t sha1_f_20_39_60_79 ( struct sha1_variables *v ) {
75
+	return ( v->b ^ v->c ^ v->d );
76
+}
77
+
78
+/**
79
+ * f(a,b,c,d) for steps 40 to 59
80
+ *
81
+ * @v v		SHA-1 variables
82
+ * @ret f	f(a,b,c,d)
83
+ */
84
+static uint32_t sha1_f_40_59 ( struct sha1_variables *v ) {
85
+	return ( ( v->b & v->c ) | ( v->b & v->d ) | ( v->c & v->d ) );
86
+}
87
+
88
+/** An SHA-1 step function */
89
+struct sha1_step {
90
+	/**
91
+	 * Calculate f(a,b,c,d)
92
+	 *
93
+	 * @v v		SHA-1 variables
94
+	 * @ret f	f(a,b,c,d)
95
+	 */
96
+	uint32_t ( * f ) ( struct sha1_variables *v );
97
+	/** Constant k */
98
+	uint32_t k;
99
+};
100
+
101
+/** SHA-1 steps */
102
+static struct sha1_step sha1_steps[4] = {
103
+	/** 0 to 19 */
104
+	{ .f = sha1_f_0_19,		.k = 0x5a827999 },
105
+	/** 20 to 39 */
106
+	{ .f = sha1_f_20_39_60_79,	.k = 0x6ed9eba1 },
107
+	/** 40 to 59 */
108
+	{ .f = sha1_f_40_59,		.k = 0x8f1bbcdc },
109
+	/** 60 to 79 */
110
+	{ .f = sha1_f_20_39_60_79,	.k = 0xca62c1d6 },
111
+};
112
+
113
+/**
114
+ * Initialise SHA-1 algorithm
115
+ *
116
+ * @v ctx		SHA-1 context
117
+ */
118
+static void sha1_init ( void *ctx ) {
119
+	struct sha1_context *context = ctx;
120
+
121
+	context->ddd.dd.digest.h[0] = cpu_to_be32 ( 0x67452301 );
122
+	context->ddd.dd.digest.h[1] = cpu_to_be32 ( 0xefcdab89 );
123
+	context->ddd.dd.digest.h[2] = cpu_to_be32 ( 0x98badcfe );
124
+	context->ddd.dd.digest.h[3] = cpu_to_be32 ( 0x10325476 );
125
+	context->ddd.dd.digest.h[4] = cpu_to_be32 ( 0xc3d2e1f0 );
126
+	context->len = 0;
127
+}
128
+
129
+/**
130
+ * Calculate SHA-1 digest of accumulated data
131
+ *
132
+ * @v context		SHA-1 context
133
+ */
134
+static void sha1_digest ( struct sha1_context *context ) {
135
+        union {
136
+		union sha1_digest_data_dwords ddd;
137
+		struct sha1_variables v;
138
+	} u;
139
+	uint32_t *a = &u.v.a;
140
+	uint32_t *b = &u.v.b;
141
+	uint32_t *c = &u.v.c;
142
+	uint32_t *d = &u.v.d;
143
+	uint32_t *e = &u.v.e;
144
+	uint32_t *w = u.v.w;
145
+	uint32_t f;
146
+	uint32_t k;
147
+	uint32_t temp;
148
+	struct sha1_step *step;
149
+	unsigned int i;
150
+
151
+	/* Sanity checks */
152
+	assert ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 );
153
+	linker_assert ( &u.ddd.dd.digest.h[0] == a, sha1_bad_layout );
154
+	linker_assert ( &u.ddd.dd.digest.h[1] == b, sha1_bad_layout );
155
+	linker_assert ( &u.ddd.dd.digest.h[2] == c, sha1_bad_layout );
156
+	linker_assert ( &u.ddd.dd.digest.h[3] == d, sha1_bad_layout );
157
+	linker_assert ( &u.ddd.dd.digest.h[4] == e, sha1_bad_layout );
158
+	linker_assert ( &u.ddd.dd.data.dword[0] == w, sha1_bad_layout );
159
+
160
+	DBGC ( context, "SHA1 digesting:\n" );
161
+	DBGC_HDA ( context, 0, &context->ddd.dd.digest,
162
+		   sizeof ( context->ddd.dd.digest ) );
163
+	DBGC_HDA ( context, context->len, &context->ddd.dd.data,
164
+		   sizeof ( context->ddd.dd.data ) );
165
+
166
+	/* Convert h[0..4] to host-endian, and initialise a, b, c, d,
167
+	 * e, and w[0..15]
168
+	 */
169
+	for ( i = 0 ; i < ( sizeof ( u.ddd.dword ) /
170
+			    sizeof ( u.ddd.dword[0] ) ) ; i++ ) {
171
+		be32_to_cpus ( &context->ddd.dword[i] );
172
+		u.ddd.dword[i] = context->ddd.dword[i];
173
+	}
174
+
175
+	/* Initialise w[16..79] */
176
+	for ( i = 16 ; i < 80 ; i++ )
177
+		w[i] = rol32 ( ( w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16] ), 1 );
178
+
179
+	/* Main loop */
180
+	for ( i = 0 ; i < 80 ; i++ ) {
181
+		step = &sha1_steps[ i / 20 ];
182
+		f = step->f ( &u.v );
183
+		k = step->k;
184
+		temp = ( rol32 ( *a, 5 ) + f + *e + k + w[i] );
185
+		*e = *d;
186
+		*d = *c;
187
+		*c = rol32 ( *b, 30 );
188
+		*b = *a;
189
+		*a = temp;
190
+		DBGC2 ( context, "%2d : %08x %08x %08x %08x %08x\n",
191
+			i, *a, *b, *c, *d, *e );
192
+	}
193
+
194
+	/* Add chunk to hash and convert back to big-endian */
195
+	for ( i = 0 ; i < 5 ; i++ ) {
196
+		context->ddd.dd.digest.h[i] =
197
+			cpu_to_be32 ( context->ddd.dd.digest.h[i] +
198
+				      u.ddd.dd.digest.h[i] );
199
+	}
200
+
201
+	DBGC ( context, "SHA1 digested:\n" );
202
+	DBGC_HDA ( context, 0, &context->ddd.dd.digest,
203
+		   sizeof ( context->ddd.dd.digest ) );
204
+}
205
+
206
+/**
207
+ * Accumulate data with SHA-1 algorithm
208
+ *
209
+ * @v ctx		SHA-1 context
210
+ * @v data		Data
211
+ * @v len		Length of data
212
+ */
213
+static void sha1_update ( void *ctx, const void *data, size_t len ) {
214
+	struct sha1_context *context = ctx;
215
+	const uint8_t *byte = data;
216
+	size_t offset;
217
+
218
+	/* Accumulate data a byte at a time, performing the digest
219
+	 * whenever we fill the data buffer
220
+	 */
221
+	while ( len-- ) {
222
+		offset = ( context->len % sizeof ( context->ddd.dd.data ) );
223
+		context->ddd.dd.data.byte[offset] = *(byte++);
224
+		context->len++;
225
+		if ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 )
226
+			sha1_digest ( context );
227
+	}
228
+}
229
+
230
+/**
231
+ * Generate SHA-1 digest
232
+ *
233
+ * @v ctx		SHA-1 context
234
+ * @v out		Output buffer
235
+ */
236
+static void sha1_final ( void *ctx, void *out ) {
237
+	struct sha1_context *context = ctx;
238
+	uint64_t len_bits;
239
+	uint8_t pad;
240
+
241
+	/* Record length before pre-processing */
242
+	len_bits = cpu_to_be64 ( ( ( uint64_t ) context->len ) * 8 );
243
+
244
+	/* Pad with a single "1" bit followed by as many "0" bits as required */
245
+	pad = 0x80;
246
+	do {
247
+		sha1_update ( ctx, &pad, sizeof ( pad ) );
248
+		pad = 0x00;
249
+	} while ( ( context->len % sizeof ( context->ddd.dd.data ) ) !=
250
+		  offsetof ( typeof ( context->ddd.dd.data ), final.len ) );
251
+
252
+	/* Append length (in bits) */
253
+	sha1_update ( ctx, &len_bits, sizeof ( len_bits ) );
254
+	assert ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 );
255
+
256
+	/* Copy out final digest */
257
+	memcpy ( out, &context->ddd.dd.digest,
258
+		 sizeof ( context->ddd.dd.digest ) );
259
+}
260
+
261
+/** SHA-1 algorithm */
262
+struct digest_algorithm sha1_algorithm = {
263
+	.name		= "sha1",
264
+	.ctxsize	= sizeof ( struct sha1_context ),
265
+	.blocksize	= sizeof ( union sha1_block ),
266
+	.digestsize	= sizeof ( struct sha1_digest ),
267
+	.init		= sha1_init,
268
+	.update		= sha1_update,
269
+	.final		= sha1_final,
270
+};

+ 67
- 11
src/include/ipxe/sha1.h View File

@@ -1,24 +1,80 @@
1 1
 #ifndef _IPXE_SHA1_H
2 2
 #define _IPXE_SHA1_H
3 3
 
4
+/** @file
5
+ *
6
+ * SHA-1 algorithm
7
+ *
8
+ */
9
+
4 10
 FILE_LICENCE ( GPL2_OR_LATER );
5 11
 
6
-#include "crypto/axtls/crypto.h"
12
+#include <stdint.h>
13
+#include <ipxe/crypto.h>
7 14
 
8
-struct digest_algorithm;
15
+/** An SHA-1 digest */
16
+struct sha1_digest {
17
+	/** Hash output */
18
+	uint32_t h[5];
19
+};
9 20
 
10
-#define SHA1_CTX_SIZE sizeof ( SHA1_CTX )
11
-#define SHA1_DIGEST_SIZE SHA1_SIZE
21
+/** An SHA-1 data block */
22
+union sha1_block {
23
+	/** Raw bytes */
24
+	uint8_t byte[64];
25
+	/** Raw dwords */
26
+	uint32_t dword[16];
27
+	/** Final block structure */
28
+	struct {
29
+		/** Padding */
30
+		uint8_t pad[56];
31
+		/** Length in bits */
32
+		uint64_t len;
33
+	} final;
34
+};
12 35
 
13
-extern struct digest_algorithm sha1_algorithm;
36
+/** SHA-1 digest and data block
37
+ *
38
+ * The order of fields within this structure is designed to minimise
39
+ * code size.
40
+ */
41
+struct sha1_digest_data {
42
+	/** Digest of data already processed */
43
+	struct sha1_digest digest;
44
+	/** Accumulated data */
45
+	union sha1_block data;
46
+} __attribute__ (( packed ));
47
+
48
+/** SHA-1 digest and data block */
49
+union sha1_digest_data_dwords {
50
+	/** Digest and data block */
51
+	struct sha1_digest_data dd;
52
+	/** Raw dwords */
53
+	uint32_t dword[ sizeof ( struct sha1_digest_data ) /
54
+			sizeof ( uint32_t ) ];
55
+};
14 56
 
15
-/* SHA1-wrapping functions defined in sha1extra.c: */
57
+/** An SHA-1 context */
58
+struct sha1_context {
59
+	/** Amount of accumulated data */
60
+	size_t len;
61
+	/** Digest and accumulated data */
62
+	union sha1_digest_data_dwords ddd;
63
+} __attribute__ (( packed ));
16 64
 
17
-void prf_sha1 ( const void *key, size_t key_len, const char *label,
18
-		const void *data, size_t data_len, void *prf, size_t prf_len );
65
+/** SHA-1 context size */
66
+#define SHA1_CTX_SIZE sizeof ( struct sha1_context )
67
+
68
+/** SHA-1 digest size */
69
+#define SHA1_DIGEST_SIZE sizeof ( struct sha1_digest )
70
+
71
+extern struct digest_algorithm sha1_algorithm;
19 72
 
20
-void pbkdf2_sha1 ( const void *passphrase, size_t pass_len,
21
-		   const void *salt, size_t salt_len,
22
-		   int iterations, void *key, size_t key_len );
73
+extern void prf_sha1 ( const void *key, size_t key_len, const char *label,
74
+		       const void *data, size_t data_len, void *prf,
75
+		       size_t prf_len );
76
+extern void pbkdf2_sha1 ( const void *passphrase, size_t pass_len,
77
+			  const void *salt, size_t salt_len,
78
+			  int iterations, void *key, size_t key_len );
23 79
 
24 80
 #endif /* _IPXE_SHA1_H */

Loading…
Cancel
Save