PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "aes.h"
2 #include <string.h>
3 
4 int INPUT_SIZE = sizeof(struct bench_args_t);
5 
6 void run_benchmark( void *vargs ) {
7  struct bench_args_t *args = (struct bench_args_t *)vargs;
8  aes256_encrypt_ecb( &(args->ctx), args->k, args->buf );
9 }
10 
11 /* Input format:
12 %%: Section 1
13 uint8_t[32]: key
14 %%: Section 2
15 uint8_t[16]: input-text
16 */
17 
18 void input_to_data(int fd, void *vdata) {
19  struct bench_args_t *data = (struct bench_args_t *)vdata;
20  char *p, *s;
21  // Zero-out everything.
22  memset(vdata,0,sizeof(struct bench_args_t));
23  // Load input string
24  p = readfile(fd);
25  // Section 1: key
26  s = find_section_start(p,1);
27  parse_uint8_t_array(s, data->k, 32);
28  // Section 2: input-text
29  s = find_section_start(p,2);
30  parse_uint8_t_array(s, data->buf, 16);
31  free(p);
32 }
33 
34 void data_to_input(int fd, void *vdata) {
35  struct bench_args_t *data = (struct bench_args_t *)vdata;
36  // Section 1
38  write_uint8_t_array(fd, data->k, 32);
39  // Section 2
41  write_uint8_t_array(fd, data->buf, 16);
42 }
43 
44 /* Output format:
45 %% Section 1
46 uint8_t[16]: output-text
47 */
48 
49 void output_to_data(int fd, void *vdata) {
50  struct bench_args_t *data = (struct bench_args_t *)vdata;
51 
52  char *p, *s;
53  // Zero-out everything.
54  memset(vdata,0,sizeof(struct bench_args_t));
55  // Load input string
56  p = readfile(fd);
57  // Section 1: output-text
58  s = find_section_start(p,1);
59  parse_uint8_t_array(s, data->buf, 16);
60  free(p);
61 }
62 
63 void data_to_output(int fd, void *vdata) {
64  struct bench_args_t *data = (struct bench_args_t *)vdata;
65  // Section 1
67  write_uint8_t_array(fd, data->buf, 16);
68 }
69 
70 int check_data( void *vdata, void *vref ) {
71  struct bench_args_t *data = (struct bench_args_t *)vdata;
72  struct bench_args_t *ref = (struct bench_args_t *)vref;
73  int has_errors = 0;
74 
75  // Exact compare encrypted output buffers
76  has_errors |= memcmp(&data->buf, &ref->buf, 16*sizeof(uint8_t));
77 
78  // Return true if it's correct.
79  return !has_errors;
80 }
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
int INPUT_SIZE
Definition: local_support.c:4
void aes256_encrypt_ecb(aes256_context *ctx, uint8_t k[32], uint8_t buf[16])
Definition: aes.c:176
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
int write_section_header(int fd)
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
uint8_t buf[16]
Definition: aes.h:21
char * readfile(int fd)
Definition: support.c:34
void input_to_data(int fd, void *vdata)
Definition: local_support.c:18
char * find_section_start(char *s, int n)
Definition: support.c:56
aes256_context ctx
Definition: aes.h:19
int write_uint8_t_array(int fd, uint8_t *arr, int n)
uint8_t k[32]
Definition: aes.h:20
int parse_uint8_t_array(char *s, uint8_t *arr, int n)
void run_benchmark(void *vargs)
Definition: local_support.c:6

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13