Print this page
first pass

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 ↓ 47 lines elided ↑ open up ↑
  48   48  #include <strings.h>
  49   49  #include <stdlib.h>
  50   50  #define BLOWFISH_ASSERT(x)
  51   51  #endif /* _KERNEL */
  52   52  
  53   53  #if defined(__i386) || defined(__amd64)
  54   54  #include <sys/byteorder.h>
  55   55  #define UNALIGNED_POINTERS_PERMITTED
  56   56  #endif
  57   57  
  58      -/* EXPORT DELETE START */
  59      -
  60   58  /*
  61   59   * Blowfish initial P box and S boxes, derived from the hex digits of PI.
  62   60   *
  63   61   * NOTE:  S boxes are placed into one large array.
  64   62   */
  65   63  static const uint32_t init_P[] = {
  66   64          0x243f6a88U, 0x85a308d3U, 0x13198a2eU,
  67   65          0x03707344U, 0xa4093822U, 0x299f31d0U,
  68   66          0x082efa98U, 0xec4e6c89U, 0x452821e6U,
  69   67          0x38d01377U, 0xbe5466cfU, 0x34e90c6cU,
↓ open down ↓ 290 lines elided ↑ open up ↑
 360  358          (((S[(word >> 24) & 0xff] + S[256 + ((word >> 16) & 0xff)]) ^ \
 361  359                  S[512 + ((word >> 8) & 0xff)]) + S[768 + (word & 0xff)])
 362  360  
 363  361  #define ROUND(left, right, i) \
 364  362          (left) ^= P[i]; \
 365  363          (right) ^= F((left)); \
 366  364          tmp = (left); \
 367  365          (left) = (right); \
 368  366          (right) = tmp;
 369  367  
 370      -/* EXPORT DELETE END */
 371      -
 372  368  /*
 373  369   * Encrypt a block of data.  Because of addition operations, convert blocks
 374  370   * to their big-endian representation, even on Intel boxen.
 375  371   */
 376  372  /* ARGSUSED */
 377  373  int
 378  374  blowfish_encrypt_block(const void *cookie, const uint8_t *block,
 379  375      uint8_t *out_block)
 380  376  {
 381      -/* EXPORT DELETE START */
 382  377          keysched_t *ksch = (keysched_t *)cookie;
 383  378  
 384  379          uint32_t left, right, tmp;
 385  380          uint32_t *P = ksch->ksch_P;
 386  381          uint32_t *S = ksch->ksch_S;
 387  382  #ifdef _BIG_ENDIAN
 388  383          uint32_t *b32;
 389  384  
 390  385          if (IS_P2ALIGNED(block, sizeof (uint32_t))) {
 391  386                  /* LINTED:  pointer alignment */
↓ open down ↓ 61 lines elided ↑ open up ↑
 453  448                  out_block[0] = left >> 24;
 454  449                  out_block[1] = left >> 16;
 455  450                  out_block[2] = left >> 8;
 456  451                  out_block[3] = left;
 457  452                  out_block[4] = right >> 24;
 458  453                  out_block[5] = right >> 16;
 459  454                  out_block[6] = right >> 8;
 460  455                  out_block[7] = right;
 461  456  #endif  /* UNALIGNED_POINTERS_PERMITTED */
 462  457          }
 463      -/* EXPORT DELETE END */
 464  458          return (CRYPTO_SUCCESS);
 465  459  }
 466  460  
 467  461  /*
 468  462   * Decrypt a block of data.  Because of addition operations, convert blocks
 469  463   * to their big-endian representation, even on Intel boxen.
 470  464   * It should look like the blowfish_encrypt_block() operation
 471  465   * except for the order in which the S/P boxes are accessed.
 472  466   */
 473  467  /* ARGSUSED */
 474  468  int
 475  469  blowfish_decrypt_block(const void *cookie, const uint8_t *block,
 476  470      uint8_t *out_block)
 477  471  {
 478      -/* EXPORT DELETE START */
 479  472          keysched_t *ksch = (keysched_t *)cookie;
 480  473  
 481  474          uint32_t left, right, tmp;
 482  475          uint32_t *P = ksch->ksch_P;
 483  476          uint32_t *S = ksch->ksch_S;
 484  477  #ifdef _BIG_ENDIAN
 485  478          uint32_t *b32;
 486  479  
 487  480          if (IS_P2ALIGNED(block, sizeof (uint32_t))) {
 488  481                  /* LINTED:  pointer alignment */
↓ open down ↓ 61 lines elided ↑ open up ↑
 550  543                  out_block[0] = left >> 24;
 551  544                  out_block[1] = left >> 16;
 552  545                  out_block[2] = left >> 8;
 553  546                  out_block[3] = left;
 554  547                  out_block[4] = right >> 24;
 555  548                  out_block[5] = right >> 16;
 556  549                  out_block[6] = right >> 8;
 557  550                  out_block[7] = right;
 558  551  #endif  /* UNALIGNED_POINTERS_PERMITTED */
 559  552          }
 560      -/* EXPORT DELETE END */
 561  553          return (CRYPTO_SUCCESS);
 562  554  }
 563  555  
 564  556  static void
 565  557  bitrepeat(uint8_t *pattern, uint_t len_bytes, uint_t len_bits, uint8_t *dst,
 566  558      uint_t dst_len_bytes)
 567  559  {
 568      -/* EXPORT DELETE START */
 569  560          uint8_t *current = dst;
 570  561          uint_t bitsleft = CRYPTO_BYTES2BITS(dst_len_bytes);
 571  562          uint_t bitoffset = 0;
 572  563          uint_t currentbits;
 573  564          int i;
 574  565  
 575  566          BLOWFISH_ASSERT(CRYPTO_BITS2BYTES(len_bits) == len_bytes);
 576  567  
 577  568          bzero(dst, dst_len_bytes);
 578  569  
↓ open down ↓ 31 lines elided ↑ open up ↑
 610  601                                          bitoffset = bitoffset + currentbits;
 611  602                                          bitoffset &= 0x7;
 612  603                                          if (bitoffset == 0)
 613  604                                                  current++;
 614  605                                          currentbits = 0;
 615  606                                  }
 616  607                          }
 617  608                          bitsleft = 0;
 618  609                  }
 619  610          }
 620      -/* EXPORT DELETE END */
 621  611  }
 622  612  
 623  613  /*
 624  614   * Initialize key schedules for Blowfish.
 625  615   */
 626  616  void
 627  617  blowfish_init_keysched(uint8_t *key, uint_t bits, void *keysched)
 628  618  {
 629      -/* EXPORT DELETE START */
 630  619          keysched_t *newbie = keysched;
 631  620          uint32_t *P = newbie->ksch_P;
 632  621          uint32_t *S = newbie->ksch_S;
 633  622          uint32_t *initp;
 634  623          uint32_t tmpblock[] = {0, 0};
 635  624          uint8_t *rawkeybytes = (uint8_t *)P;
 636  625          int i, slop, copylen;
 637  626          uintptr_t bytesleft;
 638  627          uint_t len;
 639  628  
↓ open down ↓ 38 lines elided ↑ open up ↑
 678  667                  *initp++ = ntohl(tmpblock[1]);
 679  668          }
 680  669  
 681  670          initp = S;
 682  671          for (i = 0; i < 512; i++) {
 683  672                  (void) blowfish_encrypt_block(newbie, (uint8_t *)tmpblock,
 684  673                      (uint8_t *)tmpblock);
 685  674                  *initp++ = ntohl(tmpblock[0]);
 686  675                  *initp++ = ntohl(tmpblock[1]);
 687  676          }
 688      -/* EXPORT DELETE END */
 689  677  }
 690  678  
 691  679  /*
 692  680   * Allocate key schedule for Blowfish.
 693  681   */
 694  682  /* ARGSUSED */
 695  683  void *
 696  684  blowfish_alloc_keysched(size_t *size, int kmflag)
 697  685  {
 698      -/* EXPORT DELETE START */
 699  686          keysched_t *keysched;
 700  687  
 701  688  #ifdef _KERNEL
 702  689          keysched = (keysched_t *)kmem_alloc(sizeof (keysched_t), kmflag);
 703  690  #else
 704  691          keysched = (keysched_t *)malloc(sizeof (keysched_t));
 705  692  #endif /* _KERNEL */
 706  693          if (keysched != NULL) {
 707  694                  *size = sizeof (keysched_t);
 708  695                  return (keysched);
 709  696          }
 710      -/* EXPORT DELETE END */
 711  697  
 712  698          return (NULL);
 713  699  }
 714  700  
 715  701  void
 716  702  blowfish_copy_block(uint8_t *in, uint8_t *out)
 717  703  {
 718  704          if (IS_P2ALIGNED(in, sizeof (uint32_t)) &&
 719  705              IS_P2ALIGNED(out, sizeof (uint32_t))) {
 720  706                  /* LINTED: pointer alignment */
↓ open down ↓ 66 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX