Print this page
4896 Performance improvements for KCF AES modes

Split Close
Expand all
Collapse all
          --- old/usr/src/common/crypto/des/des_impl.c
          +++ new/usr/src/common/crypto/des/des_impl.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
       25 +/*
       26 + * Copyright 2015 by Saso Kiselkov. All rights reserved.
       27 + */
  25   28  
  26   29  #include <sys/types.h>
  27   30  #include <sys/systm.h>
  28   31  #include <sys/ddi.h>
  29   32  #include <sys/sysmacros.h>
  30   33  #include <sys/strsun.h>
  31   34  #include <sys/crypto/spi.h>
  32   35  #include <modes/modes.h>
  33   36  #include <sys/crypto/common.h>
  34   37  #include "des_impl.h"
↓ open down ↓ 944 lines elided ↑ open up ↑
 979  982  {
 980  983          uint64_t k = *keyp;
 981  984          k ^= k >> 1;
 982  985          k ^= k >> 2;
 983  986          k ^= k >> 4;
 984  987          *keyp ^= (k & 0x0101010101010101ULL);
 985  988          *keyp ^= 0x0101010101010101ULL;
 986  989  }
 987  990  
 988  991  void
 989      -des_copy_block(uint8_t *in, uint8_t *out)
      992 +des_copy_block(const uint8_t *in, uint8_t *out)
 990  993  {
 991  994          if (IS_P2ALIGNED(in, sizeof (uint32_t)) &&
 992  995              IS_P2ALIGNED(out, sizeof (uint32_t))) {
 993  996                  /* LINTED: pointer alignment */
 994  997                  *(uint32_t *)&out[0] = *(uint32_t *)&in[0];
 995  998                  /* LINTED: pointer alignment */
 996  999                  *(uint32_t *)&out[4] = *(uint32_t *)&in[4];
 997 1000          } else {
 998 1001                  DES_COPY_BLOCK(in, out);
 999 1002          }
1000 1003  }
1001 1004  
1002 1005  /* XOR block of data into dest */
1003 1006  void
1004      -des_xor_block(uint8_t *data, uint8_t *dst)
     1007 +des_xor_block(const uint8_t *data, uint8_t *dst)
1005 1008  {
1006 1009          if (IS_P2ALIGNED(dst, sizeof (uint32_t)) &&
1007 1010              IS_P2ALIGNED(data, sizeof (uint32_t))) {
1008 1011                  /* LINTED: pointer alignment */
1009 1012                  *(uint32_t *)&dst[0] ^=
1010 1013                      /* LINTED: pointer alignment */
1011 1014                      *(uint32_t *)&data[0];
1012 1015                      /* LINTED: pointer alignment */
1013 1016                  *(uint32_t *)&dst[4] ^=
1014 1017                      /* LINTED: pointer alignment */
↓ open down ↓ 34 lines elided ↑ open up ↑
1049 1052  des_encrypt_contiguous_blocks(void *ctx, char *data, size_t length,
1050 1053      crypto_data_t *out)
1051 1054  {
1052 1055          des_ctx_t *des_ctx = ctx;
1053 1056          int rv;
1054 1057  
1055 1058          if (des_ctx->dc_flags & DES3_STRENGTH) {
1056 1059                  if (des_ctx->dc_flags & CBC_MODE) {
1057 1060                          rv = cbc_encrypt_contiguous_blocks(ctx, data,
1058 1061                              length, out, DES_BLOCK_LEN, des3_encrypt_block,
1059      -                            des_copy_block, des_xor_block);
     1062 +                            des_copy_block, des_xor_block, NULL);
1060 1063                  } else {
1061 1064                          rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1062      -                            out, DES_BLOCK_LEN, des3_encrypt_block);
     1065 +                            out, DES_BLOCK_LEN, des3_encrypt_block, NULL);
1063 1066                  }
1064 1067          } else {
1065 1068                  if (des_ctx->dc_flags & CBC_MODE) {
1066 1069                          rv = cbc_encrypt_contiguous_blocks(ctx, data,
1067 1070                              length, out, DES_BLOCK_LEN, des_encrypt_block,
1068      -                            des_copy_block, des_xor_block);
     1071 +                            des_copy_block, des_xor_block, NULL);
1069 1072                  } else {
1070 1073                          rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1071      -                            out, DES_BLOCK_LEN, des_encrypt_block);
     1074 +                            out, DES_BLOCK_LEN, des_encrypt_block, NULL);
1072 1075                  }
1073 1076          }
1074 1077          return (rv);
1075 1078  }
1076 1079  
1077 1080  /*
1078 1081   * Decrypt multiple blocks of data according to mode.
1079 1082   */
1080 1083  int
1081 1084  des_decrypt_contiguous_blocks(void *ctx, char *data, size_t length,
1082 1085      crypto_data_t *out)
1083 1086  {
1084 1087          des_ctx_t *des_ctx = ctx;
1085 1088          int rv;
1086 1089  
1087 1090          if (des_ctx->dc_flags & DES3_STRENGTH) {
1088 1091                  if (des_ctx->dc_flags & CBC_MODE) {
1089 1092                          rv = cbc_decrypt_contiguous_blocks(ctx, data,
1090 1093                              length, out, DES_BLOCK_LEN, des3_decrypt_block,
1091      -                            des_copy_block, des_xor_block);
     1094 +                            des_copy_block, des_xor_block, NULL, NULL);
1092 1095                  } else {
1093 1096                          rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1094      -                            out, DES_BLOCK_LEN, des3_decrypt_block);
     1097 +                            out, DES_BLOCK_LEN, des3_decrypt_block, NULL);
1095 1098                          if (rv == CRYPTO_DATA_LEN_RANGE)
1096 1099                                  rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
1097 1100                  }
1098 1101          } else {
1099 1102                  if (des_ctx->dc_flags & CBC_MODE) {
1100 1103                          rv = cbc_decrypt_contiguous_blocks(ctx, data,
1101 1104                              length, out, DES_BLOCK_LEN, des_decrypt_block,
1102      -                            des_copy_block, des_xor_block);
     1105 +                            des_copy_block, des_xor_block, NULL, NULL);
1103 1106                  } else {
1104 1107                          rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1105      -                            out, DES_BLOCK_LEN, des_decrypt_block);
     1108 +                            out, DES_BLOCK_LEN, des_decrypt_block, NULL);
1106 1109                          if (rv == CRYPTO_DATA_LEN_RANGE)
1107 1110                                  rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
1108 1111                  }
1109 1112          }
1110 1113          return (rv);
1111 1114  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX