summaryrefstree
path: root/kernel/crypto/fips140_test.h
blob: 818812688be480b94258fd8dd7a2525482d1c7d3 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef _CRYPTO_FIPS140_TEST_H
#define _CRYPTO_FIPS140_TEST_H

#include <linux/types.h>

#define FIPS140_MAX_LEN_IV		48
#define FIPS140_MAX_LEN_KEY	132
#define FIPS140_MAX_LEN_DIGEST	64
#define FIPS140_MAX_LEN_PCTEXT	1024
#define FIPS140_MAX_LEN_ENTROPY	48
#define FIPS140_MAX_LEN_STR	128

#define FIPS140_TEST_ENCRYPT 1
#define FIPS140_TEST_DECRYPT 0

#ifdef CONFIG_CRYPTO_FIPS_FUNC_TEST
void set_fips_functest_KAT_mode(const int num);
void set_fips_functest_conditional_mode(const int num);
char *get_fips_functest_mode(void);
#define SKC_FUNCTEST_KAT_CASE_NUM 25
#define SKC_FUNCTEST_CONDITIONAL_CASE_NUM 1
#define SKC_FUNCTEST_NO_TEST "NO_TEST"
#endif // CONFIG_CRYPTO_FIPS_FUNC_TEST

typedef struct {
	const char key[FIPS140_MAX_LEN_KEY];
	const char iv[FIPS140_MAX_LEN_IV];
	const char ptext[FIPS140_MAX_LEN_PCTEXT];
	const char ctext[FIPS140_MAX_LEN_PCTEXT];
	unsigned char klen;
	unsigned char iv_len;
	unsigned short len;
} cipher_testvec_t;

typedef struct {
	const char key[FIPS140_MAX_LEN_KEY];
	const char ptext[FIPS140_MAX_LEN_PCTEXT];
	const char digest[FIPS140_MAX_LEN_DIGEST];
	unsigned short plen;
	unsigned short klen;
} hash_testvec_t;

typedef struct {
	const char key[FIPS140_MAX_LEN_KEY];
	const char iv[FIPS140_MAX_LEN_IV];
	const char input[FIPS140_MAX_LEN_PCTEXT];
	const char assoc[FIPS140_MAX_LEN_PCTEXT];
	const char result[FIPS140_MAX_LEN_PCTEXT];
	unsigned int iv_len;
	unsigned char klen;
	unsigned short ilen;
	unsigned short alen;
	unsigned short rlen;
} aead_testvec_t;

typedef struct {
	const unsigned char entropy[FIPS140_MAX_LEN_ENTROPY];
	size_t entropylen;
	const unsigned char entpra[FIPS140_MAX_LEN_ENTROPY];
	const unsigned char entprb[FIPS140_MAX_LEN_ENTROPY];
	size_t entprlen;
	const unsigned char addtla[FIPS140_MAX_LEN_IV];
	const unsigned char addtlb[FIPS140_MAX_LEN_IV];
	size_t addtllen;
	const unsigned char pers[FIPS140_MAX_LEN_STR];
	size_t perslen;
	const unsigned char expected[FIPS140_MAX_LEN_STR];
	size_t expectedlen;
} drbg_testvec_t;

typedef struct {
	const cipher_testvec_t *vecs;
	unsigned int tv_count;
} cipher_test_suite_t;

typedef struct {
	const hash_testvec_t *vecs;
	unsigned int tv_count;
} hash_test_suite_t;

typedef struct {
	const aead_testvec_t *vecs;
	unsigned int tv_count;
} aead_test_suite_t;

typedef struct {
	const drbg_testvec_t *vecs;
	unsigned int tv_count;
} drbg_test_suite_t;

extern int alg_test_fips140(const char *driver, const char *alg);
int fips140_kat(void);

#endif	/* _CRYPTO_FIPS140_TEST_H */