Print this page
first pass

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libcrypt/common/des_soft.c
          +++ new/usr/src/lib/libcrypt/common/des_soft.c
↓ open down ↓ 118 lines elided ↑ open up ↑
 119  119  #endif /* def _KERNEL */
 120  120  
 121  121  #ifdef CRYPT
 122  122  /*
 123  123   * Software encrypt or decrypt a block of data (multiple of 8 bytes)
 124  124   * Do the CBC ourselves if needed.
 125  125   */
 126  126  int
 127  127  __des_crypt(char *buf, unsigned int len, struct desparams *desp)
 128  128  {
 129      -/* EXPORT DELETE START */
 130  129          short i;
 131  130          unsigned mode;
 132  131          unsigned dir;
 133  132          char nextiv[8];
 134  133          struct deskeydata softkey;
 135  134  
 136  135          mode = (unsigned)desp->des_mode;
 137  136          dir = (unsigned)desp->des_dir;
 138  137          des_setkey(desp->des_key, &softkey, dir);
 139  138          while (len != 0) {
↓ open down ↓ 18 lines elided ↑ open up ↑
 158  157                                  break;
 159  158                          }
 160  159                          break;
 161  160                  case ECB:
 162  161                          des_encrypt((uchar_t *)buf, &softkey);
 163  162                          break;
 164  163                  }
 165  164                  buf += 8;
 166  165                  len -= 8;
 167  166          }
 168      -/* EXPORT DELETE END */
 169  167          return (1);
 170  168  }
 171  169  
 172  170  
 173  171  /*
 174  172   * Set the key and direction for an encryption operation
 175  173   * We build the 16 key entries here
 176  174   */
 177  175  static void
 178  176  des_setkey(uchar_t userkey[8], struct deskeydata *kd, unsigned int dir)
 179  177  {
 180      -/* EXPORT DELETE START */
 181  178          long C, D;
 182  179          short i;
 183  180  
 184  181          /*
 185  182           * First, generate C and D by permuting
 186  183           * the key. The low order bit of each
 187  184           * 8-bit char is not used, so C and D are only 28
 188  185           * bits apiece.
 189  186           */
 190  187          {
↓ open down ↓ 59 lines elided ↑ open up ↑
 250  247                                  if (C & (BIT28 >> PC2_C[bit]))
 251  248                                          c->long0 |= bbit >> k;
 252  249                                  if (D & (BIT28 >> PC2_D[bit]))
 253  250                                          c->long1 |= bbit >> k;
 254  251                                  bit++;
 255  252                          }
 256  253                          bbit >>= 8;
 257  254                  }
 258  255  
 259  256          }
 260      -/* EXPORT DELETE END */
 261  257  }
 262  258  
 263  259  
 264  260  
 265  261  /*
 266  262   * Do an encryption operation
 267  263   * Much pain is taken (with preprocessor) to avoid loops so the compiler
 268  264   * can do address arithmetic instead of doing it at runtime.
 269  265   * Note that the byte-to-chunk conversion is necessary to guarantee
 270  266   * processor byte-order independence.
 271  267   */
 272  268  static void
 273  269  des_encrypt(uchar_t *data, struct deskeydata *kd)
 274  270  {
 275      -/* EXPORT DELETE START */
 276  271          chunk_t work1, work2;
 277  272  
 278  273          /*
 279  274           * Initial permutation
 280  275           * and byte to chunk conversion
 281  276           */
 282  277          {
 283  278                  const uint32_t *lp;
 284  279                  uint32_t l0, l1, w;
 285  280                  short i, pbit;
↓ open down ↓ 147 lines elided ↑ open up ↑
 433  428                  work2.long1 = l1;
 434  429          }
 435  430          data[0] = work2.byte0;
 436  431          data[1] = work2.byte1;
 437  432          data[2] = work2.byte2;
 438  433          data[3] = work2.byte3;
 439  434          data[4] = work2.byte4;
 440  435          data[5] = work2.byte5;
 441  436          data[6] = work2.byte6;
 442  437          data[7] = work2.byte7;
 443      -
 444      -/* EXPORT DELETE END */
 445  438  }
 446  439  #endif /* def CRYPT */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX