9 typedef UINT32 uint32_t;
18 #define GET_UINT32_BE(n,b,i) \
20 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
21 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
22 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
23 | ( (uint32_t) (b)[(i) + 3] ); \
28 #define PUT_UINT32_BE(n,b,i) \
30 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
31 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
32 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
33 (b)[(i) + 3] = (unsigned char) ( (n) ); \
37 int unhexify(
unsigned char *obuf,
const char *ibuf)
40 int len = strlen(ibuf) / 2;
41 assert(!(strlen(ibuf) %1));
46 if( c >=
'0' && c <=
'9' )
48 else if( c >=
'a' && c <=
'f' )
50 else if( c >=
'A' && c <=
'F' )
56 if( c2 >=
'0' && c2 <=
'9' )
58 else if( c2 >=
'a' && c2 <=
'f' )
60 else if( c2 >=
'A' && c2 <=
'F' )
65 *obuf++ = ( c << 4 ) | c2;
71 void hexify(
unsigned char *obuf,
const unsigned char *ibuf,
int len)
83 *obuf++ =
'a' + h - 10;
88 *obuf++ =
'a' + l - 10;
104 static int rnd_std_rand(
void *rng_state,
unsigned char *output,
size_t len )
108 if( rng_state != NULL )
111 for( i = 0; i < len; ++i )
122 static int rnd_zero_rand(
void *rng_state,
unsigned char *output,
size_t len )
124 if( rng_state != NULL )
127 memset( output, 0, len );
154 if( rng_state == NULL )
163 memcpy( output, info->
buf, use_len );
164 info->
buf += use_len;
168 if( len - use_len > 0 )
169 return(
rnd_std_rand( NULL, output + use_len, len - use_len ) );
198 uint32_t i, *k, sum, delta=0x9E3779B9;
199 unsigned char result[4];
201 if( rng_state == NULL )
208 size_t use_len = ( len > 4 ) ? 4 : len;
211 for( i = 0; i < 32; i++ )
213 info->
v0 += (((info->
v1 << 4) ^ (info->
v1 >> 5)) + info->
v1) ^ (sum + k[sum & 3]);
215 info->
v1 += (((info->
v0 << 4) ^ (info->
v0 >> 5)) + info->
v0) ^ (sum + k[(sum>>11) & 3]);
219 memcpy( output, result, use_len );
229 #ifdef POLARSSL_ERROR_C
232 FCT_SUITE_BGN(test_suite_error)
234 #ifdef POLARSSL_AES_C
236 FCT_TEST_BGN(single_low_error)
242 fct_chk( strcmp( buf,
"AES - Invalid key length" ) == 0 );
247 #ifdef POLARSSL_RSA_C
249 FCT_TEST_BGN(single_high_error)
255 fct_chk( strcmp( buf,
"RSA - Bad input parameters to function" ) == 0 );
260 #ifdef POLARSSL_AES_C
261 #ifdef POLARSSL_RSA_C
263 FCT_TEST_BGN(low_and_high_error)
269 fct_chk( strcmp( buf,
"RSA - Bad input parameters to function : AES - Invalid key length" ) == 0 );
276 FCT_TEST_BGN(non_existing_high_error)
282 fct_chk( strcmp( buf,
"UNKNOWN ERROR CODE (8880)" ) == 0 );
287 FCT_TEST_BGN(non_existing_low_error)
293 fct_chk( strcmp( buf,
"UNKNOWN ERROR CODE (0001)" ) == 0 );
298 FCT_TEST_BGN(non_existing_low_and_high_error)
304 fct_chk( strcmp( buf,
"UNKNOWN ERROR CODE (8880) : UNKNOWN ERROR CODE (0001)" ) == 0 );