Browse Source

[802.11] Eliminate use of AXTLS-specific SHA1_SIZE constant

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
4100edf9d7
1 changed files with 17 additions and 16 deletions
  1. 17
    16
      src/crypto/sha1extra.c

+ 17
- 16
src/crypto/sha1extra.c View File

@@ -47,7 +47,7 @@ void prf_sha1 ( const void *key, size_t key_len, const char *label,
47 47
 	u8 keym[key_len];	/* modifiable copy of key */
48 48
 	u8 in[strlen ( label ) + 1 + data_len + 1]; /* message to HMAC */
49 49
 	u8 *in_blknr;		/* pointer to last byte of in, block number */
50
-	u8 out[SHA1_SIZE];	/* HMAC-SHA1 result */
50
+	u8 out[SHA1_DIGEST_SIZE]; /* HMAC-SHA1 result */
51 51
 	u8 sha1_ctx[SHA1_CTX_SIZE]; /* SHA1 context */
52 52
 	const size_t label_len = strlen ( label );
53 53
 
@@ -68,14 +68,14 @@ void prf_sha1 ( const void *key, size_t key_len, const char *label,
68 68
 		hmac_update ( &sha1_algorithm, sha1_ctx, in, sizeof ( in ) );
69 69
 		hmac_final ( &sha1_algorithm, sha1_ctx, keym, &key_len, out );
70 70
 
71
-		if ( prf_len <= SHA1_SIZE ) {
71
+		if ( prf_len <= sizeof ( out ) ) {
72 72
 			memcpy ( prf, out, prf_len );
73 73
 			break;
74 74
 		}
75 75
 
76
-		memcpy ( prf, out, SHA1_SIZE );
77
-		prf_len -= SHA1_SIZE;
78
-		prf += SHA1_SIZE;
76
+		memcpy ( prf, out, sizeof ( out ) );
77
+		prf_len -= sizeof ( out );
78
+		prf += sizeof ( out );
79 79
 	}
80 80
 }
81 81
 
@@ -98,30 +98,31 @@ static void pbkdf2_sha1_f ( const void *passphrase, size_t pass_len,
98 98
 {
99 99
 	u8 pass[pass_len];	/* modifiable passphrase */
100 100
 	u8 in[salt_len + 4];	/* input buffer to first round */
101
-	u8 last[SHA1_SIZE];	/* output of round N, input of N+1 */
101
+	u8 last[SHA1_DIGEST_SIZE]; /* output of round N, input of N+1 */
102 102
 	u8 sha1_ctx[SHA1_CTX_SIZE];
103 103
 	u8 *next_in = in;	/* changed to `last' after first round */
104 104
 	int next_size = sizeof ( in );
105
-	int i, j;
105
+	int i;
106
+	unsigned int j;
106 107
 
107 108
 	blocknr = htonl ( blocknr );
108 109
 
109 110
 	memcpy ( pass, passphrase, pass_len );
110 111
 	memcpy ( in, salt, salt_len );
111 112
 	memcpy ( in + salt_len, &blocknr, 4 );
112
-	memset ( block, 0, SHA1_SIZE );
113
+	memset ( block, 0, sizeof ( last ) );
113 114
 
114 115
 	for ( i = 0; i < iterations; i++ ) {
115 116
 		hmac_init ( &sha1_algorithm, sha1_ctx, pass, &pass_len );
116 117
 		hmac_update ( &sha1_algorithm, sha1_ctx, next_in, next_size );
117 118
 		hmac_final ( &sha1_algorithm, sha1_ctx, pass, &pass_len, last );
118 119
 
119
-		for ( j = 0; j < SHA1_SIZE; j++ ) {
120
+		for ( j = 0; j < sizeof ( last ); j++ ) {
120 121
 			block[j] ^= last[j];
121 122
 		}
122 123
 
123 124
 		next_in = last;
124
-		next_size = SHA1_SIZE;
125
+		next_size = sizeof ( last );
125 126
 	}
126 127
 }
127 128
 
@@ -147,20 +148,20 @@ void pbkdf2_sha1 ( const void *passphrase, size_t pass_len,
147 148
 		   const void *salt, size_t salt_len,
148 149
 		   int iterations, void *key, size_t key_len )
149 150
 {
150
-	u32 blocks = ( key_len + SHA1_SIZE - 1 ) / SHA1_SIZE;
151
+	u32 blocks = ( key_len + SHA1_DIGEST_SIZE - 1 ) / SHA1_DIGEST_SIZE;
151 152
 	u32 blk;
152
-	u8 buf[SHA1_SIZE];
153
+	u8 buf[SHA1_DIGEST_SIZE];
153 154
 
154 155
 	for ( blk = 1; blk <= blocks; blk++ ) {
155 156
 		pbkdf2_sha1_f ( passphrase, pass_len, salt, salt_len,
156 157
 				iterations, blk, buf );
157
-		if ( key_len <= SHA1_SIZE ) {
158
+		if ( key_len <= sizeof ( buf ) ) {
158 159
 			memcpy ( key, buf, key_len );
159 160
 			break;
160 161
 		}
161 162
 
162
-		memcpy ( key, buf, SHA1_SIZE );
163
-		key_len -= SHA1_SIZE;
164
-		key += SHA1_SIZE;
163
+		memcpy ( key, buf, sizeof ( buf ) );
164
+		key_len -= sizeof ( buf );
165
+		key += sizeof ( buf );
165 166
 	}
166 167
 }

Loading…
Cancel
Save