1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
14 */
15
16 #ifndef _CRYPTOTEST_H
17 #define _CRYPTOTEST_H
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #include <sys/crypto/ioctl.h>
24
25 #define CTEST_INIT_FAILED (-1)
26 #define CTEST_NAME_RESOLVE_FAILED (-2)
27 #define CTEST_MECH_NO_PROVIDER (-3)
28
29 typedef struct cryptotest {
30 uint8_t *in;
31 uint8_t *out;
32 uint8_t *key;
33 void *param;
34
35 size_t inlen;
36 size_t outlen;
37 size_t keylen;
38 size_t plen;
39
40 char *mechname;
41 size_t updatelen;
42 } cryptotest_t;
43
44 typedef int (*testfunc_t)(cryptotest_t *);
45
46 typedef struct test_fg {
47 testfunc_t single;
48 testfunc_t update;
49 } test_fg_t;
50
51 #define CRYPTO_INVALID_SESSION ((size_t)-1)
52 typedef struct crypto_op crypto_op_t;
53
54 int run_test(cryptotest_t *args, uint8_t *cmp, size_t cmplen, test_fg_t *funcs);
55
56 /* utils */
57 crypto_op_t *cryptotest_init(cryptotest_t *args, crypto_func_group_t fg);
58 int cryptotest_close(crypto_op_t *op);
59 int get_mech_info(crypto_op_t *op);
60 int get_hsession_by_mech(crypto_op_t *op);
61
62 /* CRYPTO_MAC */
63 int mac_init(crypto_op_t *op);
64 int mac_single(crypto_op_t *op);
65 int mac_update(crypto_op_t *op, int offset);
66 int mac_final(crypto_op_t *op);
67
68 /* CRYPTO_ENCRYPT */
69 int encrypt_init(crypto_op_t *op);
70 int encrypt_single(crypto_op_t *op);
71 int encrypt_update(crypto_op_t *op, int offset, size_t *encrlen);
72 int encrypt_final(crypto_op_t *op, size_t encrlen);
73
74 /* CRYPTO_DECRYPT */
75 int decrypt_init(crypto_op_t *op);
76 int decrypt_single(crypto_op_t *op);
77 int decrypt_update(crypto_op_t *op, int offset, size_t *encrlen);
78 int decrypt_final(crypto_op_t *op, size_t encrlen);
79
80 /* wrappers */
81 int test_mac_single(cryptotest_t *args);
82 int test_mac(cryptotest_t *args);
83
84 int test_encrypt_single(cryptotest_t *args);
85 int test_encrypt(cryptotest_t *args);
86
87 int test_decrypt_single(cryptotest_t *args);
88 int test_decrypt(cryptotest_t *args);
89
90 extern test_fg_t cryptotest_decr_fg;
91 extern test_fg_t cryptotest_encr_fg;
92 extern test_fg_t cryptotest_mac_fg;
93
94 #define MAC_FG (&cryptotest_mac_fg)
95 #define ENCR_FG (&cryptotest_encr_fg)
96 #define DECR_FG (&cryptotest_decr_fg)
97
98 #ifdef __cplusplus
99 }
100 #endif
101
102 #endif /* _CRYPTOTEST_H */