Print this page
6652716 Need an ARCFOUR implementation optimized for Intel EM64T

Split Close
Expand all
Collapse all
          --- old/usr/src/common/crypto/arcfour/arcfour_crypt.c
          +++ new/usr/src/common/crypto/arcfour/arcfour_crypt.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  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 2008 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26      -#pragma ident   "@(#)arcfour_crypt.c    1.6     08/01/02 SMI"
       26 +#pragma ident   "@(#)arcfour_crypt.c    1.7     08/03/20 SMI"
  27   27  
  28   28  #include "arcfour.h"
  29   29  
  30   30  #if defined(__amd64)
  31      -/*
  32      - * Use hand-tuned, processor-specific assembly version of arcfour_crypt()
  33      - * for 64-bit x86:
  34      - */
  35      -#define USE_PSR_VERSION_OF_ARCFOUR_CRYPT
  36      -#endif /* __amd64 */
       31 +#ifdef _KERNEL
       32 +#include <sys/x86_archext.h>
       33 +#include <sys/cpuvar.h>
  37   34  
       35 +#else
       36 +#include <sys/auxv.h>
       37 +#endif  /* _KERNEL */
       38 +#endif  /* __amd64 */
       39 +
       40 +#if !defined(__amd64)
  38   41  /* Initialize the key stream 'key' using the key value */
  39   42  void
  40   43  arcfour_key_init(ARCFour_key *key, uchar_t *keyval, int keyvallen)
  41   44  {
  42   45  /* EXPORT DELETE START */
  43   46  
  44   47          uchar_t ext_keyval[256];
  45   48          uchar_t tmp;
  46   49          int i, j;
  47   50  
       51 +        /* Normalize key length to 256 */
  48   52          for (i = j = 0; i < 256; i++, j++) {
  49   53                  if (j == keyvallen)
  50   54                          j = 0;
  51      -
  52   55                  ext_keyval[i] = keyval[j];
  53   56          }
       57 +
  54   58          for (i = 0; i < 256; i++)
  55   59                  key->arr[i] = (uchar_t)i;
  56   60  
  57   61          j = 0;
  58   62          for (i = 0; i < 256; i++) {
  59   63                  j = (j + key->arr[i] + ext_keyval[i]) % 256;
  60   64                  tmp = key->arr[i];
  61   65                  key->arr[i] = key->arr[j];
  62   66                  key->arr[j] = tmp;
  63   67          }
  64   68          key->i = 0;
  65   69          key->j = 0;
  66   70  
  67   71  /* EXPORT DELETE END */
  68   72  }
  69   73  
  70   74  
  71      -#if !defined(USE_PSR_VERSION_OF_ARCFOUR_CRYPT)
  72   75  /*
  73   76   * Encipher 'in' using 'key'.
  74   77   * in and out can point to the same location
  75   78   */
  76   79  void
  77   80  arcfour_crypt(ARCFour_key *key, uchar_t *in, uchar_t *out, size_t len)
  78   81  {
  79   82          size_t ii;
  80   83          uchar_t tmp, i, j;
  81   84  
↓ open down ↓ 49 lines elided ↑ open up ↑
 131  134                  key->i = i;
 132  135                  key->j = j;
 133  136  #ifdef  sun4u
 134  137          } else {
 135  138                  arcfour_crypt_aligned(key, len, in, out);
 136  139          }
 137  140  #endif  /* sun4u */
 138  141  
 139  142  /* EXPORT DELETE END */
 140  143  }
 141      -#endif  /* !USE_PSR_VERSION_OF_ARCFOUR_CRYPT */
      144 +
      145 +#else
      146 +
      147 +/*
      148 + * Return 1 if executing on Intel, otherwise 0 (e.g., AMD64).
      149 + */
      150 +int
      151 +arcfour_crypt_on_intel(void)
      152 +{
      153 +#ifdef _KERNEL
      154 +        return (cpuid_getvendor(CPU) == X86_VENDOR_Intel);
      155 +#else
      156 +        uint_t  ui;
      157 +        (void) getisax(&ui, 1);
      158 +        return ((ui & AV_386_AMD_MMX) == 0);
      159 +#endif  /* _KERNEL */
      160 +}
      161 +#endif  /* !__amd64 */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX