n_random regression: secure random bytes and hex token generation.
n_random regression: secure random bytes and hex token generation.
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int opt = 0;
while ((opt = getopt(argc, argv, "hvV:")) != EOF) {
switch (opt) {
case 'V':
if (!strncmp("LOG_NULL", optarg, 8))
else if (!strncmp("LOG_NOTICE", optarg, 10))
else if (!strncmp("LOG_INFO", optarg, 8))
else if (!strncmp("LOG_ERR", optarg, 7))
else if (!strncmp("LOG_DEBUG", optarg, 9))
else {
fprintf(stderr, "Unknown log level %s\n", optarg);
exit(1);
}
break;
case 'v':
fprintf(stderr, "ex_random\n");
exit(1);
case 'h':
default:
fprintf(stderr, "usage: %s [-V LOG_LEVEL]\n", argv[0]);
break;
}
}
}
unsigned char a[32];
unsigned char b[32];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
return;
}
if (memcmp(a, b, sizeof(a)) == 0) {
}
int all_zero = 1;
for (size_t i = 0; i < sizeof(a); i++) {
if (a[i] != 0) {
all_zero = 0;
break;
}
}
if (all_zero) {
}
}
}
}
if (!t1 || !t2) {
} else {
}
for (
size_t i = 0; i < t1->
written; i++) {
if (!isxdigit((
unsigned char)t1->
data[i]) || (t1->
data[i] >=
'A' && t1->
data[i] <=
'F')) {
n_log(
LOG_ERR,
"token has a non-lowercase-hex character at %zu", i);
break;
}
}
}
}
}
}
int main(
int argc,
char** argv) {
return 1;
}
return 0;
}
void process_args(int argc, char **argv)
static void test_bytes(void)
static void test_token(void)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
int n_random_bytes(unsigned char *buf, size_t n)
fill buf with n cryptographically secure random bytes (getrandom(2) when available,...
N_STR * n_random_hex_token(size_t nbytes)
generate nbytes secure random bytes and return them as a lowercase hex N_STR (2*nbytes characters); f...
size_t written
number of meaningful bytes in data, excluding the null terminator; the size including the null termin...
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
A box including a string and his lenght.
Common headers and low-level functions & define.
Cryptographically secure random bytes and hex tokens (POSIX)
N_STR and string function declaration.