File: cavp_entry.c

package info (click to toggle)
libreswan 5.2-2.4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 81,656 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (89 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Parse CAVP test vectors, for libreswan (CAVP)
 *
 * Copyright (C) 2015-2018, Andrew Cagney
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <https://www.gnu.org/licenses/gpl2.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include "test_buffer.h"
#include "crypt_symkey.h"
#include "cavp_entry.h"

void op_entry(const struct cavp_entry *entry,
	      const char *value_unused UNUSED,
	      struct logger *logger_unused UNUSED)
{
	*(entry->entry) = entry;
}

void op_chunk(const struct cavp_entry *entry,
	      const char *value,
	      struct logger *logger_unused UNUSED)
{
	if (entry->chunk == NULL) {
		fprintf(stderr, "missing chunk for '%s'\n", entry->key);
		exit(1);
	}
	free_chunk_content(entry->chunk);
	*entry->chunk = chunk_from_hex(value, entry->key);
}

void op_symkey(const struct cavp_entry *entry,
	       const char *value,
	       struct logger *logger)
{
	symkey_delref(logger, "entry", entry->symkey);
	chunk_t chunk = chunk_from_hex(value, entry->key);
	*(entry->symkey) = symkey_from_hunk("symkey", chunk, logger);
	free_chunk_content(&chunk);
}

void op_signed_long(const struct cavp_entry *entry,
		    const char *value,
		    struct logger *logger_unused UNUSED)
{
	*(entry->signed_long) = strtol(value, NULL, 10);
}

void op_unsigned_long(const struct cavp_entry *entry,
		      const char *value,
		      struct logger *logger_unused UNUSED)
{
	*(entry->unsigned_long) = strtoul(value, NULL, 10);
}

void op_ignore(const struct cavp_entry *entry UNUSED,
	       const char *value_unused UNUSED,
	       struct logger *logger_unused UNUSED)
{
}

const struct cavp_entry *cavp_entry_by_key(const struct cavp_entry *entries,
						  const char *key)
{
	const struct cavp_entry *entry;
	for (entry = entries; entry->key != NULL; entry++) {
		if (strcmp(entry->key, key) == 0) {
			return entry;
		}
	}
	return NULL;
}

const struct cavp_entry *cavp_entry_by_opt(const struct cavp_entry *entries, const char *opt)
{
	for (const struct cavp_entry *entry = entries; entry->key != NULL; entry++) {
		if (entry->opt != NULL && strcasecmp(entry->opt, opt) == 0) {
			return entry;
		}
	}
	return NULL;
}