A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 87 lines 2.5 kB view raw
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 "tomcrypt.h" 11 12/** 13 @file compare_testvector.c 14 Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel 15*/ 16 17#if defined(LTC_TEST) && defined(LTC_TEST_DBG) 18static void _print_hex(const char* what, const void* v, const unsigned long l) 19{ 20 const unsigned char* p = v; 21 unsigned long x, y = 0, z; 22 fprintf(stderr, "%s contents: \n", what); 23 for (x = 0; x < l; ) { 24 fprintf(stderr, "%02X ", p[x]); 25 if (!(++x % 16) || x == l) { 26 if((x % 16) != 0) { 27 z = 16 - (x % 16); 28 if(z >= 8) 29 fprintf(stderr, " "); 30 for (; z != 0; --z) { 31 fprintf(stderr, " "); 32 } 33 } 34 fprintf(stderr, " | "); 35 for(; y < x; y++) { 36 if((y % 8) == 0) 37 fprintf(stderr, " "); 38 if(isgraph(p[y])) 39 fprintf(stderr, "%c", p[y]); 40 else 41 fprintf(stderr, "."); 42 } 43 fprintf(stderr, "\n"); 44 } 45 else if((x % 8) == 0) { 46 fprintf(stderr, " "); 47 } 48 } 49} 50#endif 51 52/** 53 Compare two test-vectors 54 55 @param is The data as it is 56 @param is_len The length of is 57 @param should The data as it should 58 @param should_len The length of should 59 @param what The type of the data 60 @param which The iteration count 61 @return 0 on equality, -1 or 1 on difference 62*/ 63int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which) 64{ 65 int res = 0; 66 if(is_len != should_len) 67 res = is_len > should_len ? -1 : 1; 68 else 69 res = XMEMCMP(is, should, is_len); 70 71#if defined(LTC_TEST) && defined(LTC_TEST_DBG) 72 if (res != 0) { 73 fprintf(stderr, "Testvector #%i of %s failed:\n", which, what); 74 _print_hex("SHOULD", should, should_len); 75 _print_hex("IS ", is, is_len); 76 } 77#else 78 LTC_UNUSED_PARAM(which); 79 LTC_UNUSED_PARAM(what); 80#endif 81 82 return res; 83} 84 85/* ref: HEAD -> master, tag: v1.18.2 */ 86/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */ 87/* commit time: 2018-07-01 22:49:01 +0200 */