aboutsummaryrefslogtreecommitdiff
path: root/test/validation/api/crypto/test_vectors.h
blob: 33ba52d3421ef68546bbd6a0d4b9a7e613a5d147 (plain)
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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2014-2018 Linaro Limited
 * Copyright (c) 2021-2023 Nokia
 */

#ifndef TEST_VECTORS_H
#define TEST_VECTORS_H

#include <odp_api.h>
#include "test_vectors_len.h"

typedef struct crypto_test_reference_s {
	uint8_t copy_previous_vector;  /* does not copy digest_length */
	odp_cipher_alg_t cipher;
	odp_auth_alg_t auth;
	uint32_t cipher_key_length;
	uint8_t cipher_key[MAX_KEY_LEN];
	uint32_t auth_key_length;
	uint8_t auth_key[MAX_KEY_LEN];
	uint32_t cipher_iv_length;
	uint8_t cipher_iv[MAX_IV_LEN];
	uint32_t auth_iv_length;
	uint8_t auth_iv[MAX_IV_LEN];
	uint32_t length;
	odp_bool_t is_length_in_bits;
	uint8_t plaintext[MAX_DATA_LEN];
	uint8_t ciphertext[MAX_DATA_LEN];
	uint32_t aad_length;
	uint8_t aad[MAX_AAD_LEN];
	uint32_t digest_length;
	uint8_t digest[MAX_DIGEST_LEN];
} crypto_test_reference_t;

ODP_STATIC_ASSERT(ODP_CIPHER_ALG_NULL == 0, "null cipher is not the default");
ODP_STATIC_ASSERT(ODP_AUTH_ALG_NULL == 0, "null auth is not the default");

/*
 * Return test data length in bytes, rounding up to full bytes.
 */
static inline uint32_t ref_length_in_bytes(const crypto_test_reference_t *ref)
{
	return ref->is_length_in_bits ? (ref->length + 7) / 8 : ref->length;
}

/*
 * Return test data length in bits
 */
static inline uint32_t ref_length_in_bits(const crypto_test_reference_t *ref)
{
	return ref->is_length_in_bits ? ref->length : 8 * ref->length;
}

static inline void init_reference(crypto_test_reference_t *ref, int size)
{
	int n;
	crypto_test_reference_t *prev = NULL;

	for (n = 0; n < size; n++) {
		if (prev && ref[n].copy_previous_vector) {
			uint32_t len;

			len = ref[n].digest_length;
			ref[n] = *prev;
			ref[n].digest_length = len;
		}
		prev = &ref[n];
	}
}

#endif