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 * Copyright 2018, Joyent, Inc. 15 */ 16 17 #ifndef _CRYPTOTEST_H 18 #define _CRYPTOTEST_H 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #include <sys/crypto/ioctl.h> 25 26 #define CTEST_INIT_FAILED (-1) 27 #define CTEST_NAME_RESOLVE_FAILED (-2) 28 #define CTEST_MECH_NO_PROVIDER (-3) 29 30 typedef struct cryptotest { 31 uint8_t *in; 32 uint8_t *out; 33 uint8_t *key; 34 void *param; 35 36 size_t inlen; 37 size_t outlen; 38 size_t keylen; 39 size_t plen; 40 41 char *mechname; 42 size_t updatelen; 43 } cryptotest_t; 44 45 typedef int (*testfunc_t)(cryptotest_t *); 46 47 typedef struct test_fg { 48 testfunc_t single; 49 testfunc_t update; 50 } test_fg_t; 51 52 #define CRYPTO_INVALID_SESSION ((size_t)-1) 53 typedef struct crypto_op crypto_op_t; 54 55 int run_test(cryptotest_t *args, uint8_t *cmp, size_t cmplen, test_fg_t *funcs); 56 57 /* utils */ 58 crypto_op_t *cryptotest_init(cryptotest_t *args, crypto_func_group_t fg); 59 int cryptotest_close(crypto_op_t *op); 60 int get_mech_info(crypto_op_t *op); 61 int get_hsession_by_mech(crypto_op_t *op); 62 63 /* CRYPTO_MAC */ 64 int mac_init(crypto_op_t *op); 65 int mac_single(crypto_op_t *op); 66 int mac_update(crypto_op_t *op, int offset); 67 int mac_final(crypto_op_t *op); 68 69 /* CRYPTO_ENCRYPT */ 70 int encrypt_init(crypto_op_t *op); 71 int encrypt_single(crypto_op_t *op); 72 int encrypt_update(crypto_op_t *op, int offset, size_t *encrlen); 73 int encrypt_final(crypto_op_t *op, size_t encrlen); 74 75 /* CRYPTO_DECRYPT */ 76 int decrypt_init(crypto_op_t *op); 77 int decrypt_single(crypto_op_t *op); 78 int decrypt_update(crypto_op_t *op, int offset, size_t *encrlen); 79 int decrypt_final(crypto_op_t *op, size_t encrlen); 80 81 /* CRYPTO_DIGEST */ 82 int digest_init(crypto_op_t *op); 83 int digest_single(crypto_op_t *op); 84 int digest_update(crypto_op_t *op, int); 85 int digest_final(crypto_op_t *op); 86 87 /* wrappers */ 88 int test_mac_single(cryptotest_t *args); 89 int test_mac(cryptotest_t *args); 90 91 int test_encrypt_single(cryptotest_t *args); 92 int test_encrypt(cryptotest_t *args); 93 94 int test_decrypt_single(cryptotest_t *args); 95 int test_decrypt(cryptotest_t *args); 96 97 int test_digest_single(cryptotest_t *args); 98 int test_digest(cryptotest_t *args); 99 100 extern test_fg_t cryptotest_decr_fg; 101 extern test_fg_t cryptotest_encr_fg; 102 extern test_fg_t cryptotest_mac_fg; 103 extern test_fg_t cryptotest_digest_fg; 104 105 #define MAC_FG (&cryptotest_mac_fg) 106 #define ENCR_FG (&cryptotest_encr_fg) 107 #define DECR_FG (&cryptotest_decr_fg) 108 #define DIGEST_FG (&cryptotest_digest_fg) 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif /* _CRYPTOTEST_H */