| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef CRYPTOPERF_H |
| 21 |
#define CRYPTOPERF_H |
| 22 |
|
| 23 |
#define _GNU_SOURCE |
| 24 |
|
| 25 |
#include <stdint.h> |
| 26 |
#include <stdio.h> |
| 27 |
#include <time.h> |
| 28 |
#include <stdlib.h> |
| 29 |
#include <string.h> |
| 30 |
#include <sys/types.h> |
| 31 |
#include <sys/stat.h> |
| 32 |
#include <fcntl.h> |
| 33 |
#include <unistd.h> |
| 34 |
#include <errno.h> |
| 35 |
|
| 36 |
#include "kcapi.h" |
| 37 |
|
| 38 |
#define DRIVER_NAME "cryptoperf" |
| 39 |
|
| 40 |
#if 0 |
| 41 |
#define dbg(fmt, ...) printf(DRIVER_NAME": " fmt, ##__VA_ARGS__) |
| 42 |
#else |
| 43 |
#define dbg(fmt, ...) |
| 44 |
#endif |
| 45 |
|
| 46 |
|
| 47 |
#define DFLT_EXECTIME 10 |
| 48 |
|
| 49 |
#define SUCCESS 1 |
| 50 |
#define FAILURE 0 |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
struct cp_test_param { |
| 61 |
unsigned int exectime; |
| 62 |
size_t len; |
| 63 |
unsigned int aio; |
| 64 |
int accesstype; |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
struct rng_def { |
| 71 |
unsigned int blocksize; |
| 72 |
unsigned char *scratchpad; |
| 73 |
size_t inputlen; |
| 74 |
struct kcapi_handle *handle; |
| 75 |
}; |
| 76 |
|
| 77 |
struct hash_def { |
| 78 |
unsigned int hmac; |
| 79 |
unsigned char *scratchpad; |
| 80 |
size_t inputlen; |
| 81 |
struct kcapi_handle *handle; |
| 82 |
}; |
| 83 |
|
| 84 |
struct skcipher_def { |
| 85 |
unsigned int keysize; |
| 86 |
unsigned char *scratchpad; |
| 87 |
unsigned char *iv; |
| 88 |
size_t inputlen; |
| 89 |
struct iovec *iovec; |
| 90 |
struct kcapi_handle *handle; |
| 91 |
}; |
| 92 |
|
| 93 |
struct aead_def { |
| 94 |
unsigned int keysize; |
| 95 |
unsigned char *input; |
| 96 |
unsigned char *output; |
| 97 |
unsigned char *iv; |
| 98 |
size_t indatalen; |
| 99 |
size_t outdatalen; |
| 100 |
size_t assoclen; |
| 101 |
struct iovec *iniov; |
| 102 |
struct iovec *outiov; |
| 103 |
struct kcapi_handle *handle; |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
struct cp_res { |
| 110 |
uint64_t rounds; |
| 111 |
uint64_t processed_bytes; |
| 112 |
uint64_t totaltime; |
| 113 |
size_t byteperop; |
| 114 |
size_t chunksize; |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
struct cp_test; |
| 121 |
struct cp_test { |
| 122 |
char *testname; |
| 123 |
char *driver_name; |
| 124 |
char *type; |
| 125 |
int enc; |
| 126 |
unsigned int exectime; |
| 127 |
struct cp_res results; |
| 128 |
struct cp_test_param *test_params; |
| 129 |
int (*init_test)(struct cp_test *test); |
| 130 |
size_t (*exec_test)(struct cp_test *test); |
| 131 |
void (*fini_test)(struct cp_test *test); |
| 132 |
|
| 133 |
|
| 134 |
union { |
| 135 |
struct rng_def rng; |
| 136 |
struct skcipher_def skcipher; |
| 137 |
struct aead_def aead; |
| 138 |
struct hash_def hash; |
| 139 |
} u; |
| 140 |
}; |
| 141 |
|
| 142 |
static inline uint64_t cp_ts2u64(struct timespec *ts) |
| 143 |
{ |
| 144 |
uint64_t upper = (uint64_t)ts->tv_sec; |
| 145 |
|
| 146 |
upper = upper << 32; |
| 147 |
return (upper | (uint64_t)ts->tv_nsec); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
static inline void cp_cpusetup(void) |
| 154 |
{ |
| 155 |
#ifdef __X8664___ |
| 156 |
asm volatile("cpuid"::"a" (0), "c" (0): "memory"); |
| 157 |
asm volatile("cpuid"::"a" (0), "c" (0): "memory"); |
| 158 |
asm volatile("cpuid"::"a" (0), "c" (0): "memory"); |
| 159 |
#endif |
| 160 |
} |
| 161 |
|
| 162 |
static inline void cp_get_nstime(struct timespec *ts) |
| 163 |
{ |
| 164 |
clock_gettime(CLOCK_REALTIME, ts); |
| 165 |
} |
| 166 |
|
| 167 |
static inline void cp_start_time(struct timespec *ts) |
| 168 |
{ |
| 169 |
cp_cpusetup(); |
| 170 |
cp_get_nstime(ts); |
| 171 |
} |
| 172 |
|
| 173 |
static inline void cp_end_time(struct timespec *ts) |
| 174 |
{ |
| 175 |
cp_get_nstime(ts); |
| 176 |
} |
| 177 |
|
| 178 |
static inline void *cp_zalloc(size_t len) |
| 179 |
{ |
| 180 |
return calloc(1, len); |
| 181 |
} |
| 182 |
static inline void cp_zfree(void *ptr, unsigned int len) |
| 183 |
{ |
| 184 |
memset(ptr, 0, len); |
| 185 |
free(ptr); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
char *cp_print_status(struct cp_test *test, int raw); |
| 192 |
int cp_exec_test(struct cp_test *test); |
| 193 |
int cp_read_random(unsigned char *buf, size_t buflen); |
| 194 |
|
| 195 |
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 196 |
|
| 197 |
|
| 198 |
void cp_hash_register(struct cp_test **hash_test, size_t *entries); |
| 199 |
void cp_rng_register(struct cp_test **rng_test, size_t *entries); |
| 200 |
void cp_skcipher_register(struct cp_test **skcipher_test, size_t *entries); |
| 201 |
void cp_aead_register(struct cp_test **aead_test, size_t *entries); |
| 202 |
#endif |