23c57df72989c916b3e98084eb88d48777999691mcpowers * CDDL HEADER START
23c57df72989c916b3e98084eb88d48777999691mcpowers * The contents of this file are subject to the terms of the
23c57df72989c916b3e98084eb88d48777999691mcpowers * Common Development and Distribution License (the "License").
23c57df72989c916b3e98084eb88d48777999691mcpowers * You may not use this file except in compliance with the License.
23c57df72989c916b3e98084eb88d48777999691mcpowers * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
23c57df72989c916b3e98084eb88d48777999691mcpowers * See the License for the specific language governing permissions
23c57df72989c916b3e98084eb88d48777999691mcpowers * and limitations under the License.
23c57df72989c916b3e98084eb88d48777999691mcpowers * When distributing Covered Code, include this CDDL HEADER in each
23c57df72989c916b3e98084eb88d48777999691mcpowers * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
23c57df72989c916b3e98084eb88d48777999691mcpowers * If applicable, add the following below this CDDL HEADER, with the
23c57df72989c916b3e98084eb88d48777999691mcpowers * fields enclosed by brackets "[]" replaced with your own identifying
23c57df72989c916b3e98084eb88d48777999691mcpowers * information: Portions Copyright [yyyy] [name of copyright owner]
23c57df72989c916b3e98084eb88d48777999691mcpowers * CDDL HEADER END
23c57df72989c916b3e98084eb88d48777999691mcpowers * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23c57df72989c916b3e98084eb88d48777999691mcpowers * Use is subject to license terms.
23c57df72989c916b3e98084eb88d48777999691mcpowers * Encrypt and decrypt multiple blocks of data in counter mode.
23c57df72989c916b3e98084eb88d48777999691mcpowersctr_mode_contiguous_blocks(ctr_ctx_t *ctx, char *data, size_t length,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*cipher)(const void *ks, const uint8_t *pt, uint8_t *ct),
23c57df72989c916b3e98084eb88d48777999691mcpowers if (length + ctx->ctr_remainder_len < block_size) {
23c57df72989c916b3e98084eb88d48777999691mcpowers /* accumulate bytes here and return */
23c57df72989c916b3e98084eb88d48777999691mcpowers (uint8_t *)ctx->ctr_remainder + ctx->ctr_remainder_len,
23c57df72989c916b3e98084eb88d48777999691mcpowers /* Unprocessed data from last call. */
23c57df72989c916b3e98084eb88d48777999691mcpowers /* ctr_cb is the counter block */
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers * Increment Counter.
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers lower_counter = ntohll(ctx->ctr_cb[1] & ctx->ctr_lower_mask);
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers ctx->ctr_cb[1] = (ctx->ctr_cb[1] & ~(ctx->ctr_lower_mask)) |
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers /* wrap around */
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers * XOR encrypted counter block with the current clear block.
23c57df72989c916b3e98084eb88d48777999691mcpowers crypto_get_ptrs(out, &iov_or_mp, &offset, &out_data_1,
23c57df72989c916b3e98084eb88d48777999691mcpowers /* copy block to where it belongs */
23c57df72989c916b3e98084eb88d48777999691mcpowers /* update offset */
23c57df72989c916b3e98084eb88d48777999691mcpowers /* Update pointer to next block of data to be processed. */
23c57df72989c916b3e98084eb88d48777999691mcpowers /* Incomplete last block. */
23c57df72989c916b3e98084eb88d48777999691mcpowers } while (remainder > 0);
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *))
23c57df72989c916b3e98084eb88d48777999691mcpowers encrypt_block(ctx->ctr_keysched, (uint8_t *)ctx->ctr_cb,
23c57df72989c916b3e98084eb88d48777999691mcpowers crypto_get_ptrs(out, &iov_or_mp, &offset, &out_data_1,
23c57df72989c916b3e98084eb88d48777999691mcpowers &out_data_1_len, &out_data_2, ctx->ctr_remainder_len);
23c57df72989c916b3e98084eb88d48777999691mcpowers out_data_2, ctx->ctr_remainder_len - out_data_1_len);
23c57df72989c916b3e98084eb88d48777999691mcpowersctr_init_ctx(ctr_ctx_t *ctr_ctx, ulong_t count, uint8_t *cb,
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers /* upper 64 bits of the mask */
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers upper_mask = (count == 64) ? UINT64_MAX : (1ULL << count) - 1;
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers /* now the lower 63 bits */
23c57df72989c916b3e98084eb88d48777999691mcpowers ctr_ctx->ctr_lastp = (uint8_t *)&ctr_ctx->ctr_cb[0];
23c57df72989c916b3e98084eb88d48777999691mcpowers/* ARGSUSED */
23c57df72989c916b3e98084eb88d48777999691mcpowers if ((ctr_ctx = kmem_zalloc(sizeof (ctr_ctx_t), kmflag)) == NULL)