md5_locl.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <openssl/e_os2.h>
  12. #include <openssl/md5.h>
  13. #ifdef MD5_ASM
  14. # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
  15. defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
  16. # define md5_block_data_order md5_block_asm_data_order
  17. # elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
  18. # define md5_block_data_order md5_block_asm_data_order
  19. # elif defined(__sparc) || defined(__sparc__)
  20. # define md5_block_data_order md5_block_asm_data_order
  21. # endif
  22. #endif
  23. void md5_block_data_order(MD5_CTX *c, const void *p, size_t num);
  24. #define DATA_ORDER_IS_LITTLE_ENDIAN
  25. #define HASH_LONG MD5_LONG
  26. #define HASH_CTX MD5_CTX
  27. #define HASH_CBLOCK MD5_CBLOCK
  28. #define HASH_UPDATE MD5_Update
  29. #define HASH_TRANSFORM MD5_Transform
  30. #define HASH_FINAL MD5_Final
  31. #define HASH_MAKE_STRING(c,s) do { \
  32. unsigned long ll; \
  33. ll=(c)->A; (void)HOST_l2c(ll,(s)); \
  34. ll=(c)->B; (void)HOST_l2c(ll,(s)); \
  35. ll=(c)->C; (void)HOST_l2c(ll,(s)); \
  36. ll=(c)->D; (void)HOST_l2c(ll,(s)); \
  37. } while (0)
  38. #define HASH_BLOCK_DATA_ORDER md5_block_data_order
  39. #include "internal/md32_common.h"
  40. /*-
  41. #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
  42. #define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
  43. */
  44. /*
  45. * As pointed out by Wei Dai, the above can be simplified to the code
  46. * below. Wei attributes these optimizations to Peter Gutmann's
  47. * SHS code, and he attributes it to Rich Schroeppel.
  48. */
  49. #define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
  50. #define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
  51. #define H(b,c,d) ((b) ^ (c) ^ (d))
  52. #define I(b,c,d) (((~(d)) | (b)) ^ (c))
  53. #define R0(a,b,c,d,k,s,t) { \
  54. a+=((k)+(t)+F((b),(c),(d))); \
  55. a=ROTATE(a,s); \
  56. a+=b; };\
  57. #define R1(a,b,c,d,k,s,t) { \
  58. a+=((k)+(t)+G((b),(c),(d))); \
  59. a=ROTATE(a,s); \
  60. a+=b; };
  61. #define R2(a,b,c,d,k,s,t) { \
  62. a+=((k)+(t)+H((b),(c),(d))); \
  63. a=ROTATE(a,s); \
  64. a+=b; };
  65. #define R3(a,b,c,d,k,s,t) { \
  66. a+=((k)+(t)+I((b),(c),(d))); \
  67. a=ROTATE(a,s); \
  68. a+=b; };