aes_cbc_crypt.c revision 234a61874a02ec04dc4f51cebd5e255f00cf2df8
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include "aes_cbc_crypt.h"
#include "aes_impl.h"
#ifndef _KERNEL
#include <strings.h>
#endif /* !_KERNEL */
crypto_data_t *);
/*
* Initialize by setting iov_or_mp to point to the current iovec or mp,
* and by setting current_offset to an offset within the current iovec or mp .
*/
static void
{
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO: {
*current_offset = offset;
break;
}
case CRYPTO_DATA_MBLK: {
*current_offset = offset;
break;
}
} /* end switch */
}
/*
* Get pointers for where in the output to copy a block of encrypted or
* decrypted data. The iov_or_mp argument stores a pointer to the current
* iovec or mp, and offset stores an offset into the current iovec or mp.
*/
static void
{
case CRYPTO_DATA_RAW: {
offset = *current_offset;
/* one AES block fits */
*out_data_1_len = amt;
*out_data_2 = NULL;
}
break;
}
case CRYPTO_DATA_UIO: {
uint8_t *p;
offset = *current_offset;
*out_data_1 = p;
/* can fit one AES block into this iov */
*out_data_1_len = amt;
*out_data_2 = NULL;
} else {
/* one AES block spans two iovecs */
return;
vec_idx++;
}
break;
}
case CRYPTO_DATA_MBLK: {
uint8_t *p;
offset = *current_offset;
*out_data_1 = p;
/* can fit one AES block into this mblk */
*out_data_1_len = amt;
*out_data_2 = NULL;
} else {
/* one AES block spans two mblks */
return;
}
break;
}
} /* end switch */
}
static int
{
/* EXPORT DELETE START */
void *iov_or_mp;
/* accumulate bytes here and return */
length);
return (0);
}
do {
/* Unprocessed data from last call. */
if (ctx->ac_remainder_len > 0) {
return (1);
} else {
}
/* don't write on the plaintext */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
} else {
}
}
/*
* XOR the previous cipher block or IV with the
* current clear block. Check for alignment.
*/
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
} else {
}
}
if (ctx->ac_remainder_len > 0) {
need);
}
} else {
/* copy block to where it belongs */
if (out_data_2 != NULL) {
}
/* update offset */
}
/* Update pointer to next block of data to be processed. */
if (ctx->ac_remainder_len != 0) {
ctx->ac_remainder_len = 0;
} else {
datap += AES_BLOCK_LEN;
}
/* Incomplete last block. */
goto out;
}
} while (remainder > 0);
out:
/*
* Save the last encrypted block in the context - but only for
* the CBC mode of operation.
*/
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
} else {
}
}
/* EXPORT DELETE END */
return (0);
}
/*
* Encrypt multiple blocks of data.
*/
/* ARGSUSED */
int
{
}
/* ARGSUSED */
static int
{
/* EXPORT DELETE START */
void *iov_or_mp;
/* accumulate bytes here and return */
length);
return (0);
}
do {
/* Unprocessed data from last call. */
if (ctx->ac_remainder_len > 0) {
return (1);
} else {
}
/* Save current ciphertext block */
/* LINTED: pointer alignment */
ctx);
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
} else {
/* LINTED: pointer alignment */
}
}
} else {
}
/*
* XOR the previous cipher block or IV with the
* currently decrypted block. Check for alignment.
*/
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
} else {
}
/* LINTED: pointer alignment */
}
/* copy temporary block to where it belongs */
if (out_data_2 != NULL) {
}
/* update offset */
} else if (ctx->ac_remainder_len > 0) {
/* copy temporary block to where it belongs */
}
/* Update pointer to next block of data to be processed. */
if (ctx->ac_remainder_len != 0) {
ctx->ac_remainder_len = 0;
} else {
datap += AES_BLOCK_LEN;
}
/* Incomplete last block. */
return (0);
}
} while (remainder > 0);
/* EXPORT DELETE END */
return (0);
}
/*
* Decrypt multiple blocks of data.
*/
int
{
}
/* ARGSUSED */
int
{
/* EXPORT DELETE START */
int i;
void *iov_or_mp;
return (CRYPTO_ARGUMENTS_BAD);
/* ac_iv is the counter block */
(uint8_t *)counter_block);
/* copy remainder to temporary buffer */
/* XOR with counter block */
for (i = 0; i < ctx->ac_remainder_len; i++) {
}
/* copy temporary block to where it belongs */
if (out_data_2 != NULL) {
}
ctx->ac_remainder_len = 0;
/* EXPORT DELETE END */
return (0);
}
/*
* Encrypt and decrypt multiple blocks of data in counter mode.
*/
/* ARGSUSED */
int
{
/* EXPORT DELETE START */
void *iov_or_mp;
#ifdef _LITTLE_ENDIAN
uint8_t *p;
#endif
/* accumulate bytes here and return */
length);
return (0);
}
do {
/* Unprocessed data from last call. */
if (ctx->ac_remainder_len > 0) {
return (1);
} else {
}
/* don't write on the plaintext */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
} else {
}
}
/* ac_cb is the counter block */
(uint8_t *)counter_block);
/*
* Increment counter. Counter bits are confined
* to the bottom 64 bits of the counter block.
*/
#ifdef _LITTLE_ENDIAN
(uint64_t)p[7]);
#endif
counter++;
#ifdef _LITTLE_ENDIAN
(uint64_t)p[7]);
#endif
/*
* XOR the previous cipher block or IV with the
* current clear block. Check for alignment.
*/
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
/* LINTED: pointer alignment */
} else {
}
if (ctx->ac_remainder_len > 0) {
need);
}
} else {
/* copy block to where it belongs */
if (out_data_2 != NULL) {
}
/* update offset */
}
/* Update pointer to next block of data to be processed. */
if (ctx->ac_remainder_len != 0) {
ctx->ac_remainder_len = 0;
} else {
datap += AES_BLOCK_LEN;
}
/* Incomplete last block. */
goto out;
}
} while (remainder > 0);
out:
/* EXPORT DELETE END */
return (0);
}