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 2019 Joyent, Inc. 15 * Copyright 2023 RackTop Systems, Inc. 16 */ 17 18 #ifndef _CRYPTOTEST_H 19 #define _CRYPTOTEST_H 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #include <inttypes.h> 26 #include <sys/crypto/ioctl.h> 27 28 /* 29 * A somewhat arbitrary size that should be large enough to hold the printed 30 * error and size messages. 31 */ 32 #define BUFSZ 128 33 34 #define CTEST_INIT_FAILED (-1) 35 #define CTEST_NAME_RESOLVE_FAILED (-2) 36 #define CTEST_MECH_NO_PROVIDER (-3) 37 38 #define CTEST_UPDATELEN_WHOLE SIZE_MAX 39 #define CTEST_UPDATELEN_END 0 40 41 typedef struct cryptotest { 42 uint8_t *in; 43 uint8_t *out; 44 uint8_t *key; 45 void *param; 46 47 size_t inlen; 48 size_t outlen; 49 size_t keylen; 50 size_t plen; 51 52 char *mechname; 53 size_t *updatelens; 54 } cryptotest_t; 55 56 typedef struct crypto_op crypto_op_t; 57 58 typedef struct test_fg { 59 crypto_func_group_t tf_fg; 60 int (*tf_init)(crypto_op_t *); 61 int (*tf_single)(crypto_op_t *); 62 int (*tf_update)(crypto_op_t *, size_t, size_t, size_t *); 63 int (*tf_final)(crypto_op_t *, size_t); 64 } test_fg_t; 65 66 #define CRYPTO_INVALID_SESSION ((crypto_session_id_t)-1) 67 68 int run_test(cryptotest_t *args, uint8_t *cmp, size_t cmplen, test_fg_t *funcs); 69 70 const char *cryptotest_errstr(int e, char *buf, size_t buflen); 71 72 /* utils */ 73 crypto_op_t *cryptotest_init(cryptotest_t *args, crypto_func_group_t fg); 74 void cryptotest_close(crypto_op_t *op); 75 int get_mech_info(crypto_op_t *op); 76 int get_hsession_by_mech(crypto_op_t *op); 77 78 /* CRYPTO_MAC */ 79 int mac_init(crypto_op_t *op); 80 int mac_single(crypto_op_t *op); 81 int mac_update(crypto_op_t *op, size_t offset, size_t len, size_t *dummy); 82 int mac_final(crypto_op_t *op, size_t dummy); 83 84 /* CRYPTO_ENCRYPT */ 85 int encrypt_init(crypto_op_t *op); 86 int encrypt_single(crypto_op_t *op); 87 int encrypt_update(crypto_op_t *op, size_t offset, size_t plainlen, 88 size_t *encrlen); 89 int encrypt_final(crypto_op_t *op, size_t encrlen); 90 91 /* CRYPTO_DECRYPT */ 92 int decrypt_init(crypto_op_t *op); 93 int decrypt_single(crypto_op_t *op); 94 int decrypt_update(crypto_op_t *op, size_t offset, size_t cipherlen, 95 size_t *encrlen); 96 int decrypt_final(crypto_op_t *op, size_t encrlen); 97 98 /* CRYPTO_DIGEST */ 99 int digest_init(crypto_op_t *op); 100 int digest_single(crypto_op_t *op); 101 int digest_update(crypto_op_t *op, size_t offset, size_t len, size_t *dummy); 102 int digest_final(crypto_op_t *op, size_t dummy); 103 104 extern test_fg_t cryptotest_decr_fg; 105 extern test_fg_t cryptotest_encr_fg; 106 extern test_fg_t cryptotest_mac_fg; 107 extern test_fg_t cryptotest_digest_fg; 108 109 #define MAC_FG (&cryptotest_mac_fg) 110 #define ENCR_FG (&cryptotest_encr_fg) 111 #define DECR_FG (&cryptotest_decr_fg) 112 #define DIGEST_FG (&cryptotest_digest_fg) 113 114 /* 115 * KCF and PKCS11 use different structures for the CCM params (CK_AES_CCM_PARAMS 116 * and CK_CCM_PARAMS respectively. Each cryptotest_*.c file implements this 117 * for their respective structs. 118 */ 119 void ccm_init_params(void *, ulong_t, uchar_t *, ulong_t, uchar_t *, ulong_t, 120 ulong_t); 121 size_t ccm_param_len(void); 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif /* _CRYPTOTEST_H */ 128