From b3dcbc18f6fcfbee33b019958aef5f2f31a07e74 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Sun, 13 Mar 2011 16:57:25 +0000 Subject: [PATCH] - Made function resilient to endianness differences. --- tests/suites/helpers.function | 37 +++++++++++++++++++++++++++++--- tests/suites/test_suite_rsa.data | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index d8dbb13ea..32500b904 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -1,3 +1,33 @@ +#ifdef _MSC_VER +#include +typedef UINT32 uint32_t; +#else +#include +#endif + +/* + * 32-bit integer manipulation macros (big endian) + */ +#ifndef GET_ULONG_BE +#define GET_ULONG_BE(n,b,i) \ +{ \ + (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ + | ( (unsigned long) (b)[(i) + 1] << 16 ) \ + | ( (unsigned long) (b)[(i) + 2] << 8 ) \ + | ( (unsigned long) (b)[(i) + 3] ); \ +} +#endif + +#ifndef PUT_ULONG_BE +#define PUT_ULONG_BE(n,b,i) \ +{ \ + (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ + (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ + (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ + (b)[(i) + 3] = (unsigned char) ( (n) ); \ +} +#endif + int unhexify(unsigned char *obuf, const char *ibuf) { unsigned char c, c2; @@ -138,11 +168,12 @@ static int rnd_buffer_rand( void *rng_state ) * Info structure for the pseudo random function * * Key should be set at the start to a test-unique value. + * Do not forget endianness! * State( v0, v1 ) should be set to zero. */ typedef struct { - unsigned char key[16]; + uint32_t key[16]; uint32_t v0, v1; } rnd_pseudo_info; @@ -157,12 +188,12 @@ typedef struct static int rnd_pseudo_rand( void *rng_state ) { rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state; - uint32_t i, *k, sum, delta=0x9E3779B9; + uint32_t i, *k, sum = 0, delta=0x9E3779B9; if( rng_state == NULL ) return( rand() ); - k = (uint32_t *) info->key; + k = info->key; for( i = 0; i < 32; i++ ) { info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]); diff --git a/tests/suites/test_suite_rsa.data b/tests/suites/test_suite_rsa.data index b19ba647f..dd3573cec 100644 --- a/tests/suites/test_suite_rsa.data +++ b/tests/suites/test_suite_rsa.data @@ -173,7 +173,7 @@ RSA PKCS1 Sign #8 Verify (Invalid padding type) rsa_pkcs1_verify:"59779fd2a39e56640c4fc1e67b60aeffcecd78aed7ad2bdfa464e93d04198d48466b8da7445f25bfa19db2844edd5c8f539cf772cc132b483169d390db28a43bc4ee0f038f6568ffc87447746cb72fefac2d6d90ee3143a915ac4688028805905a68eb8f8a96674b093c495eddd8704461eaa2b345efbb2ad6930acd8023f870":1:SIG_RSA_MD5:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"3bcf673c3b27f6e2ece4bb97c7a37161e6c6ee7419ef366efc3cfee0f15f415ff6d9d4390937386c6fec1771acba73f24ec6b0469ea8b88083f0b4e1b6069d7bf286e67cf94182a548663137e82a6e09c35de2c27779da0503f1f5bedfebadf2a875f17763a0564df4a6d945a5a3e46bc90fb692af3a55106aafc6b577587456ff8d49cfd5c299d7a2b776dbe4c1ae777b0f64aa3bab27689af32d6cc76157c7dc6900a3469e18a7d9b6bfe4951d1105a08864575e4f4ec05b3e053f9b7a2d5653ae085e50a63380d6bdd6f58ab378d7e0a2be708c559849891317089ab04c82d8bc589ea088b90b11dea5cf85856ff7e609cc1adb1d403beead4c126ff29021":POLARSSL_ERR_RSA_INVALID_PADDING RSA PKCS1 Encrypt #1 -rsa_pkcs1_encrypt:"4E636AF98E40F3ADCFCCB698F4E80B9F":RSA_PKCS_V15:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"0543bd6d7e88daab6830f39648faeca5c00b423a36456946c2775d3ed676fcb57c83b1b1ad3c47823441b3bae059c2f63817ce8f75d93c9eeb8ddc8a0d3ae5572e8c6010f0959f2222306b18e263326e6d5aa38bd7d2763173f13aab5245d2dd937473e8c2f5b68442f1341e09139f55a1df4a3b89e34752983c0448a2262321d7f9f8e460ce1db3609731e2c5b1d1520daba5cc8547d42d1646e6df068e649fadad1434fcd75abb47d640e050a43cb1e37dc7e873b6a71adafe4c2d80e8d2a9dbba424ace993467d5eff62e59ce5224c857e3c700e3f52323fed206fb6a32556fc5731424f8819d23d3a7928298027681b469eb9e04bf117b9d9fb69056dd65":0 +rsa_pkcs1_encrypt:"4E636AF98E40F3ADCFCCB698F4E80B9F":RSA_PKCS_V15:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"54dbfe9e723ea7d094d5f10c885e2376d282492ebf75398fb0af70a361a6884d2e681be70f580ae22a08a53bf3b1520de38bdf2adb9cd8cf051bd33302cd1d8bc3acaf9f07f8b770aa64f739e35aacffc23ef8c5d378515f01992f7516f7c39004a35fd59b21db6ea9a06dd8a94657b50da94f2e2f0c8e775cf7f86f476c52611dca7cdefbbeadbf04e6915767df8f97070738e6c35223fb0ba9c9e7f51a492b97813ff10efe91613a0730d47afdae77edf9476a7f9b89e42225e74143a6b9f8a975cdd47066b2429a6ecb64ecce23970d72c59fa00e0a5096cb44d468090ea625c00f45454abb75fff7e652b4df86f4d0373436eb5383ba3bd510ed53c4609e":0 RSA PKCS1 Decrypt #1 (Verify) rsa_pkcs1_decrypt:"a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6":RSA_PKCS_V15:2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":1000:"4E636AF98E40F3ADCFCCB698F4E80B9F":0