Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewbonney 0:ec559500a63f 1 /*
andrewbonney 0:ec559500a63f 2 * FIPS-180-1 compliant SHA-1 implementation
andrewbonney 0:ec559500a63f 3 *
andrewbonney 0:ec559500a63f 4 * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
andrewbonney 0:ec559500a63f 5 * All rights reserved.
andrewbonney 0:ec559500a63f 6 *
andrewbonney 0:ec559500a63f 7 * This program is free software; you can redistribute it and/or modify
andrewbonney 0:ec559500a63f 8 * it under the terms of the GNU General Public License as published by
andrewbonney 0:ec559500a63f 9 * the Free Software Foundation; either version 2 of the License, or
andrewbonney 0:ec559500a63f 10 * (at your option) any later version.
andrewbonney 0:ec559500a63f 11 *
andrewbonney 0:ec559500a63f 12 * This program is distributed in the hope that it will be useful,
andrewbonney 0:ec559500a63f 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewbonney 0:ec559500a63f 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewbonney 0:ec559500a63f 15 * GNU General Public License for more details.
andrewbonney 0:ec559500a63f 16 *
andrewbonney 0:ec559500a63f 17 * You should have received a copy of the GNU General Public License along
andrewbonney 0:ec559500a63f 18 * with this program; if not, write to the Free Software Foundation, Inc.,
andrewbonney 0:ec559500a63f 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
andrewbonney 0:ec559500a63f 20 */
andrewbonney 0:ec559500a63f 21 /*
andrewbonney 0:ec559500a63f 22 * The SHA-1 standard was published by NIST in 1993.
andrewbonney 0:ec559500a63f 23 *
andrewbonney 0:ec559500a63f 24 * http://www.itl.nist.gov/fipspubs/fip180-1.htm
andrewbonney 0:ec559500a63f 25 */
andrewbonney 0:ec559500a63f 26
andrewbonney 0:ec559500a63f 27 #include "sha1config.h"
andrewbonney 0:ec559500a63f 28
andrewbonney 0:ec559500a63f 29 #if defined(POLARSSL_SHA1_C)
andrewbonney 0:ec559500a63f 30
andrewbonney 0:ec559500a63f 31 #include "sha1.h"
andrewbonney 0:ec559500a63f 32
andrewbonney 0:ec559500a63f 33 #include <string.h>
andrewbonney 0:ec559500a63f 34 #include <stdio.h>
andrewbonney 0:ec559500a63f 35
andrewbonney 0:ec559500a63f 36 /*
andrewbonney 0:ec559500a63f 37 * 32-bit integer manipulation macros (big endian)
andrewbonney 0:ec559500a63f 38 */
andrewbonney 0:ec559500a63f 39 #ifndef GET_ULONG_BE
andrewbonney 0:ec559500a63f 40 #define GET_ULONG_BE(n,b,i) \
andrewbonney 0:ec559500a63f 41 { \
andrewbonney 0:ec559500a63f 42 (n) = ( (unsigned long) (b)[(i) ] << 24 ) \
andrewbonney 0:ec559500a63f 43 | ( (unsigned long) (b)[(i) + 1] << 16 ) \
andrewbonney 0:ec559500a63f 44 | ( (unsigned long) (b)[(i) + 2] << 8 ) \
andrewbonney 0:ec559500a63f 45 | ( (unsigned long) (b)[(i) + 3] ); \
andrewbonney 0:ec559500a63f 46 }
andrewbonney 0:ec559500a63f 47 #endif
andrewbonney 0:ec559500a63f 48
andrewbonney 0:ec559500a63f 49 #ifndef PUT_ULONG_BE
andrewbonney 0:ec559500a63f 50 #define PUT_ULONG_BE(n,b,i) \
andrewbonney 0:ec559500a63f 51 { \
andrewbonney 0:ec559500a63f 52 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
andrewbonney 0:ec559500a63f 53 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
andrewbonney 0:ec559500a63f 54 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
andrewbonney 0:ec559500a63f 55 (b)[(i) + 3] = (unsigned char) ( (n) ); \
andrewbonney 0:ec559500a63f 56 }
andrewbonney 0:ec559500a63f 57 #endif
andrewbonney 0:ec559500a63f 58
andrewbonney 0:ec559500a63f 59 /*
andrewbonney 0:ec559500a63f 60 * SHA-1 context setup
andrewbonney 0:ec559500a63f 61 */
andrewbonney 0:ec559500a63f 62 void sha1_starts( sha1_context *ctx )
andrewbonney 0:ec559500a63f 63 {
andrewbonney 0:ec559500a63f 64 ctx->total[0] = 0;
andrewbonney 0:ec559500a63f 65 ctx->total[1] = 0;
andrewbonney 0:ec559500a63f 66
andrewbonney 0:ec559500a63f 67 ctx->state[0] = 0x67452301;
andrewbonney 0:ec559500a63f 68 ctx->state[1] = 0xEFCDAB89;
andrewbonney 0:ec559500a63f 69 ctx->state[2] = 0x98BADCFE;
andrewbonney 0:ec559500a63f 70 ctx->state[3] = 0x10325476;
andrewbonney 0:ec559500a63f 71 ctx->state[4] = 0xC3D2E1F0;
andrewbonney 0:ec559500a63f 72 }
andrewbonney 0:ec559500a63f 73
andrewbonney 0:ec559500a63f 74 static void sha1_process( sha1_context *ctx, const unsigned char data[64] )
andrewbonney 0:ec559500a63f 75 {
andrewbonney 0:ec559500a63f 76 unsigned long temp, W[16], A, B, C, D, E;
andrewbonney 0:ec559500a63f 77
andrewbonney 0:ec559500a63f 78 GET_ULONG_BE( W[ 0], data, 0 );
andrewbonney 0:ec559500a63f 79 GET_ULONG_BE( W[ 1], data, 4 );
andrewbonney 0:ec559500a63f 80 GET_ULONG_BE( W[ 2], data, 8 );
andrewbonney 0:ec559500a63f 81 GET_ULONG_BE( W[ 3], data, 12 );
andrewbonney 0:ec559500a63f 82 GET_ULONG_BE( W[ 4], data, 16 );
andrewbonney 0:ec559500a63f 83 GET_ULONG_BE( W[ 5], data, 20 );
andrewbonney 0:ec559500a63f 84 GET_ULONG_BE( W[ 6], data, 24 );
andrewbonney 0:ec559500a63f 85 GET_ULONG_BE( W[ 7], data, 28 );
andrewbonney 0:ec559500a63f 86 GET_ULONG_BE( W[ 8], data, 32 );
andrewbonney 0:ec559500a63f 87 GET_ULONG_BE( W[ 9], data, 36 );
andrewbonney 0:ec559500a63f 88 GET_ULONG_BE( W[10], data, 40 );
andrewbonney 0:ec559500a63f 89 GET_ULONG_BE( W[11], data, 44 );
andrewbonney 0:ec559500a63f 90 GET_ULONG_BE( W[12], data, 48 );
andrewbonney 0:ec559500a63f 91 GET_ULONG_BE( W[13], data, 52 );
andrewbonney 0:ec559500a63f 92 GET_ULONG_BE( W[14], data, 56 );
andrewbonney 0:ec559500a63f 93 GET_ULONG_BE( W[15], data, 60 );
andrewbonney 0:ec559500a63f 94
andrewbonney 0:ec559500a63f 95 #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
andrewbonney 0:ec559500a63f 96
andrewbonney 0:ec559500a63f 97 #define R(t) \
andrewbonney 0:ec559500a63f 98 ( \
andrewbonney 0:ec559500a63f 99 temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
andrewbonney 0:ec559500a63f 100 W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \
andrewbonney 0:ec559500a63f 101 ( W[t & 0x0F] = S(temp,1) ) \
andrewbonney 0:ec559500a63f 102 )
andrewbonney 0:ec559500a63f 103
andrewbonney 0:ec559500a63f 104 #define P(a,b,c,d,e,x) \
andrewbonney 0:ec559500a63f 105 { \
andrewbonney 0:ec559500a63f 106 e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
andrewbonney 0:ec559500a63f 107 }
andrewbonney 0:ec559500a63f 108
andrewbonney 0:ec559500a63f 109 A = ctx->state[0];
andrewbonney 0:ec559500a63f 110 B = ctx->state[1];
andrewbonney 0:ec559500a63f 111 C = ctx->state[2];
andrewbonney 0:ec559500a63f 112 D = ctx->state[3];
andrewbonney 0:ec559500a63f 113 E = ctx->state[4];
andrewbonney 0:ec559500a63f 114
andrewbonney 0:ec559500a63f 115 #define F(x,y,z) (z ^ (x & (y ^ z)))
andrewbonney 0:ec559500a63f 116 #define K 0x5A827999
andrewbonney 0:ec559500a63f 117
andrewbonney 0:ec559500a63f 118 P( A, B, C, D, E, W[0] );
andrewbonney 0:ec559500a63f 119 P( E, A, B, C, D, W[1] );
andrewbonney 0:ec559500a63f 120 P( D, E, A, B, C, W[2] );
andrewbonney 0:ec559500a63f 121 P( C, D, E, A, B, W[3] );
andrewbonney 0:ec559500a63f 122 P( B, C, D, E, A, W[4] );
andrewbonney 0:ec559500a63f 123 P( A, B, C, D, E, W[5] );
andrewbonney 0:ec559500a63f 124 P( E, A, B, C, D, W[6] );
andrewbonney 0:ec559500a63f 125 P( D, E, A, B, C, W[7] );
andrewbonney 0:ec559500a63f 126 P( C, D, E, A, B, W[8] );
andrewbonney 0:ec559500a63f 127 P( B, C, D, E, A, W[9] );
andrewbonney 0:ec559500a63f 128 P( A, B, C, D, E, W[10] );
andrewbonney 0:ec559500a63f 129 P( E, A, B, C, D, W[11] );
andrewbonney 0:ec559500a63f 130 P( D, E, A, B, C, W[12] );
andrewbonney 0:ec559500a63f 131 P( C, D, E, A, B, W[13] );
andrewbonney 0:ec559500a63f 132 P( B, C, D, E, A, W[14] );
andrewbonney 0:ec559500a63f 133 P( A, B, C, D, E, W[15] );
andrewbonney 0:ec559500a63f 134 P( E, A, B, C, D, R(16) );
andrewbonney 0:ec559500a63f 135 P( D, E, A, B, C, R(17) );
andrewbonney 0:ec559500a63f 136 P( C, D, E, A, B, R(18) );
andrewbonney 0:ec559500a63f 137 P( B, C, D, E, A, R(19) );
andrewbonney 0:ec559500a63f 138
andrewbonney 0:ec559500a63f 139 #undef K
andrewbonney 0:ec559500a63f 140 #undef F
andrewbonney 0:ec559500a63f 141
andrewbonney 0:ec559500a63f 142 #define F(x,y,z) (x ^ y ^ z)
andrewbonney 0:ec559500a63f 143 #define K 0x6ED9EBA1
andrewbonney 0:ec559500a63f 144
andrewbonney 0:ec559500a63f 145 P( A, B, C, D, E, R(20) );
andrewbonney 0:ec559500a63f 146 P( E, A, B, C, D, R(21) );
andrewbonney 0:ec559500a63f 147 P( D, E, A, B, C, R(22) );
andrewbonney 0:ec559500a63f 148 P( C, D, E, A, B, R(23) );
andrewbonney 0:ec559500a63f 149 P( B, C, D, E, A, R(24) );
andrewbonney 0:ec559500a63f 150 P( A, B, C, D, E, R(25) );
andrewbonney 0:ec559500a63f 151 P( E, A, B, C, D, R(26) );
andrewbonney 0:ec559500a63f 152 P( D, E, A, B, C, R(27) );
andrewbonney 0:ec559500a63f 153 P( C, D, E, A, B, R(28) );
andrewbonney 0:ec559500a63f 154 P( B, C, D, E, A, R(29) );
andrewbonney 0:ec559500a63f 155 P( A, B, C, D, E, R(30) );
andrewbonney 0:ec559500a63f 156 P( E, A, B, C, D, R(31) );
andrewbonney 0:ec559500a63f 157 P( D, E, A, B, C, R(32) );
andrewbonney 0:ec559500a63f 158 P( C, D, E, A, B, R(33) );
andrewbonney 0:ec559500a63f 159 P( B, C, D, E, A, R(34) );
andrewbonney 0:ec559500a63f 160 P( A, B, C, D, E, R(35) );
andrewbonney 0:ec559500a63f 161 P( E, A, B, C, D, R(36) );
andrewbonney 0:ec559500a63f 162 P( D, E, A, B, C, R(37) );
andrewbonney 0:ec559500a63f 163 P( C, D, E, A, B, R(38) );
andrewbonney 0:ec559500a63f 164 P( B, C, D, E, A, R(39) );
andrewbonney 0:ec559500a63f 165
andrewbonney 0:ec559500a63f 166 #undef K
andrewbonney 0:ec559500a63f 167 #undef F
andrewbonney 0:ec559500a63f 168
andrewbonney 0:ec559500a63f 169 #define F(x,y,z) ((x & y) | (z & (x | y)))
andrewbonney 0:ec559500a63f 170 #define K 0x8F1BBCDC
andrewbonney 0:ec559500a63f 171
andrewbonney 0:ec559500a63f 172 P( A, B, C, D, E, R(40) );
andrewbonney 0:ec559500a63f 173 P( E, A, B, C, D, R(41) );
andrewbonney 0:ec559500a63f 174 P( D, E, A, B, C, R(42) );
andrewbonney 0:ec559500a63f 175 P( C, D, E, A, B, R(43) );
andrewbonney 0:ec559500a63f 176 P( B, C, D, E, A, R(44) );
andrewbonney 0:ec559500a63f 177 P( A, B, C, D, E, R(45) );
andrewbonney 0:ec559500a63f 178 P( E, A, B, C, D, R(46) );
andrewbonney 0:ec559500a63f 179 P( D, E, A, B, C, R(47) );
andrewbonney 0:ec559500a63f 180 P( C, D, E, A, B, R(48) );
andrewbonney 0:ec559500a63f 181 P( B, C, D, E, A, R(49) );
andrewbonney 0:ec559500a63f 182 P( A, B, C, D, E, R(50) );
andrewbonney 0:ec559500a63f 183 P( E, A, B, C, D, R(51) );
andrewbonney 0:ec559500a63f 184 P( D, E, A, B, C, R(52) );
andrewbonney 0:ec559500a63f 185 P( C, D, E, A, B, R(53) );
andrewbonney 0:ec559500a63f 186 P( B, C, D, E, A, R(54) );
andrewbonney 0:ec559500a63f 187 P( A, B, C, D, E, R(55) );
andrewbonney 0:ec559500a63f 188 P( E, A, B, C, D, R(56) );
andrewbonney 0:ec559500a63f 189 P( D, E, A, B, C, R(57) );
andrewbonney 0:ec559500a63f 190 P( C, D, E, A, B, R(58) );
andrewbonney 0:ec559500a63f 191 P( B, C, D, E, A, R(59) );
andrewbonney 0:ec559500a63f 192
andrewbonney 0:ec559500a63f 193 #undef K
andrewbonney 0:ec559500a63f 194 #undef F
andrewbonney 0:ec559500a63f 195
andrewbonney 0:ec559500a63f 196 #define F(x,y,z) (x ^ y ^ z)
andrewbonney 0:ec559500a63f 197 #define K 0xCA62C1D6
andrewbonney 0:ec559500a63f 198
andrewbonney 0:ec559500a63f 199 P( A, B, C, D, E, R(60) );
andrewbonney 0:ec559500a63f 200 P( E, A, B, C, D, R(61) );
andrewbonney 0:ec559500a63f 201 P( D, E, A, B, C, R(62) );
andrewbonney 0:ec559500a63f 202 P( C, D, E, A, B, R(63) );
andrewbonney 0:ec559500a63f 203 P( B, C, D, E, A, R(64) );
andrewbonney 0:ec559500a63f 204 P( A, B, C, D, E, R(65) );
andrewbonney 0:ec559500a63f 205 P( E, A, B, C, D, R(66) );
andrewbonney 0:ec559500a63f 206 P( D, E, A, B, C, R(67) );
andrewbonney 0:ec559500a63f 207 P( C, D, E, A, B, R(68) );
andrewbonney 0:ec559500a63f 208 P( B, C, D, E, A, R(69) );
andrewbonney 0:ec559500a63f 209 P( A, B, C, D, E, R(70) );
andrewbonney 0:ec559500a63f 210 P( E, A, B, C, D, R(71) );
andrewbonney 0:ec559500a63f 211 P( D, E, A, B, C, R(72) );
andrewbonney 0:ec559500a63f 212 P( C, D, E, A, B, R(73) );
andrewbonney 0:ec559500a63f 213 P( B, C, D, E, A, R(74) );
andrewbonney 0:ec559500a63f 214 P( A, B, C, D, E, R(75) );
andrewbonney 0:ec559500a63f 215 P( E, A, B, C, D, R(76) );
andrewbonney 0:ec559500a63f 216 P( D, E, A, B, C, R(77) );
andrewbonney 0:ec559500a63f 217 P( C, D, E, A, B, R(78) );
andrewbonney 0:ec559500a63f 218 P( B, C, D, E, A, R(79) );
andrewbonney 0:ec559500a63f 219
andrewbonney 0:ec559500a63f 220 #undef K
andrewbonney 0:ec559500a63f 221 #undef F
andrewbonney 0:ec559500a63f 222
andrewbonney 0:ec559500a63f 223 ctx->state[0] += A;
andrewbonney 0:ec559500a63f 224 ctx->state[1] += B;
andrewbonney 0:ec559500a63f 225 ctx->state[2] += C;
andrewbonney 0:ec559500a63f 226 ctx->state[3] += D;
andrewbonney 0:ec559500a63f 227 ctx->state[4] += E;
andrewbonney 0:ec559500a63f 228 }
andrewbonney 0:ec559500a63f 229
andrewbonney 0:ec559500a63f 230 /*
andrewbonney 0:ec559500a63f 231 * SHA-1 process buffer
andrewbonney 0:ec559500a63f 232 */
andrewbonney 0:ec559500a63f 233 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )
andrewbonney 0:ec559500a63f 234 {
andrewbonney 0:ec559500a63f 235 int fill;
andrewbonney 0:ec559500a63f 236 unsigned long left;
andrewbonney 0:ec559500a63f 237
andrewbonney 0:ec559500a63f 238 if( ilen <= 0 )
andrewbonney 0:ec559500a63f 239 return;
andrewbonney 0:ec559500a63f 240
andrewbonney 0:ec559500a63f 241 left = ctx->total[0] & 0x3F;
andrewbonney 0:ec559500a63f 242 fill = 64 - left;
andrewbonney 0:ec559500a63f 243
andrewbonney 0:ec559500a63f 244 ctx->total[0] += ilen;
andrewbonney 0:ec559500a63f 245 ctx->total[0] &= 0xFFFFFFFF;
andrewbonney 0:ec559500a63f 246
andrewbonney 0:ec559500a63f 247 if( ctx->total[0] < (unsigned long) ilen )
andrewbonney 0:ec559500a63f 248 ctx->total[1]++;
andrewbonney 0:ec559500a63f 249
andrewbonney 0:ec559500a63f 250 if( left && ilen >= fill )
andrewbonney 0:ec559500a63f 251 {
andrewbonney 0:ec559500a63f 252 memcpy( (void *) (ctx->buffer + left),
andrewbonney 0:ec559500a63f 253 (void *) input, fill );
andrewbonney 0:ec559500a63f 254 sha1_process( ctx, ctx->buffer );
andrewbonney 0:ec559500a63f 255 input += fill;
andrewbonney 0:ec559500a63f 256 ilen -= fill;
andrewbonney 0:ec559500a63f 257 left = 0;
andrewbonney 0:ec559500a63f 258 }
andrewbonney 0:ec559500a63f 259
andrewbonney 0:ec559500a63f 260 while( ilen >= 64 )
andrewbonney 0:ec559500a63f 261 {
andrewbonney 0:ec559500a63f 262 sha1_process( ctx, input );
andrewbonney 0:ec559500a63f 263 input += 64;
andrewbonney 0:ec559500a63f 264 ilen -= 64;
andrewbonney 0:ec559500a63f 265 }
andrewbonney 0:ec559500a63f 266
andrewbonney 0:ec559500a63f 267 if( ilen > 0 )
andrewbonney 0:ec559500a63f 268 {
andrewbonney 0:ec559500a63f 269 memcpy( (void *) (ctx->buffer + left),
andrewbonney 0:ec559500a63f 270 (void *) input, ilen );
andrewbonney 0:ec559500a63f 271 }
andrewbonney 0:ec559500a63f 272 }
andrewbonney 0:ec559500a63f 273
andrewbonney 0:ec559500a63f 274 static const unsigned char sha1_padding[64] =
andrewbonney 0:ec559500a63f 275 {
andrewbonney 0:ec559500a63f 276 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
andrewbonney 0:ec559500a63f 277 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
andrewbonney 0:ec559500a63f 278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
andrewbonney 0:ec559500a63f 279 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
andrewbonney 0:ec559500a63f 280 };
andrewbonney 0:ec559500a63f 281
andrewbonney 0:ec559500a63f 282 /*
andrewbonney 0:ec559500a63f 283 * SHA-1 final digest
andrewbonney 0:ec559500a63f 284 */
andrewbonney 0:ec559500a63f 285 void sha1_finish( sha1_context *ctx, unsigned char output[20] )
andrewbonney 0:ec559500a63f 286 {
andrewbonney 0:ec559500a63f 287 unsigned long last, padn;
andrewbonney 0:ec559500a63f 288 unsigned long high, low;
andrewbonney 0:ec559500a63f 289 unsigned char msglen[8];
andrewbonney 0:ec559500a63f 290
andrewbonney 0:ec559500a63f 291 high = ( ctx->total[0] >> 29 )
andrewbonney 0:ec559500a63f 292 | ( ctx->total[1] << 3 );
andrewbonney 0:ec559500a63f 293 low = ( ctx->total[0] << 3 );
andrewbonney 0:ec559500a63f 294
andrewbonney 0:ec559500a63f 295 PUT_ULONG_BE( high, msglen, 0 );
andrewbonney 0:ec559500a63f 296 PUT_ULONG_BE( low, msglen, 4 );
andrewbonney 0:ec559500a63f 297
andrewbonney 0:ec559500a63f 298 last = ctx->total[0] & 0x3F;
andrewbonney 0:ec559500a63f 299 padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
andrewbonney 0:ec559500a63f 300
andrewbonney 0:ec559500a63f 301 sha1_update( ctx, (unsigned char *) sha1_padding, padn );
andrewbonney 0:ec559500a63f 302 sha1_update( ctx, msglen, 8 );
andrewbonney 0:ec559500a63f 303
andrewbonney 0:ec559500a63f 304 PUT_ULONG_BE( ctx->state[0], output, 0 );
andrewbonney 0:ec559500a63f 305 PUT_ULONG_BE( ctx->state[1], output, 4 );
andrewbonney 0:ec559500a63f 306 PUT_ULONG_BE( ctx->state[2], output, 8 );
andrewbonney 0:ec559500a63f 307 PUT_ULONG_BE( ctx->state[3], output, 12 );
andrewbonney 0:ec559500a63f 308 PUT_ULONG_BE( ctx->state[4], output, 16 );
andrewbonney 0:ec559500a63f 309 }
andrewbonney 0:ec559500a63f 310
andrewbonney 0:ec559500a63f 311 /*
andrewbonney 0:ec559500a63f 312 * output = SHA-1( input buffer )
andrewbonney 0:ec559500a63f 313 */
andrewbonney 0:ec559500a63f 314 void sha1( const unsigned char *input, int ilen, unsigned char output[20] )
andrewbonney 0:ec559500a63f 315 {
andrewbonney 0:ec559500a63f 316 sha1_context ctx;
andrewbonney 0:ec559500a63f 317
andrewbonney 0:ec559500a63f 318 sha1_starts( &ctx );
andrewbonney 0:ec559500a63f 319 sha1_update( &ctx, input, ilen );
andrewbonney 0:ec559500a63f 320 sha1_finish( &ctx, output );
andrewbonney 0:ec559500a63f 321
andrewbonney 0:ec559500a63f 322 memset( &ctx, 0, sizeof( sha1_context ) );
andrewbonney 0:ec559500a63f 323 }
andrewbonney 0:ec559500a63f 324
andrewbonney 0:ec559500a63f 325 /*
andrewbonney 0:ec559500a63f 326 * output = SHA-1( file contents )
andrewbonney 0:ec559500a63f 327 */
andrewbonney 0:ec559500a63f 328 #if 0 //No need for that
andrewbonney 0:ec559500a63f 329 int sha1_file( const char *path, unsigned char output[20] )
andrewbonney 0:ec559500a63f 330 {
andrewbonney 0:ec559500a63f 331 FILE *f;
andrewbonney 0:ec559500a63f 332 size_t n;
andrewbonney 0:ec559500a63f 333 sha1_context ctx;
andrewbonney 0:ec559500a63f 334 unsigned char buf[1024];
andrewbonney 0:ec559500a63f 335
andrewbonney 0:ec559500a63f 336 if( ( f = fopen( path, "rb" ) ) == NULL )
andrewbonney 0:ec559500a63f 337 return( 1 );
andrewbonney 0:ec559500a63f 338
andrewbonney 0:ec559500a63f 339 sha1_starts( &ctx );
andrewbonney 0:ec559500a63f 340
andrewbonney 0:ec559500a63f 341 while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
andrewbonney 0:ec559500a63f 342 sha1_update( &ctx, buf, (int) n );
andrewbonney 0:ec559500a63f 343
andrewbonney 0:ec559500a63f 344 sha1_finish( &ctx, output );
andrewbonney 0:ec559500a63f 345
andrewbonney 0:ec559500a63f 346 memset( &ctx, 0, sizeof( sha1_context ) );
andrewbonney 0:ec559500a63f 347
andrewbonney 0:ec559500a63f 348 if( ferror( f ) != 0 )
andrewbonney 0:ec559500a63f 349 {
andrewbonney 0:ec559500a63f 350 fclose( f );
andrewbonney 0:ec559500a63f 351 return( 2 );
andrewbonney 0:ec559500a63f 352 }
andrewbonney 0:ec559500a63f 353
andrewbonney 0:ec559500a63f 354 fclose( f );
andrewbonney 0:ec559500a63f 355 return( 0 );
andrewbonney 0:ec559500a63f 356 }
andrewbonney 0:ec559500a63f 357 #endif
andrewbonney 0:ec559500a63f 358
andrewbonney 0:ec559500a63f 359 /*
andrewbonney 0:ec559500a63f 360 * SHA-1 HMAC context setup
andrewbonney 0:ec559500a63f 361 */
andrewbonney 0:ec559500a63f 362 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen )
andrewbonney 0:ec559500a63f 363 {
andrewbonney 0:ec559500a63f 364 int i;
andrewbonney 0:ec559500a63f 365 unsigned char sum[20];
andrewbonney 0:ec559500a63f 366
andrewbonney 0:ec559500a63f 367 if( keylen > 64 )
andrewbonney 0:ec559500a63f 368 {
andrewbonney 0:ec559500a63f 369 sha1( key, keylen, sum );
andrewbonney 0:ec559500a63f 370 keylen = 20;
andrewbonney 0:ec559500a63f 371 key = sum;
andrewbonney 0:ec559500a63f 372 }
andrewbonney 0:ec559500a63f 373
andrewbonney 0:ec559500a63f 374 memset( ctx->ipad, 0x36, 64 );
andrewbonney 0:ec559500a63f 375 memset( ctx->opad, 0x5C, 64 );
andrewbonney 0:ec559500a63f 376
andrewbonney 0:ec559500a63f 377 for( i = 0; i < keylen; i++ )
andrewbonney 0:ec559500a63f 378 {
andrewbonney 0:ec559500a63f 379 ctx->ipad[i] = (unsigned char)( ctx->ipad[i] ^ key[i] );
andrewbonney 0:ec559500a63f 380 ctx->opad[i] = (unsigned char)( ctx->opad[i] ^ key[i] );
andrewbonney 0:ec559500a63f 381 }
andrewbonney 0:ec559500a63f 382
andrewbonney 0:ec559500a63f 383 sha1_starts( ctx );
andrewbonney 0:ec559500a63f 384 sha1_update( ctx, ctx->ipad, 64 );
andrewbonney 0:ec559500a63f 385
andrewbonney 0:ec559500a63f 386 memset( sum, 0, sizeof( sum ) );
andrewbonney 0:ec559500a63f 387 }
andrewbonney 0:ec559500a63f 388
andrewbonney 0:ec559500a63f 389 /*
andrewbonney 0:ec559500a63f 390 * SHA-1 HMAC process buffer
andrewbonney 0:ec559500a63f 391 */
andrewbonney 0:ec559500a63f 392 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen )
andrewbonney 0:ec559500a63f 393 {
andrewbonney 0:ec559500a63f 394 sha1_update( ctx, input, ilen );
andrewbonney 0:ec559500a63f 395 }
andrewbonney 0:ec559500a63f 396
andrewbonney 0:ec559500a63f 397 /*
andrewbonney 0:ec559500a63f 398 * SHA-1 HMAC final digest
andrewbonney 0:ec559500a63f 399 */
andrewbonney 0:ec559500a63f 400 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] )
andrewbonney 0:ec559500a63f 401 {
andrewbonney 0:ec559500a63f 402 unsigned char tmpbuf[20];
andrewbonney 0:ec559500a63f 403
andrewbonney 0:ec559500a63f 404 sha1_finish( ctx, tmpbuf );
andrewbonney 0:ec559500a63f 405 sha1_starts( ctx );
andrewbonney 0:ec559500a63f 406 sha1_update( ctx, ctx->opad, 64 );
andrewbonney 0:ec559500a63f 407 sha1_update( ctx, tmpbuf, 20 );
andrewbonney 0:ec559500a63f 408 sha1_finish( ctx, output );
andrewbonney 0:ec559500a63f 409
andrewbonney 0:ec559500a63f 410 memset( tmpbuf, 0, sizeof( tmpbuf ) );
andrewbonney 0:ec559500a63f 411 }
andrewbonney 0:ec559500a63f 412
andrewbonney 0:ec559500a63f 413 /*
andrewbonney 0:ec559500a63f 414 * SHA1 HMAC context reset
andrewbonney 0:ec559500a63f 415 */
andrewbonney 0:ec559500a63f 416 void sha1_hmac_reset( sha1_context *ctx )
andrewbonney 0:ec559500a63f 417 {
andrewbonney 0:ec559500a63f 418 sha1_starts( ctx );
andrewbonney 0:ec559500a63f 419 sha1_update( ctx, ctx->ipad, 64 );
andrewbonney 0:ec559500a63f 420 }
andrewbonney 0:ec559500a63f 421
andrewbonney 0:ec559500a63f 422 /*
andrewbonney 0:ec559500a63f 423 * output = HMAC-SHA-1( hmac key, input buffer )
andrewbonney 0:ec559500a63f 424 */
andrewbonney 0:ec559500a63f 425 void sha1_hmac( const unsigned char *key, int keylen,
andrewbonney 0:ec559500a63f 426 const unsigned char *input, int ilen,
andrewbonney 0:ec559500a63f 427 unsigned char output[20] )
andrewbonney 0:ec559500a63f 428 {
andrewbonney 0:ec559500a63f 429 sha1_context ctx;
andrewbonney 0:ec559500a63f 430
andrewbonney 0:ec559500a63f 431 sha1_hmac_starts( &ctx, key, keylen );
andrewbonney 0:ec559500a63f 432 sha1_hmac_update( &ctx, input, ilen );
andrewbonney 0:ec559500a63f 433 sha1_hmac_finish( &ctx, output );
andrewbonney 0:ec559500a63f 434
andrewbonney 0:ec559500a63f 435 memset( &ctx, 0, sizeof( sha1_context ) );
andrewbonney 0:ec559500a63f 436 }
andrewbonney 0:ec559500a63f 437
andrewbonney 0:ec559500a63f 438 #if defined(POLARSSL_SELF_TEST)
andrewbonney 0:ec559500a63f 439 /*
andrewbonney 0:ec559500a63f 440 * FIPS-180-1 test vectors
andrewbonney 0:ec559500a63f 441 */
andrewbonney 0:ec559500a63f 442 static unsigned char sha1_test_buf[3][57] =
andrewbonney 0:ec559500a63f 443 {
andrewbonney 0:ec559500a63f 444 { "abc" },
andrewbonney 0:ec559500a63f 445 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
andrewbonney 0:ec559500a63f 446 { "" }
andrewbonney 0:ec559500a63f 447 };
andrewbonney 0:ec559500a63f 448
andrewbonney 0:ec559500a63f 449 static const int sha1_test_buflen[3] =
andrewbonney 0:ec559500a63f 450 {
andrewbonney 0:ec559500a63f 451 3, 56, 1000
andrewbonney 0:ec559500a63f 452 };
andrewbonney 0:ec559500a63f 453
andrewbonney 0:ec559500a63f 454 static const unsigned char sha1_test_sum[3][20] =
andrewbonney 0:ec559500a63f 455 {
andrewbonney 0:ec559500a63f 456 { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
andrewbonney 0:ec559500a63f 457 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
andrewbonney 0:ec559500a63f 458 { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
andrewbonney 0:ec559500a63f 459 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
andrewbonney 0:ec559500a63f 460 { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
andrewbonney 0:ec559500a63f 461 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
andrewbonney 0:ec559500a63f 462 };
andrewbonney 0:ec559500a63f 463
andrewbonney 0:ec559500a63f 464 /*
andrewbonney 0:ec559500a63f 465 * RFC 2202 test vectors
andrewbonney 0:ec559500a63f 466 */
andrewbonney 0:ec559500a63f 467 static unsigned char sha1_hmac_test_key[7][26] =
andrewbonney 0:ec559500a63f 468 {
andrewbonney 0:ec559500a63f 469 { "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
andrewbonney 0:ec559500a63f 470 "\x0B\x0B\x0B\x0B" },
andrewbonney 0:ec559500a63f 471 { "Jefe" },
andrewbonney 0:ec559500a63f 472 { "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
andrewbonney 0:ec559500a63f 473 "\xAA\xAA\xAA\xAA" },
andrewbonney 0:ec559500a63f 474 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
andrewbonney 0:ec559500a63f 475 "\x11\x12\x13\x14\x15\x16\x17\x18\x19" },
andrewbonney 0:ec559500a63f 476 { "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C"
andrewbonney 0:ec559500a63f 477 "\x0C\x0C\x0C\x0C" },
andrewbonney 0:ec559500a63f 478 { "" }, /* 0xAA 80 times */
andrewbonney 0:ec559500a63f 479 { "" }
andrewbonney 0:ec559500a63f 480 };
andrewbonney 0:ec559500a63f 481
andrewbonney 0:ec559500a63f 482 static const int sha1_hmac_test_keylen[7] =
andrewbonney 0:ec559500a63f 483 {
andrewbonney 0:ec559500a63f 484 20, 4, 20, 25, 20, 80, 80
andrewbonney 0:ec559500a63f 485 };
andrewbonney 0:ec559500a63f 486
andrewbonney 0:ec559500a63f 487 static unsigned char sha1_hmac_test_buf[7][74] =
andrewbonney 0:ec559500a63f 488 {
andrewbonney 0:ec559500a63f 489 { "Hi There" },
andrewbonney 0:ec559500a63f 490 { "what do ya want for nothing?" },
andrewbonney 0:ec559500a63f 491 { "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
andrewbonney 0:ec559500a63f 492 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
andrewbonney 0:ec559500a63f 493 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
andrewbonney 0:ec559500a63f 494 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
andrewbonney 0:ec559500a63f 495 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" },
andrewbonney 0:ec559500a63f 496 { "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
andrewbonney 0:ec559500a63f 497 "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
andrewbonney 0:ec559500a63f 498 "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
andrewbonney 0:ec559500a63f 499 "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
andrewbonney 0:ec559500a63f 500 "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" },
andrewbonney 0:ec559500a63f 501 { "Test With Truncation" },
andrewbonney 0:ec559500a63f 502 { "Test Using Larger Than Block-Size Key - Hash Key First" },
andrewbonney 0:ec559500a63f 503 { "Test Using Larger Than Block-Size Key and Larger"
andrewbonney 0:ec559500a63f 504 " Than One Block-Size Data" }
andrewbonney 0:ec559500a63f 505 };
andrewbonney 0:ec559500a63f 506
andrewbonney 0:ec559500a63f 507 static const int sha1_hmac_test_buflen[7] =
andrewbonney 0:ec559500a63f 508 {
andrewbonney 0:ec559500a63f 509 8, 28, 50, 50, 20, 54, 73
andrewbonney 0:ec559500a63f 510 };
andrewbonney 0:ec559500a63f 511
andrewbonney 0:ec559500a63f 512 static const unsigned char sha1_hmac_test_sum[7][20] =
andrewbonney 0:ec559500a63f 513 {
andrewbonney 0:ec559500a63f 514 { 0xB6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xE2, 0x8B,
andrewbonney 0:ec559500a63f 515 0xC0, 0xB6, 0xFB, 0x37, 0x8C, 0x8E, 0xF1, 0x46, 0xBE, 0x00 },
andrewbonney 0:ec559500a63f 516 { 0xEF, 0xFC, 0xDF, 0x6A, 0xE5, 0xEB, 0x2F, 0xA2, 0xD2, 0x74,
andrewbonney 0:ec559500a63f 517 0x16, 0xD5, 0xF1, 0x84, 0xDF, 0x9C, 0x25, 0x9A, 0x7C, 0x79 },
andrewbonney 0:ec559500a63f 518 { 0x12, 0x5D, 0x73, 0x42, 0xB9, 0xAC, 0x11, 0xCD, 0x91, 0xA3,
andrewbonney 0:ec559500a63f 519 0x9A, 0xF4, 0x8A, 0xA1, 0x7B, 0x4F, 0x63, 0xF1, 0x75, 0xD3 },
andrewbonney 0:ec559500a63f 520 { 0x4C, 0x90, 0x07, 0xF4, 0x02, 0x62, 0x50, 0xC6, 0xBC, 0x84,
andrewbonney 0:ec559500a63f 521 0x14, 0xF9, 0xBF, 0x50, 0xC8, 0x6C, 0x2D, 0x72, 0x35, 0xDA },
andrewbonney 0:ec559500a63f 522 { 0x4C, 0x1A, 0x03, 0x42, 0x4B, 0x55, 0xE0, 0x7F, 0xE7, 0xF2,
andrewbonney 0:ec559500a63f 523 0x7B, 0xE1 },
andrewbonney 0:ec559500a63f 524 { 0xAA, 0x4A, 0xE5, 0xE1, 0x52, 0x72, 0xD0, 0x0E, 0x95, 0x70,
andrewbonney 0:ec559500a63f 525 0x56, 0x37, 0xCE, 0x8A, 0x3B, 0x55, 0xED, 0x40, 0x21, 0x12 },
andrewbonney 0:ec559500a63f 526 { 0xE8, 0xE9, 0x9D, 0x0F, 0x45, 0x23, 0x7D, 0x78, 0x6D, 0x6B,
andrewbonney 0:ec559500a63f 527 0xBA, 0xA7, 0x96, 0x5C, 0x78, 0x08, 0xBB, 0xFF, 0x1A, 0x91 }
andrewbonney 0:ec559500a63f 528 };
andrewbonney 0:ec559500a63f 529
andrewbonney 0:ec559500a63f 530 /*
andrewbonney 0:ec559500a63f 531 * Checkup routine
andrewbonney 0:ec559500a63f 532 */
andrewbonney 0:ec559500a63f 533 int sha1_self_test( int verbose )
andrewbonney 0:ec559500a63f 534 {
andrewbonney 0:ec559500a63f 535 int i, j, buflen;
andrewbonney 0:ec559500a63f 536 unsigned char buf[1024];
andrewbonney 0:ec559500a63f 537 unsigned char sha1sum[20];
andrewbonney 0:ec559500a63f 538 sha1_context ctx;
andrewbonney 0:ec559500a63f 539
andrewbonney 0:ec559500a63f 540 /*
andrewbonney 0:ec559500a63f 541 * SHA-1
andrewbonney 0:ec559500a63f 542 */
andrewbonney 0:ec559500a63f 543 for( i = 0; i < 3; i++ )
andrewbonney 0:ec559500a63f 544 {
andrewbonney 0:ec559500a63f 545 if( verbose != 0 )
andrewbonney 0:ec559500a63f 546 printf( " SHA-1 test #%d: ", i + 1 );
andrewbonney 0:ec559500a63f 547
andrewbonney 0:ec559500a63f 548 sha1_starts( &ctx );
andrewbonney 0:ec559500a63f 549
andrewbonney 0:ec559500a63f 550 if( i == 2 )
andrewbonney 0:ec559500a63f 551 {
andrewbonney 0:ec559500a63f 552 memset( buf, 'a', buflen = 1000 );
andrewbonney 0:ec559500a63f 553
andrewbonney 0:ec559500a63f 554 for( j = 0; j < 1000; j++ )
andrewbonney 0:ec559500a63f 555 sha1_update( &ctx, buf, buflen );
andrewbonney 0:ec559500a63f 556 }
andrewbonney 0:ec559500a63f 557 else
andrewbonney 0:ec559500a63f 558 sha1_update( &ctx, sha1_test_buf[i],
andrewbonney 0:ec559500a63f 559 sha1_test_buflen[i] );
andrewbonney 0:ec559500a63f 560
andrewbonney 0:ec559500a63f 561 sha1_finish( &ctx, sha1sum );
andrewbonney 0:ec559500a63f 562
andrewbonney 0:ec559500a63f 563 if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 )
andrewbonney 0:ec559500a63f 564 {
andrewbonney 0:ec559500a63f 565 if( verbose != 0 )
andrewbonney 0:ec559500a63f 566 printf( "failed\n" );
andrewbonney 0:ec559500a63f 567
andrewbonney 0:ec559500a63f 568 return( 1 );
andrewbonney 0:ec559500a63f 569 }
andrewbonney 0:ec559500a63f 570
andrewbonney 0:ec559500a63f 571 if( verbose != 0 )
andrewbonney 0:ec559500a63f 572 printf( "passed\n" );
andrewbonney 0:ec559500a63f 573 }
andrewbonney 0:ec559500a63f 574
andrewbonney 0:ec559500a63f 575 if( verbose != 0 )
andrewbonney 0:ec559500a63f 576 printf( "\n" );
andrewbonney 0:ec559500a63f 577
andrewbonney 0:ec559500a63f 578 for( i = 0; i < 7; i++ )
andrewbonney 0:ec559500a63f 579 {
andrewbonney 0:ec559500a63f 580 if( verbose != 0 )
andrewbonney 0:ec559500a63f 581 printf( " HMAC-SHA-1 test #%d: ", i + 1 );
andrewbonney 0:ec559500a63f 582
andrewbonney 0:ec559500a63f 583 if( i == 5 || i == 6 )
andrewbonney 0:ec559500a63f 584 {
andrewbonney 0:ec559500a63f 585 memset( buf, '\xAA', buflen = 80 );
andrewbonney 0:ec559500a63f 586 sha1_hmac_starts( &ctx, buf, buflen );
andrewbonney 0:ec559500a63f 587 }
andrewbonney 0:ec559500a63f 588 else
andrewbonney 0:ec559500a63f 589 sha1_hmac_starts( &ctx, sha1_hmac_test_key[i],
andrewbonney 0:ec559500a63f 590 sha1_hmac_test_keylen[i] );
andrewbonney 0:ec559500a63f 591
andrewbonney 0:ec559500a63f 592 sha1_hmac_update( &ctx, sha1_hmac_test_buf[i],
andrewbonney 0:ec559500a63f 593 sha1_hmac_test_buflen[i] );
andrewbonney 0:ec559500a63f 594
andrewbonney 0:ec559500a63f 595 sha1_hmac_finish( &ctx, sha1sum );
andrewbonney 0:ec559500a63f 596
andrewbonney 0:ec559500a63f 597 buflen = ( i == 4 ) ? 12 : 20;
andrewbonney 0:ec559500a63f 598
andrewbonney 0:ec559500a63f 599 if( memcmp( sha1sum, sha1_hmac_test_sum[i], buflen ) != 0 )
andrewbonney 0:ec559500a63f 600 {
andrewbonney 0:ec559500a63f 601 if( verbose != 0 )
andrewbonney 0:ec559500a63f 602 printf( "failed\n" );
andrewbonney 0:ec559500a63f 603
andrewbonney 0:ec559500a63f 604 return( 1 );
andrewbonney 0:ec559500a63f 605 }
andrewbonney 0:ec559500a63f 606
andrewbonney 0:ec559500a63f 607 if( verbose != 0 )
andrewbonney 0:ec559500a63f 608 printf( "passed\n" );
andrewbonney 0:ec559500a63f 609 }
andrewbonney 0:ec559500a63f 610
andrewbonney 0:ec559500a63f 611 if( verbose != 0 )
andrewbonney 0:ec559500a63f 612 printf( "\n" );
andrewbonney 0:ec559500a63f 613
andrewbonney 0:ec559500a63f 614 return( 0 );
andrewbonney 0:ec559500a63f 615 }
andrewbonney 0:ec559500a63f 616
andrewbonney 0:ec559500a63f 617 #endif
andrewbonney 0:ec559500a63f 618
andrewbonney 0:ec559500a63f 619 #endif