tests: add function print_hex()

This commit is contained in:
Steffen Jaeckel 2014-08-28 13:18:30 +02:00
parent 64f887e8f3
commit efc6844f9c
3 changed files with 20 additions and 19 deletions

View File

@ -100,19 +100,6 @@ static int rsa_compat_test(void)
return 0; return 0;
} }
static void _rsa_testPrint(const char* what, const unsigned char* p, const unsigned long l)
{
unsigned long x;
fprintf(stderr, "%s contents: \n", what);
for (x = 0; x < l; ) {
fprintf(stderr, "%02x ", p[x]);
if (!(++x % 16)) {
fprintf(stderr, "\n");
}
}
fprintf(stderr, "\n");
}
int rsa_test(void) int rsa_test(void)
{ {
unsigned char in[1024], out[1024], tmp[1024]; unsigned char in[1024], out[1024], tmp[1024];
@ -200,8 +187,8 @@ for (cnt = 0; cnt < len; ) {
} }
if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) { if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
fprintf(stderr, "\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2); fprintf(stderr, "\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
_rsa_testPrint("Original", in, rsa_msgsize); print_hex("Original", in, rsa_msgsize);
_rsa_testPrint("Output", tmp, len2); print_hex("Output", tmp, len2);
return 1; return 1;
} }
} }
@ -230,8 +217,8 @@ for (cnt = 0; cnt < len; ) {
} }
if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) { if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2); fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2);
_rsa_testPrint("Original", in, rsa_msgsize); print_hex("Original", in, rsa_msgsize);
_rsa_testPrint("Output", tmp, len2); print_hex("Output", tmp, len2);
return 1; return 1;
} }
} }
@ -256,8 +243,8 @@ for (cnt = 0; cnt < len; ) {
} }
if (memcmp(tmp, in, rsa_msgsize)) { if (memcmp(tmp, in, rsa_msgsize)) {
fprintf(stderr, "rsa_decrypt_key_ex mismatch data"); fprintf(stderr, "rsa_decrypt_key_ex mismatch data");
_rsa_testPrint("Original", in, rsa_msgsize); print_hex("Original", in, rsa_msgsize);
_rsa_testPrint("Output", tmp, rsa_msgsize); print_hex("Output", tmp, rsa_msgsize);
return 1; return 1;
} }
} }

View File

@ -80,6 +80,7 @@ extern int no_results;
extern const struct ltc_prng_descriptor no_prng_desc; extern const struct ltc_prng_descriptor no_prng_desc;
#endif #endif
void print_hex(const char* what, const unsigned char* p, const unsigned long l);
int sorter(const void *a, const void *b); int sorter(const void *a, const void *b);
void tally_results(int type); void tally_results(int type);
ulong64 rdtsc (void); ulong64 rdtsc (void);

View File

@ -2,6 +2,19 @@
prng_state yarrow_prng; prng_state yarrow_prng;
void print_hex(const char* what, const unsigned char* p, const unsigned long l)
{
unsigned long x;
fprintf(stderr, "%s contents: \n", what);
for (x = 0; x < l; ) {
fprintf(stderr, "%02x ", p[x]);
if (!(++x % 16)) {
fprintf(stderr, "\n");
}
}
fprintf(stderr, "\n");
}
struct list results[100]; struct list results[100];
int no_results; int no_results;
int sorter(const void *a, const void *b) int sorter(const void *a, const void *b)