rc2_locl.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #undef c2l
  10. #define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
  11. l|=((unsigned long)(*((c)++)))<< 8L, \
  12. l|=((unsigned long)(*((c)++)))<<16L, \
  13. l|=((unsigned long)(*((c)++)))<<24L)
  14. /* NOTE - c is not incremented as per c2l */
  15. #undef c2ln
  16. #define c2ln(c,l1,l2,n) { \
  17. c+=n; \
  18. l1=l2=0; \
  19. switch (n) { \
  20. case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
  21. case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
  22. case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
  23. case 5: l2|=((unsigned long)(*(--(c)))); \
  24. case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
  25. case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
  26. case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
  27. case 1: l1|=((unsigned long)(*(--(c)))); \
  28. } \
  29. }
  30. #undef l2c
  31. #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
  32. *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
  33. *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
  34. *((c)++)=(unsigned char)(((l)>>24L)&0xff))
  35. /* NOTE - c is not incremented as per l2c */
  36. #undef l2cn
  37. #define l2cn(l1,l2,c,n) { \
  38. c+=n; \
  39. switch (n) { \
  40. case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
  41. case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
  42. case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
  43. case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
  44. case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
  45. case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
  46. case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
  47. case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
  48. } \
  49. }
  50. /* NOTE - c is not incremented as per n2l */
  51. #define n2ln(c,l1,l2,n) { \
  52. c+=n; \
  53. l1=l2=0; \
  54. switch (n) { \
  55. case 8: l2 =((unsigned long)(*(--(c)))) ; \
  56. case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
  57. case 6: l2|=((unsigned long)(*(--(c))))<<16; \
  58. case 5: l2|=((unsigned long)(*(--(c))))<<24; \
  59. case 4: l1 =((unsigned long)(*(--(c)))) ; \
  60. case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
  61. case 2: l1|=((unsigned long)(*(--(c))))<<16; \
  62. case 1: l1|=((unsigned long)(*(--(c))))<<24; \
  63. } \
  64. }
  65. /* NOTE - c is not incremented as per l2n */
  66. #define l2nn(l1,l2,c,n) { \
  67. c+=n; \
  68. switch (n) { \
  69. case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
  70. case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
  71. case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
  72. case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
  73. case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
  74. case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
  75. case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
  76. case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
  77. } \
  78. }
  79. #undef n2l
  80. #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
  81. l|=((unsigned long)(*((c)++)))<<16L, \
  82. l|=((unsigned long)(*((c)++)))<< 8L, \
  83. l|=((unsigned long)(*((c)++))))
  84. #undef l2n
  85. #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
  86. *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
  87. *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
  88. *((c)++)=(unsigned char)(((l) )&0xff))
  89. #define C_RC2(n) \
  90. t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \
  91. x0=(t<<1)|(t>>15); \
  92. t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \
  93. x1=(t<<2)|(t>>14); \
  94. t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \
  95. x2=(t<<3)|(t>>13); \
  96. t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \
  97. x3=(t<<5)|(t>>11);