Print this page
4896 Performance improvements for KCF AES modes
*** 20,29 ****
--- 20,32 ----
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+ /*
+ * Copyright 2015 by Saso Kiselkov. All rights reserved.
+ */
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/ddi.h>
#include <sys/sysmacros.h>
*** 984,994 ****
*keyp ^= (k & 0x0101010101010101ULL);
*keyp ^= 0x0101010101010101ULL;
}
void
! des_copy_block(uint8_t *in, uint8_t *out)
{
if (IS_P2ALIGNED(in, sizeof (uint32_t)) &&
IS_P2ALIGNED(out, sizeof (uint32_t))) {
/* LINTED: pointer alignment */
*(uint32_t *)&out[0] = *(uint32_t *)&in[0];
--- 987,997 ----
*keyp ^= (k & 0x0101010101010101ULL);
*keyp ^= 0x0101010101010101ULL;
}
void
! des_copy_block(const uint8_t *in, uint8_t *out)
{
if (IS_P2ALIGNED(in, sizeof (uint32_t)) &&
IS_P2ALIGNED(out, sizeof (uint32_t))) {
/* LINTED: pointer alignment */
*(uint32_t *)&out[0] = *(uint32_t *)&in[0];
*** 999,1009 ****
}
}
/* XOR block of data into dest */
void
! des_xor_block(uint8_t *data, uint8_t *dst)
{
if (IS_P2ALIGNED(dst, sizeof (uint32_t)) &&
IS_P2ALIGNED(data, sizeof (uint32_t))) {
/* LINTED: pointer alignment */
*(uint32_t *)&dst[0] ^=
--- 1002,1012 ----
}
}
/* XOR block of data into dest */
void
! des_xor_block(const uint8_t *data, uint8_t *dst)
{
if (IS_P2ALIGNED(dst, sizeof (uint32_t)) &&
IS_P2ALIGNED(data, sizeof (uint32_t))) {
/* LINTED: pointer alignment */
*(uint32_t *)&dst[0] ^=
*** 1054,1076 ****
if (des_ctx->dc_flags & DES3_STRENGTH) {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_encrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des3_encrypt_block,
! des_copy_block, des_xor_block);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des3_encrypt_block);
}
} else {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_encrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des_encrypt_block,
! des_copy_block, des_xor_block);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des_encrypt_block);
}
}
return (rv);
}
--- 1057,1079 ----
if (des_ctx->dc_flags & DES3_STRENGTH) {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_encrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des3_encrypt_block,
! des_copy_block, des_xor_block, NULL);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des3_encrypt_block, NULL);
}
} else {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_encrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des_encrypt_block,
! des_copy_block, des_xor_block, NULL);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des_encrypt_block, NULL);
}
}
return (rv);
}
*** 1086,1110 ****
if (des_ctx->dc_flags & DES3_STRENGTH) {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_decrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des3_decrypt_block,
! des_copy_block, des_xor_block);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des3_decrypt_block);
if (rv == CRYPTO_DATA_LEN_RANGE)
rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
}
} else {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_decrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des_decrypt_block,
! des_copy_block, des_xor_block);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des_decrypt_block);
if (rv == CRYPTO_DATA_LEN_RANGE)
rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
}
}
return (rv);
--- 1089,1113 ----
if (des_ctx->dc_flags & DES3_STRENGTH) {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_decrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des3_decrypt_block,
! des_copy_block, des_xor_block, NULL, NULL);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des3_decrypt_block, NULL);
if (rv == CRYPTO_DATA_LEN_RANGE)
rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
}
} else {
if (des_ctx->dc_flags & CBC_MODE) {
rv = cbc_decrypt_contiguous_blocks(ctx, data,
length, out, DES_BLOCK_LEN, des_decrypt_block,
! des_copy_block, des_xor_block, NULL, NULL);
} else {
rv = ecb_cipher_contiguous_blocks(ctx, data, length,
! out, DES_BLOCK_LEN, des_decrypt_block, NULL);
if (rv == CRYPTO_DATA_LEN_RANGE)
rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
}
}
return (rv);