md5_local.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 1995-2022 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) || \
  16. defined(_M_X64) || defined(__aarch64__)
  17. # define md5_block_data_order ossl_md5_block_asm_data_order
  18. # elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
  19. # define md5_block_data_order ossl_md5_block_asm_data_order
  20. # elif defined(__sparc) || defined(__sparc__)
  21. # define md5_block_data_order ossl_md5_block_asm_data_order
  22. # endif
  23. #endif
  24. void md5_block_data_order(MD5_CTX *c, const void *p, size_t num);
  25. #define DATA_ORDER_IS_LITTLE_ENDIAN
  26. #define HASH_LONG MD5_LONG
  27. #define HASH_CTX MD5_CTX
  28. #define HASH_CBLOCK MD5_CBLOCK
  29. #define HASH_UPDATE MD5_Update
  30. #define HASH_TRANSFORM MD5_Transform
  31. #define HASH_FINAL MD5_Final
  32. #define HASH_MAKE_STRING(c,s) do { \
  33. unsigned long ll; \
  34. ll=(c)->A; (void)HOST_l2c(ll,(s)); \
  35. ll=(c)->B; (void)HOST_l2c(ll,(s)); \
  36. ll=(c)->C; (void)HOST_l2c(ll,(s)); \
  37. ll=(c)->D; (void)HOST_l2c(ll,(s)); \
  38. } while (0)
  39. #define HASH_BLOCK_DATA_ORDER md5_block_data_order
  40. #include "crypto/md32_common.h"
  41. /*-
  42. #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
  43. #define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
  44. */
  45. /*
  46. * As pointed out by Wei Dai, the above can be simplified to the code
  47. * below. Wei attributes these optimizations to Peter Gutmann's
  48. * SHS code, and he attributes it to Rich Schroeppel.
  49. */
  50. #define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
  51. #define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
  52. #define H(b,c,d) ((b) ^ (c) ^ (d))
  53. #define I(b,c,d) (((~(d)) | (b)) ^ (c))
  54. #define R0(a,b,c,d,k,s,t) { \
  55. a+=((k)+(t)+F((b),(c),(d))); \
  56. a=ROTATE(a,s); \
  57. a+=b; };
  58. #define R1(a,b,c,d,k,s,t) { \
  59. a+=((k)+(t)+G((b),(c),(d))); \
  60. a=ROTATE(a,s); \
  61. a+=b; };
  62. #define R2(a,b,c,d,k,s,t) { \
  63. a+=((k)+(t)+H((b),(c),(d))); \
  64. a=ROTATE(a,s); \
  65. a+=b; };
  66. #define R3(a,b,c,d,k,s,t) { \
  67. a+=((k)+(t)+I((b),(c),(d))); \
  68. a=ROTATE(a,s); \
  69. a+=b; };