md5_local.h 2.6 KB

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