Print this page
4896 Performance improvements for KCF AES modes

Split Close
Expand all
Collapse all
          --- old/usr/src/common/crypto/blowfish/blowfish_impl.c
          +++ new/usr/src/common/crypto/blowfish/blowfish_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 2010 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  /*
  27   30   * Blowfish encryption/decryption and keyschedule code.
  28   31   */
  29   32  
  30   33  #include <sys/types.h>
  31   34  #include <sys/systm.h>
  32   35  #include <sys/ddi.h>
  33   36  #include <sys/sysmacros.h>
  34   37  #include <sys/strsun.h>
↓ open down ↓ 657 lines elided ↑ open up ↑
 692  695  #endif /* _KERNEL */
 693  696          if (keysched != NULL) {
 694  697                  *size = sizeof (keysched_t);
 695  698                  return (keysched);
 696  699          }
 697  700  
 698  701          return (NULL);
 699  702  }
 700  703  
 701  704  void
 702      -blowfish_copy_block(uint8_t *in, uint8_t *out)
      705 +blowfish_copy_block(const uint8_t *in, uint8_t *out)
 703  706  {
 704  707          if (IS_P2ALIGNED(in, sizeof (uint32_t)) &&
 705  708              IS_P2ALIGNED(out, sizeof (uint32_t))) {
 706  709                  /* LINTED: pointer alignment */
 707  710                  *(uint32_t *)&out[0] = *(uint32_t *)&in[0];
 708  711                  /* LINTED: pointer alignment */
 709  712                  *(uint32_t *)&out[4] = *(uint32_t *)&in[4];
 710  713          } else {
 711  714                  BLOWFISH_COPY_BLOCK(in, out);
 712  715          }
 713  716  }
 714  717  
 715  718  /* XOR block of data into dest */
 716  719  void
 717      -blowfish_xor_block(uint8_t *data, uint8_t *dst)
      720 +blowfish_xor_block(const uint8_t *data, uint8_t *dst)
 718  721  {
 719  722          if (IS_P2ALIGNED(dst, sizeof (uint32_t)) &&
 720  723              IS_P2ALIGNED(data, sizeof (uint32_t))) {
 721  724                  /* LINTED: pointer alignment */
 722  725                  *(uint32_t *)&dst[0] ^= *(uint32_t *)&data[0];
 723  726                  /* LINTED: pointer alignment */
 724  727                  *(uint32_t *)&dst[4] ^= *(uint32_t *)&data[4];
 725  728          } else {
 726  729                  BLOWFISH_XOR_BLOCK(data, dst);
 727  730          }
↓ open down ↓ 5 lines elided ↑ open up ↑
 733  736  int
 734  737  blowfish_encrypt_contiguous_blocks(void *ctx, char *data, size_t length,
 735  738      crypto_data_t *out)
 736  739  {
 737  740          blowfish_ctx_t *blowfish_ctx = ctx;
 738  741          int rv;
 739  742  
 740  743          if (blowfish_ctx->bc_flags & CBC_MODE) {
 741  744                  rv = cbc_encrypt_contiguous_blocks(ctx, data, length, out,
 742  745                      BLOWFISH_BLOCK_LEN, blowfish_encrypt_block,
 743      -                    blowfish_copy_block, blowfish_xor_block);
      746 +                    blowfish_copy_block, blowfish_xor_block, NULL);
 744  747          } else {
 745  748                  rv = ecb_cipher_contiguous_blocks(ctx, data, length, out,
 746      -                    BLOWFISH_BLOCK_LEN, blowfish_encrypt_block);
      749 +                    BLOWFISH_BLOCK_LEN, blowfish_encrypt_block, NULL);
 747  750          }
 748  751          return (rv);
 749  752  }
 750  753  
 751  754  /*
 752  755   * Decrypt multiple blocks of data according to mode.
 753  756   */
 754  757  int
 755  758  blowfish_decrypt_contiguous_blocks(void *ctx, char *data, size_t length,
 756  759      crypto_data_t *out)
 757  760  {
 758  761          blowfish_ctx_t *blowfish_ctx = ctx;
 759  762          int rv;
 760  763  
 761  764          if (blowfish_ctx->bc_flags & CBC_MODE) {
 762  765                  rv = cbc_decrypt_contiguous_blocks(ctx, data, length, out,
 763  766                      BLOWFISH_BLOCK_LEN, blowfish_decrypt_block,
 764      -                    blowfish_copy_block, blowfish_xor_block);
      767 +                    blowfish_copy_block, blowfish_xor_block, NULL, NULL);
 765  768          } else {
 766  769                  rv = ecb_cipher_contiguous_blocks(ctx, data, length, out,
 767      -                    BLOWFISH_BLOCK_LEN, blowfish_decrypt_block);
      770 +                    BLOWFISH_BLOCK_LEN, blowfish_decrypt_block, NULL);
 768  771                  if (rv == CRYPTO_DATA_LEN_RANGE)
 769  772                          rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
 770  773          }
 771  774          return (rv);
 772  775  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX