/* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2021 Tintri by DDN, Inc. All rights reserved. */ #include #include #include #include #include #include #include #include #include #include "test_data.h" #include "utils.h" /* * Test program for the interfaces used in * smb3_encrypt_reply() */ int do_encrypt(uint8_t *outbuf, size_t *outlen, const char *inbuf, size_t inlen, int mid) { smb_enc_ctx_t ctx; uio_t uio_in; uio_t uio_out; iovec_t iov_in[4]; iovec_t iov_out[4]; int rc; bzero(&ctx, sizeof (ctx)); ctx.mech.mechanism = mid; // CKM_AES_CCM or CKM_AES_GCM switch (mid) { case CKM_AES_CCM: smb3_crypto_init_ccm_param(&ctx, (uint8_t *)nonce, 11, (uint8_t *)authdata, 16, inlen); break; case CKM_AES_GCM: smb3_crypto_init_gcm_param(&ctx, (uint8_t *)nonce, 12, (uint8_t *)authdata, 16); break; default: return (1); } rc = smb3_encrypt_init(&ctx, (uint8_t *)keydata, 16); if (rc != 0) return (rc); make_uio((void *)inbuf, inlen, &uio_in, iov_in, 4); make_uio(outbuf, *outlen, &uio_out, iov_out, 4); *outlen = uio_out.uio_resid; rc = smb3_encrypt_uio(&ctx, &uio_in, &uio_out); *outlen -= uio_out.uio_resid; smb3_enc_ctx_done(&ctx); return (rc); } uint8_t outbuf[CIPHER_DATA_LEN]; void test_encrypt(const uint8_t *ref, int mid) { size_t outlen; int rc; outlen = sizeof (outbuf); rc = do_encrypt(outbuf, &outlen, clear_data_ref, clear_data_len, mid); if (rc != 0) { printf("FAIL: encrypt rc= %d\n"); return; } if (outlen != CIPHER_DATA_LEN) { printf("FAIL: out len = %d (want %d)\n", outlen, CIPHER_DATA_LEN); return; } if (memcmp(outbuf, ref, CIPHER_DATA_LEN) != 0) { printf("FAIL: ciphertext:\n"); hexdump(outbuf, CIPHER_DATA_LEN); return; } printf("PASS mid=0x%x\n", mid); } int main(int argc, char *argv[]) { test_encrypt(cipher_data_ccm, CKM_AES_CCM); test_encrypt(cipher_data_gcm, CKM_AES_GCM); return (0); }