md4_local.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/opensslconf.h>
  12. #include <openssl/md4.h>
  13. void md4_block_data_order(MD4_CTX *c, const void *p, size_t num);
  14. #define DATA_ORDER_IS_LITTLE_ENDIAN
  15. #define HASH_LONG MD4_LONG
  16. #define HASH_CTX MD4_CTX
  17. #define HASH_CBLOCK MD4_CBLOCK
  18. #define HASH_UPDATE MD4_Update
  19. #define HASH_TRANSFORM MD4_Transform
  20. #define HASH_FINAL MD4_Final
  21. #define HASH_MAKE_STRING(c,s) do { \
  22. unsigned long ll; \
  23. ll=(c)->A; (void)HOST_l2c(ll,(s)); \
  24. ll=(c)->B; (void)HOST_l2c(ll,(s)); \
  25. ll=(c)->C; (void)HOST_l2c(ll,(s)); \
  26. ll=(c)->D; (void)HOST_l2c(ll,(s)); \
  27. } while (0)
  28. #define HASH_BLOCK_DATA_ORDER md4_block_data_order
  29. #include "crypto/md32_common.h"
  30. /*-
  31. #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
  32. #define G(x,y,z) (((x) & (y)) | ((x) & ((z))) | ((y) & ((z))))
  33. */
  34. /*
  35. * As pointed out by Wei Dai, the above can be simplified to the code
  36. * below. Wei attributes these optimizations to Peter Gutmann's SHS code,
  37. * and he attributes it to Rich Schroeppel.
  38. */
  39. #define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
  40. #define G(b,c,d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
  41. #define H(b,c,d) ((b) ^ (c) ^ (d))
  42. #define R0(a,b,c,d,k,s,t) { \
  43. a+=((k)+(t)+F((b),(c),(d))); \
  44. a=ROTATE(a,s); };
  45. #define R1(a,b,c,d,k,s,t) { \
  46. a+=((k)+(t)+G((b),(c),(d))); \
  47. a=ROTATE(a,s); };
  48. #define R2(a,b,c,d,k,s,t) { \
  49. a+=((k)+(t)+H((b),(c),(d))); \
  50. a=ROTATE(a,s); };