// SPDX-License-Identifier: CDDL-1.0 /* * 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 * https://opensource.org/license/CDDL-1.0. */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #include #include #include /* Copy a 16-byte AES block from "in" to "out" */ void aes_copy_block(uint8_t *in, uint8_t *out) { if (IS_P2ALIGNED2(in, out, sizeof (uint32_t))) { /* LINTED: pointer alignment */ *(uint32_t *)&out[0] = *(uint32_t *)&in[0]; /* LINTED: pointer alignment */ *(uint32_t *)&out[4] = *(uint32_t *)&in[4]; /* LINTED: pointer alignment */ *(uint32_t *)&out[8] = *(uint32_t *)&in[8]; /* LINTED: pointer alignment */ *(uint32_t *)&out[12] = *(uint32_t *)&in[12]; } else { AES_COPY_BLOCK(in, out); } } /* XOR a 16-byte AES block of data into dst */ void aes_xor_block(uint8_t *data, uint8_t *dst) { if (IS_P2ALIGNED2(dst, data, sizeof (uint32_t))) { /* LINTED: pointer alignment */ *(uint32_t *)&dst[0] ^= *(uint32_t *)&data[0]; /* LINTED: pointer alignment */ *(uint32_t *)&dst[4] ^= *(uint32_t *)&data[4]; /* LINTED: pointer alignment */ *(uint32_t *)&dst[8] ^= *(uint32_t *)&data[8]; /* LINTED: pointer alignment */ *(uint32_t *)&dst[12] ^= *(uint32_t *)&data[12]; } else { AES_XOR_BLOCK(data, dst); } } /* * Encrypt multiple blocks of data according to mode. */ int aes_encrypt_contiguous_blocks(void *ctx, char *data, size_t length, crypto_data_t *out) { aes_ctx_t *aes_ctx = ctx; int rv; if (aes_ctx->ac_flags & CCM_MODE) { rv = ccm_mode_encrypt_contiguous_blocks(ctx, data, length, out, AES_BLOCK_LEN, aes_encrypt_block, aes_copy_block, aes_xor_block); } else if (aes_ctx->ac_flags & GCM_MODE) { rv = gcm_mode_encrypt_contiguous_blocks(ctx, data, length, out, AES_BLOCK_LEN, aes_encrypt_block, aes_copy_block, aes_xor_block); } else __builtin_unreachable(); return (rv); } /* * Decrypt multiple blocks of data according to mode. */ int aes_decrypt_contiguous_blocks(void *ctx, char *data, size_t length, crypto_data_t *out) { aes_ctx_t *aes_ctx = ctx; int rv; if (aes_ctx->ac_flags & CCM_MODE) { rv = ccm_mode_decrypt_contiguous_blocks(ctx, data, length, out, AES_BLOCK_LEN, aes_encrypt_block, aes_copy_block, aes_xor_block); } else if (aes_ctx->ac_flags & GCM_MODE) { rv = gcm_mode_decrypt_contiguous_blocks(ctx, data, length, out, AES_BLOCK_LEN, aes_encrypt_block, aes_copy_block, aes_xor_block); } else __builtin_unreachable(); return (rv); }