1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Amaury Pouly
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
28 #define STR(a) _STR(a)
31 #define MIN(a,b) ((a) < (b) ? (a) : (b))
34 #define bug(...) do { fprintf(stderr,"["__FILE__":"STR(__LINE__)"]ERROR: "__VA_ARGS__); exit(1); } while(0)
35 #define bugp(...) do { fprintf(stderr, __VA_ARGS__); perror(" "); exit(1); } while(0)
37 #define ROUND_UP(val, round) ((((val) + (round) - 1) / (round)) * (round))
42 typedef struct crypto_key_t
*key_array_t
;
44 key_array_t g_key_array
;
46 void *memdup(const void *p
, size_t len
);
47 void *augment_array(void *arr
, size_t elem_sz
, size_t cnt
, void *aug
, size_t aug_cnt
);
48 void augment_array_ex(void **arr
, size_t elem_sz
, int *cnt
, int *capacity
,
49 void *aug
, int aug_cnt
);
50 void generate_random_data(void *buf
, size_t sz
);
51 void *xmalloc(size_t s
);
52 int convxdigit(char digit
, byte
*val
);
53 void print_hex(byte
*data
, int len
, bool newline
);
54 void add_keys(key_array_t ka
, int kac
);
55 bool parse_key(char **str
, struct crypto_key_t
*key
);
56 bool add_keys_from_file(const char *key_file
);
57 void print_key(struct crypto_key_t
*key
, bool newline
);
60 typedef char color_t
[];
62 extern color_t OFF
, GREY
, RED
, GREEN
, YELLOW
, BLUE
;
63 void color(color_t c
);
64 void enable_color(bool enable
);
66 #endif /* __MISC_H__ */