Updated libtest161
This commit is contained in:
		| @@ -9,6 +9,9 @@ | |||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <errno.h> | #include <errno.h> | ||||||
|  | #include <unistd.h> | ||||||
|  | #include <time.h> | ||||||
|  | #include <stdio.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #include <kern/secure.h> | #include <kern/secure.h> | ||||||
| @@ -35,6 +38,10 @@ static const unsigned char opad[SHA256_BLOCK_SIZE] = { [0 ... SHA256_BLOCK_SIZE- | |||||||
| static char temp_buffers[NUM_BUFFERS][BUFFER_LEN]; | static char temp_buffers[NUM_BUFFERS][BUFFER_LEN]; | ||||||
| static int buf_num = 0; | static int buf_num = 0; | ||||||
|  |  | ||||||
|  | #ifndef _KERNEL | ||||||
|  | static int did_random = 0; | ||||||
|  | #endif | ||||||
|  |  | ||||||
| static void * _alloc(size_t size) | static void * _alloc(size_t size) | ||||||
| { | { | ||||||
| #ifdef _KERNEL | #ifdef _KERNEL | ||||||
| @@ -133,6 +140,15 @@ static void array_to_hex(unsigned char *a, size_t len, char *res) | |||||||
|  |  | ||||||
| static void make_salt(char *salt_str) | static void make_salt(char *salt_str) | ||||||
| { | { | ||||||
|  | #ifndef _KERNEL | ||||||
|  | 	if (!did_random) { | ||||||
|  | 		did_random = 1; | ||||||
|  | 		time_t t; | ||||||
|  | 		time(&t); | ||||||
|  | 		srandom(t); | ||||||
|  | 	} | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	// Compute salt value | 	// Compute salt value | ||||||
| 	uint32_t salt[SALT_BYTES/sizeof(uint32_t)]; | 	uint32_t salt[SALT_BYTES/sizeof(uint32_t)]; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -58,6 +58,13 @@ success(int status, const char * secret, const char * name) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int | ||||||
|  | partial_credit(const char *secret, const char *name, int scored, int total) | ||||||
|  | { | ||||||
|  |         char buffer[128]; | ||||||
|  |         snprintf(buffer, 128, "PARTIAL CREDIT %d OF %d", scored, total); | ||||||
|  |         return secprintf(secret, buffer, name); | ||||||
|  | } | ||||||
| #ifndef _KERNEL | #ifndef _KERNEL | ||||||
|  |  | ||||||
| // Borrowed from parallelvm.  We need atomic console writes so our | // Borrowed from parallelvm.  We need atomic console writes so our | ||||||
|   | |||||||
| @@ -37,5 +37,6 @@ | |||||||
|  |  | ||||||
| int success(int, const char *, const char *); | int success(int, const char *, const char *); | ||||||
| int secprintf(const char *secret, const char *msg, const char *name); | int secprintf(const char *secret, const char *msg, const char *name); | ||||||
|  | int partial_credit(const char *secret, const char *name, int scored, int total); | ||||||
|  |  | ||||||
| #endif /* _KERN_TEST161_H_ */ | #endif /* _KERN_TEST161_H_ */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user