and userspace. In userspace, this is accessed through #include <secure.h> In the kernel, this is access through #include <kern/secure.h> There is a unit test for this (hm1) that computes the hmac and compares it to the known value. The salted vesion tested offline. ----- Also, fixed usespace compile issue with not changing KERNEL_SECRET => SECRET.
64 lines
910 B
C
64 lines
910 B
C
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <kern/secret.h>
|
|
|
|
#ifdef HOST
|
|
#include "hostcompat.h"
|
|
#endif
|
|
|
|
/* printf variant that is quiet during automated testing */
|
|
int
|
|
tprintf(const char *fmt, ...)
|
|
{
|
|
int chars;
|
|
va_list ap;
|
|
|
|
if (SECRET != 0) {
|
|
return 0;
|
|
}
|
|
|
|
va_start(ap, fmt);
|
|
chars = vprintf(fmt, ap);
|
|
va_end(ap);
|
|
|
|
return chars;
|
|
}
|
|
|
|
/* printf variant that is loud during automated testing */
|
|
int
|
|
nprintf(const char *fmt, ...)
|
|
{
|
|
int chars;
|
|
va_list ap;
|
|
|
|
if (SECRET == 0) {
|
|
return 0;
|
|
}
|
|
|
|
va_start(ap, fmt);
|
|
chars = vprintf(fmt, ap);
|
|
va_end(ap);
|
|
|
|
return chars;
|
|
}
|
|
|
|
/* printf variant that prepends the kernel secret */
|
|
int
|
|
printsf(const char *fmt, ...)
|
|
{
|
|
int chars;
|
|
va_list ap;
|
|
|
|
if (SECRET != 0) {
|
|
printf("%llu: ", (unsigned long long)SECRET);
|
|
}
|
|
va_start(ap, fmt);
|
|
chars = vprintf(fmt, ap);
|
|
va_end(ap);
|
|
|
|
return chars;
|
|
}
|