comparison libtomcrypt/tests/common.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9
10 #include "common.h"
11
12 /**
13 @file common.c
14
15 Steffen Jaeckel
16 */
17
18 void run_cmd(int res, int line, const char *file, const char *cmd, const char *algorithm)
19 {
20 if (res != CRYPT_OK) {
21 fprintf(stderr, "%s (%d)%s%s\n%s:%d:%s\n",
22 error_to_string(res), res,
23 (algorithm ? " - " : ""), (algorithm ? algorithm : ""),
24 file, line, cmd);
25 if (res != CRYPT_NOP) {
26 exit(EXIT_FAILURE);
27 }
28 }
29 }
30
31 void print_hex(const char* what, const void* v, const unsigned long l)
32 {
33 const unsigned char* p = v;
34 unsigned long x, y = 0, z;
35 fprintf(stderr, "%s contents: \n", what);
36 for (x = 0; x < l; ) {
37 fprintf(stderr, "%02X ", p[x]);
38 if (!(++x % 16) || x == l) {
39 if((x % 16) != 0) {
40 z = 16 - (x % 16);
41 if(z >= 8)
42 fprintf(stderr, " ");
43 for (; z != 0; --z) {
44 fprintf(stderr, " ");
45 }
46 }
47 fprintf(stderr, " | ");
48 for(; y < x; y++) {
49 if((y % 8) == 0)
50 fprintf(stderr, " ");
51 if(isgraph(p[y]))
52 fprintf(stderr, "%c", p[y]);
53 else
54 fprintf(stderr, ".");
55 }
56 fprintf(stderr, "\n");
57 }
58 else if((x % 8) == 0) {
59 fprintf(stderr, " ");
60 }
61 }
62 }
63
64 prng_state yarrow_prng;
65
66 /* ref: $Format:%D$ */
67 /* git commit: $Format:%H$ */
68 /* commit time: $Format:%ai$ */