Print this page
4896 Performance improvements for KCF AES modes

Split Close
Expand all
Collapse all
          --- old/usr/src/common/crypto/modes/modes.c
          +++ new/usr/src/common/crypto/modes/modes.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  #ifndef _KERNEL
  27   30  #include <stdlib.h>
  28   31  #endif
  29   32  
  30   33  #include <sys/strsun.h>
  31   34  #include <sys/types.h>
  32   35  #include <modes/modes.h>
  33   36  #include <sys/crypto/common.h>
  34   37  #include <sys/crypto/impl.h>
↓ open down ↓ 36 lines elided ↑ open up ↑
  71   74                          ;
  72   75  
  73   76                  *current_offset = offset;
  74   77                  *iov_or_mp = mp;
  75   78                  break;
  76   79  
  77   80          }
  78   81          } /* end switch */
  79   82  }
  80   83  
  81      -/*
  82      - * Get pointers for where in the output to copy a block of encrypted or
  83      - * decrypted data.  The iov_or_mp argument stores a pointer to the current
  84      - * iovec or mp, and offset stores an offset into the current iovec or mp.
  85      - */
  86   84  void
  87      -crypto_get_ptrs(crypto_data_t *out, void **iov_or_mp, offset_t *current_offset,
  88      -    uint8_t **out_data_1, size_t *out_data_1_len, uint8_t **out_data_2,
  89      -    size_t amt)
  90      -{
  91      -        offset_t offset;
  92      -
  93      -        switch (out->cd_format) {
  94      -        case CRYPTO_DATA_RAW: {
  95      -                iovec_t *iov;
  96      -
  97      -                offset = *current_offset;
  98      -                iov = &out->cd_raw;
  99      -                if ((offset + amt) <= iov->iov_len) {
 100      -                        /* one block fits */
 101      -                        *out_data_1 = (uint8_t *)iov->iov_base + offset;
 102      -                        *out_data_1_len = amt;
 103      -                        *out_data_2 = NULL;
 104      -                        *current_offset = offset + amt;
 105      -                }
 106      -                break;
 107      -        }
 108      -
 109      -        case CRYPTO_DATA_UIO: {
 110      -                uio_t *uio = out->cd_uio;
 111      -                iovec_t *iov;
 112      -                offset_t offset;
 113      -                uintptr_t vec_idx;
 114      -                uint8_t *p;
 115      -
 116      -                offset = *current_offset;
 117      -                vec_idx = (uintptr_t)(*iov_or_mp);
 118      -                iov = &uio->uio_iov[vec_idx];
 119      -                p = (uint8_t *)iov->iov_base + offset;
 120      -                *out_data_1 = p;
 121      -
 122      -                if (offset + amt <= iov->iov_len) {
 123      -                        /* can fit one block into this iov */
 124      -                        *out_data_1_len = amt;
 125      -                        *out_data_2 = NULL;
 126      -                        *current_offset = offset + amt;
 127      -                } else {
 128      -                        /* one block spans two iovecs */
 129      -                        *out_data_1_len = iov->iov_len - offset;
 130      -                        if (vec_idx == uio->uio_iovcnt)
 131      -                                return;
 132      -                        vec_idx++;
 133      -                        iov = &uio->uio_iov[vec_idx];
 134      -                        *out_data_2 = (uint8_t *)iov->iov_base;
 135      -                        *current_offset = amt - *out_data_1_len;
 136      -                }
 137      -                *iov_or_mp = (void *)vec_idx;
 138      -                break;
 139      -        }
 140      -
 141      -        case CRYPTO_DATA_MBLK: {
 142      -                mblk_t *mp;
 143      -                uint8_t *p;
 144      -
 145      -                offset = *current_offset;
 146      -                mp = (mblk_t *)*iov_or_mp;
 147      -                p = mp->b_rptr + offset;
 148      -                *out_data_1 = p;
 149      -                if ((p + amt) <= mp->b_wptr) {
 150      -                        /* can fit one block into this mblk */
 151      -                        *out_data_1_len = amt;
 152      -                        *out_data_2 = NULL;
 153      -                        *current_offset = offset + amt;
 154      -                } else {
 155      -                        /* one block spans two mblks */
 156      -                        *out_data_1_len = _PTRDIFF(mp->b_wptr, p);
 157      -                        if ((mp = mp->b_cont) == NULL)
 158      -                                return;
 159      -                        *out_data_2 = mp->b_rptr;
 160      -                        *current_offset = (amt - *out_data_1_len);
 161      -                }
 162      -                *iov_or_mp = mp;
 163      -                break;
 164      -        }
 165      -        } /* end switch */
 166      -}
 167      -
 168      -void
 169   85  crypto_free_mode_ctx(void *ctx)
 170   86  {
 171   87          common_ctx_t *common_ctx = (common_ctx_t *)ctx;
 172   88  
 173   89          switch (common_ctx->cc_flags &
 174   90              (ECB_MODE|CBC_MODE|CTR_MODE|CCM_MODE|GCM_MODE|GMAC_MODE)) {
 175   91          case ECB_MODE:
 176   92  #ifdef _KERNEL
 177   93                  kmem_free(common_ctx, sizeof (ecb_ctx_t));
 178   94  #else
↓ open down ↓ 27 lines elided ↑ open up ↑
 206  122  #else
 207  123                  if (((ccm_ctx_t *)ctx)->ccm_pt_buf != NULL)
 208  124                          free(((ccm_ctx_t *)ctx)->ccm_pt_buf);
 209  125                  free(ctx);
 210  126  #endif
 211  127                  break;
 212  128  
 213  129          case GCM_MODE:
 214  130          case GMAC_MODE:
 215  131  #ifdef _KERNEL
 216      -                if (((gcm_ctx_t *)ctx)->gcm_pt_buf != NULL)
 217      -                        kmem_free(((gcm_ctx_t *)ctx)->gcm_pt_buf,
 218      -                            ((gcm_ctx_t *)ctx)->gcm_pt_buf_len);
 219      -
 220  132                  kmem_free(ctx, sizeof (gcm_ctx_t));
 221  133  #else
 222      -                if (((gcm_ctx_t *)ctx)->gcm_pt_buf != NULL)
 223      -                        free(((gcm_ctx_t *)ctx)->gcm_pt_buf);
 224  134                  free(ctx);
 225  135  #endif
 226  136          }
 227  137  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX