2
0

rmd_local.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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/ripemd.h>
  13. /*
  14. * DO EXAMINE COMMENTS IN crypto/md5/md5_local.h & crypto/md5/md5_dgst.c
  15. * FOR EXPLANATIONS ON FOLLOWING "CODE."
  16. */
  17. #ifdef RMD160_ASM
  18. # if defined(__i386) || defined(__i386__) || defined(_M_IX86)
  19. # define ripemd160_block_data_order ripemd160_block_asm_data_order
  20. # endif
  21. #endif
  22. void ripemd160_block_data_order(RIPEMD160_CTX *c, const void *p, size_t num);
  23. #define DATA_ORDER_IS_LITTLE_ENDIAN
  24. #define HASH_LONG RIPEMD160_LONG
  25. #define HASH_CTX RIPEMD160_CTX
  26. #define HASH_CBLOCK RIPEMD160_CBLOCK
  27. #define HASH_UPDATE RIPEMD160_Update
  28. #define HASH_TRANSFORM RIPEMD160_Transform
  29. #define HASH_FINAL RIPEMD160_Final
  30. #define HASH_MAKE_STRING(c,s) do { \
  31. unsigned long ll; \
  32. ll=(c)->A; (void)HOST_l2c(ll,(s)); \
  33. ll=(c)->B; (void)HOST_l2c(ll,(s)); \
  34. ll=(c)->C; (void)HOST_l2c(ll,(s)); \
  35. ll=(c)->D; (void)HOST_l2c(ll,(s)); \
  36. ll=(c)->E; (void)HOST_l2c(ll,(s)); \
  37. } while (0)
  38. #define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
  39. #include "crypto/md32_common.h"
  40. /*
  41. * Transformed F2 and F4 are courtesy of Wei Dai
  42. */
  43. #define F1(x,y,z) ((x) ^ (y) ^ (z))
  44. #define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
  45. #define F3(x,y,z) (((~(y)) | (x)) ^ (z))
  46. #define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
  47. #define F5(x,y,z) (((~(z)) | (y)) ^ (x))
  48. #define RIPEMD160_A 0x67452301L
  49. #define RIPEMD160_B 0xEFCDAB89L
  50. #define RIPEMD160_C 0x98BADCFEL
  51. #define RIPEMD160_D 0x10325476L
  52. #define RIPEMD160_E 0xC3D2E1F0L
  53. #include "rmdconst.h"
  54. #define RIP1(a,b,c,d,e,w,s) { \
  55. a+=F1(b,c,d)+X(w); \
  56. a=ROTATE(a,s)+e; \
  57. c=ROTATE(c,10); }
  58. #define RIP2(a,b,c,d,e,w,s,K) { \
  59. a+=F2(b,c,d)+X(w)+K; \
  60. a=ROTATE(a,s)+e; \
  61. c=ROTATE(c,10); }
  62. #define RIP3(a,b,c,d,e,w,s,K) { \
  63. a+=F3(b,c,d)+X(w)+K; \
  64. a=ROTATE(a,s)+e; \
  65. c=ROTATE(c,10); }
  66. #define RIP4(a,b,c,d,e,w,s,K) { \
  67. a+=F4(b,c,d)+X(w)+K; \
  68. a=ROTATE(a,s)+e; \
  69. c=ROTATE(c,10); }
  70. #define RIP5(a,b,c,d,e,w,s,K) { \
  71. a+=F5(b,c,d)+X(w)+K; \
  72. a=ROTATE(a,s)+e; \
  73. c=ROTATE(c,10); }