Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474

Split Close
Expand all
Collapse all
          --- old/usr/src/common/crypto/md4/md4.c
          +++ new/usr/src/common/crypto/md4/md4.c
   1    1  /*
   2      - * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
        2 + * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
   3    3   * Use is subject to license terms.
   4    4   */
   5    5  
   6      -#pragma ident   "%Z%%M% %I%     %E% SMI"
   7      -
   8    6  /*
   9    7   * MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
  10    8   */
  11    9  
  12   10  /*
  13   11   * Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
  14   12   *
  15   13   * License to copy and use this software is granted provided that it
  16   14   * is identified as the "RSA Data Security, Inc. MD4 Message-Digest
  17   15   * Algorithm" in all material mentioning or referencing this software
↓ open down ↓ 13 lines elided ↑ open up ↑
  31   29   * documentation and/or software.
  32   30   */
  33   31  
  34   32  #include <sys/types.h>
  35   33  #ifdef _KERNEL
  36   34  #include <sys/sunddi.h>
  37   35  #else
  38   36  #include <strings.h>
  39   37  #endif /* _KERNEL */
  40   38  
       39 +#if defined(__i386) || defined(__amd64)
       40 +#define UNALIGNED_POINTERS_PERMITTED
       41 +#endif
       42 +
  41   43  #include <sys/md4.h>
  42   44  
  43   45  /*
  44   46   * Constants for MD4Transform routine.
  45   47   */
  46   48  #define S11 3
  47   49  #define S12 7
  48   50  #define S13 11
  49   51  #define S14 19
  50   52  #define S21 3
↓ open down ↓ 204 lines elided ↑ open up ↑
 255  257  
 256  258          /* zeroize sensitive information */
 257  259          bzero(x, sizeof (*x));
 258  260  }
 259  261  
 260  262  /*
 261  263   * Encodes input (uint32_t) into output (unsigned char). Assumes len is
 262  264   * a multiple of 4.
 263  265   */
 264  266  static void
 265      -Encode(output, input, len)
 266      -        unsigned char *output;
 267      -        uint32_t *input;
 268      -        unsigned int len;
      267 +Encode(unsigned char *output, uint32_t *input, unsigned int len)
 269  268  {
 270  269          unsigned int i, j;
 271  270  
 272  271          for (i = 0, j = 0; j < len; i++, j += 4) {
      272 +#if defined(_LITTLE_ENDIAN) && defined(UNALIGNED_POINTERS_PERMITTED)
      273 +                *(uint32_t *)&output[j] = input[i];
      274 +#else
      275 +                /* endian-independent code */
 273  276                  output[j] = (unsigned char)(input[i] & 0xff);
 274  277                  output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
 275  278                  output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
 276  279                  output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
      280 +#endif  /* _LITTLE_ENDIAN && UNALIGNED_POINTERS_PERMITTED */
 277  281          }
 278  282  }
 279  283  
 280  284  /*
 281  285   * Decodes input (unsigned char) into output (uint32_t). Assumes len is
 282  286   * a multiple of 4.
 283  287   */
 284  288  static void
 285      -Decode(output, input, len)
 286      -        uint32_t *output;
 287      -        unsigned char *input;
 288      -        unsigned int len;
      289 +Decode(uint32_t *output, unsigned char *input, unsigned int len)
 289  290  {
 290  291          unsigned int i, j;
 291  292  
 292      -        for (i = 0, j = 0; j < len; i++, j += 4)
      293 +        for (i = 0, j = 0; j < len; i++, j += 4) {
      294 +#if defined(_LITTLE_ENDIAN) && defined(UNALIGNED_POINTERS_PERMITTED)
      295 +                output[i] = *(uint32_t *)&input[j];
      296 +#else
      297 +                /* endian-independent code */
 293  298                  output[i] = ((uint32_t)input[j]) |
 294      -                        (((uint32_t)input[j+1]) << 8) |
 295      -                        (((uint32_t)input[j+2]) << 16) |
 296      -                        (((uint32_t)input[j+3]) << 24);
      299 +                    (((uint32_t)input[j+1]) << 8) |
      300 +                    (((uint32_t)input[j+2]) << 16) |
      301 +                    (((uint32_t)input[j+3]) << 24);
      302 +#endif  /* _LITTLE_ENDIAN && UNALIGNED_POINTERS_PERMITTED */
      303 +        }
      304 +
 297  305  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX