Print this page
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64 (fix lint)

Split Close
Expand all
Collapse all
          --- old/usr/src/common/crypto/des/des_impl.c
          +++ new/usr/src/common/crypto/des/des_impl.c
↓ open down ↓ 526 lines elided ↑ open up ↑
 527  527                          /* LINTED */
 528  528                          *(uint64_t *)out_block = des_crypt_impl(
 529  529                              ksch->ksch_encrypt, /* LINTED */
 530  530                              *(uint64_t *)block, 3);
 531  531          } else
 532  532  #endif  /* _BIG_ENDIAN */
 533  533          {
 534  534                  uint64_t tmp;
 535  535  
 536  536  #ifdef UNALIGNED_POINTERS_PERMITTED
 537      -                tmp = htonll(*(uint64_t *)&block[0]);
      537 +                tmp = htonll(*(uint64_t *)(void *)&block[0]);
 538  538  #else
 539  539                  tmp = (((uint64_t)block[0] << 56) | ((uint64_t)block[1] << 48) |
 540  540                      ((uint64_t)block[2] << 40) | ((uint64_t)block[3] << 32) |
 541  541                      ((uint64_t)block[4] << 24) | ((uint64_t)block[5] << 16) |
 542  542                      ((uint64_t)block[6] << 8) | (uint64_t)block[7]);
 543  543  #endif  /* UNALIGNED_POINTERS_PERMITTED */
 544  544  
 545  545                  if (decrypt == B_TRUE)
 546  546                          tmp = des_crypt_impl(ksch->ksch_decrypt, tmp, 3);
 547  547                  else
 548  548                          tmp = des_crypt_impl(ksch->ksch_encrypt, tmp, 3);
 549  549  
 550  550  #ifdef UNALIGNED_POINTERS_PERMITTED
 551      -                *(uint64_t *)&out_block[0] = htonll(tmp);
      551 +                *(uint64_t *)(void *)&out_block[0] = htonll(tmp);
 552  552  #else
 553  553                  out_block[0] = tmp >> 56;
 554  554                  out_block[1] = tmp >> 48;
 555  555                  out_block[2] = tmp >> 40;
 556  556                  out_block[3] = tmp >> 32;
 557  557                  out_block[4] = tmp >> 24;
 558  558                  out_block[5] = tmp >> 16;
 559  559                  out_block[6] = tmp >> 8;
 560  560                  out_block[7] = (uint8_t)tmp;
 561  561  #endif  /* UNALIGNED_POINTERS_PERMITTED */
↓ open down ↓ 27 lines elided ↑ open up ↑
 589  589                          *(uint64_t *)out_block = des_crypt_impl(
 590  590                              ksch->ksch_encrypt, /* LINTED */
 591  591                              *(uint64_t *)block, 1);
 592  592  
 593  593          } else
 594  594  #endif  /* _BIG_ENDIAN */
 595  595          {
 596  596                  uint64_t tmp;
 597  597  
 598  598  #ifdef UNALIGNED_POINTERS_PERMITTED
 599      -                tmp = htonll(*(uint64_t *)&block[0]);
      599 +                tmp = htonll(*(uint64_t *)(void *)&block[0]);
 600  600  #else
 601  601                  tmp = (((uint64_t)block[0] << 56) | ((uint64_t)block[1] << 48) |
 602  602                      ((uint64_t)block[2] << 40) | ((uint64_t)block[3] << 32) |
 603  603                      ((uint64_t)block[4] << 24) | ((uint64_t)block[5] << 16) |
 604  604                      ((uint64_t)block[6] << 8) | (uint64_t)block[7]);
 605  605  #endif  /* UNALIGNED_POINTERS_PERMITTED */
 606  606  
 607  607  
 608  608                  if (decrypt == B_TRUE)
 609  609                          tmp = des_crypt_impl(ksch->ksch_decrypt, tmp, 1);
 610  610                  else
 611  611                          tmp = des_crypt_impl(ksch->ksch_encrypt, tmp, 1);
 612  612  
 613  613  #ifdef UNALIGNED_POINTERS_PERMITTED
 614      -                *(uint64_t *)&out_block[0] = htonll(tmp);
      614 +                *(uint64_t *)(void *)&out_block[0] = htonll(tmp);
 615  615  #else
 616  616                  out_block[0] = tmp >> 56;
 617  617                  out_block[1] = tmp >> 48;
 618  618                  out_block[2] = tmp >> 40;
 619  619                  out_block[3] = tmp >> 32;
 620  620                  out_block[4] = tmp >> 24;
 621  621                  out_block[5] = tmp >> 16;
 622  622                  out_block[6] = tmp >> 8;
 623  623                  out_block[7] = (uint8_t)tmp;
 624  624  #endif  /* UNALIGNED_POINTERS_PERMITTED */
↓ open down ↓ 41 lines elided ↑ open up ↑
 666  666                  0xe0fee0fef1fef1feULL,  0xfee0fee0fef1fef1ULL,
 667  667  #endif  /* _LITTLE_ENDIAN */
 668  668  
 669  669                  /* We'll save the other possibly-weak keys for the future. */
 670  670          };
 671  671  
 672  672          if (key == NULL)
 673  673                  return (B_FALSE);
 674  674  
 675  675  #ifdef UNALIGNED_POINTERS_PERMITTED
 676      -        key_so_far = htonll(*(uint64_t *)&key[0]);
      676 +        key_so_far = htonll(*(uint64_t *)(void *)&key[0]);
 677  677  #else
 678  678          /*
 679  679           * The code below reverses the bytes on LITTLE_ENDIAN machines.
 680  680           * On BIG_ENDIAN, the same code copies without reversing
 681  681           * the bytes.
 682  682           */
 683  683          key_so_far = (((uint64_t)key[0] << 56) | ((uint64_t)key[1] << 48) |
 684  684              ((uint64_t)key[2] << 40) | ((uint64_t)key[3] << 32) |
 685  685              ((uint64_t)key[4] << 24) | ((uint64_t)key[5] << 16) |
 686  686              ((uint64_t)key[6] << 8) | (uint64_t)key[7]);
↓ open down ↓ 5 lines elided ↑ open up ↑
 692  692          fix_des_parity(&key_so_far);
 693  693  
 694  694          /* Do weak key check itself. */
 695  695          for (i = 0; i < (sizeof (des_weak_keys) / sizeof (uint64_t)); i++)
 696  696                  if (key_so_far == des_weak_keys[i]) {
 697  697                          return (B_FALSE);
 698  698                  }
 699  699  
 700  700          if (corrected_key != NULL) {
 701  701  #ifdef UNALIGNED_POINTERS_PERMITTED
 702      -                *(uint64_t *)&corrected_key[0] = htonll(key_so_far);
      702 +                *(uint64_t *)(void *)&corrected_key[0] = htonll(key_so_far);
 703  703  #else
 704  704                  /*
 705  705                   * The code below reverses the bytes on LITTLE_ENDIAN machines.
 706  706                   * On BIG_ENDIAN, the same code copies without reversing
 707  707                   * the bytes.
 708  708                   */
 709  709                  corrected_key[0] = key_so_far >> 56;
 710  710                  corrected_key[1] = key_so_far >> 48;
 711  711                  corrected_key[2] = key_so_far >> 40;
 712  712                  corrected_key[3] = key_so_far >> 32;
↓ open down ↓ 88 lines elided ↑ open up ↑
 801  801  
 802  802          if (strength == DES)
 803  803                  bcopy(key, aligned_key, DES_KEYSIZE);
 804  804          else
 805  805                  bcopy(key, aligned_key, DES3_KEYSIZE);
 806  806  
 807  807          paritied_key = (uint8_t *)aligned_key;
 808  808          while (strength > i) {
 809  809                  offset = 8 * i;
 810  810  #ifdef UNALIGNED_POINTERS_PERMITTED
 811      -                key_so_far = htonll(*(uint64_t *)&paritied_key[offset]);
      811 +                key_so_far = htonll(*(uint64_t *)(void *)&paritied_key[offset]);
 812  812  #else
 813  813                  key_so_far = (((uint64_t)paritied_key[offset + 0] << 56) |
 814  814                      ((uint64_t)paritied_key[offset + 1] << 48) |
 815  815                      ((uint64_t)paritied_key[offset + 2] << 40) |
 816  816                      ((uint64_t)paritied_key[offset + 3] << 32) |
 817  817                      ((uint64_t)paritied_key[offset + 4] << 24) |
 818  818                      ((uint64_t)paritied_key[offset + 5] << 16) |
 819  819                      ((uint64_t)paritied_key[offset + 6] << 8) |
 820  820                      (uint64_t)paritied_key[offset + 7]);
 821  821  #endif  /* UNALIGNED_POINTERS_PERMITTED */
 822  822  
 823  823                  fix_des_parity(&key_so_far);
 824  824  
 825  825  #ifdef UNALIGNED_POINTERS_PERMITTED
 826      -                *(uint64_t *)&paritied_key[offset] = htonll(key_so_far);
      826 +                *(uint64_t *)(void *)&paritied_key[offset] = htonll(key_so_far);
 827  827  #else
 828  828                  paritied_key[offset + 0] = key_so_far >> 56;
 829  829                  paritied_key[offset + 1] = key_so_far >> 48;
 830  830                  paritied_key[offset + 2] = key_so_far >> 40;
 831  831                  paritied_key[offset + 3] = key_so_far >> 32;
 832  832                  paritied_key[offset + 4] = key_so_far >> 24;
 833  833                  paritied_key[offset + 5] = key_so_far >> 16;
 834  834                  paritied_key[offset + 6] = key_so_far >> 8;
 835  835                  paritied_key[offset + 7] = (uint8_t)key_so_far;
 836  836  #endif  /* UNALIGNED_POINTERS_PERMITTED */
↓ open down ↓ 46 lines elided ↑ open up ↑
 883  883          if (IS_P2ALIGNED(cipherKey, sizeof (uint64_t))) {
 884  884                  for (i = 0, j = 0; j < keysize; i++, j += 8) {
 885  885                          /* LINTED: pointer alignment */
 886  886                          key_uint64[i] = *((uint64_t *)&cipherKey[j]);
 887  887                  }
 888  888          } else
 889  889  #endif  /* _BIG_ENDIAN */
 890  890          {
 891  891                  for (i = 0, j = 0; j < keysize; i++, j += 8) {
 892  892  #ifdef UNALIGNED_POINTERS_PERMITTED
 893      -                        key_uint64[i] = htonll(*(uint64_t *)&cipherKey[j]);
      893 +                        key_uint64[i] =
      894 +                            htonll(*(uint64_t *)(void *)&cipherKey[j]);
 894  895  #else
 895  896                          key_uint64[i] = (((uint64_t)cipherKey[j] << 56) |
 896  897                              ((uint64_t)cipherKey[j + 1] << 48) |
 897  898                              ((uint64_t)cipherKey[j + 2] << 40) |
 898  899                              ((uint64_t)cipherKey[j + 3] << 32) |
 899  900                              ((uint64_t)cipherKey[j + 4] << 24) |
 900  901                              ((uint64_t)cipherKey[j + 5] << 16) |
 901  902                              ((uint64_t)cipherKey[j + 6] << 8) |
 902  903                              (uint64_t)cipherKey[j + 7]);
 903  904  #endif  /* UNALIGNED_POINTERS_PERMITTED */
↓ open down ↓ 220 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX