rc2_local.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #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. /* fall thru */ \
  22. case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
  23. /* fall thru */ \
  24. case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
  25. /* fall thru */ \
  26. case 5: l2|=((unsigned long)(*(--(c)))); \
  27. /* fall thru */ \
  28. case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
  29. /* fall thru */ \
  30. case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
  31. /* fall thru */ \
  32. case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
  33. /* fall thru */ \
  34. case 1: l1|=((unsigned long)(*(--(c)))); \
  35. } \
  36. }
  37. #undef l2c
  38. #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
  39. *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
  40. *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
  41. *((c)++)=(unsigned char)(((l)>>24L)&0xff))
  42. /* NOTE - c is not incremented as per l2c */
  43. #undef l2cn
  44. #define l2cn(l1,l2,c,n) { \
  45. c+=n; \
  46. switch (n) { \
  47. case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
  48. /* fall thru */ \
  49. case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
  50. /* fall thru */ \
  51. case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
  52. /* fall thru */ \
  53. case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
  54. /* fall thru */ \
  55. case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
  56. /* fall thru */ \
  57. case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
  58. /* fall thru */ \
  59. case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
  60. /* fall thru */ \
  61. case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
  62. } \
  63. }
  64. /* NOTE - c is not incremented as per n2l */
  65. #define n2ln(c,l1,l2,n) { \
  66. c+=n; \
  67. l1=l2=0; \
  68. switch (n) { \
  69. case 8: l2 =((unsigned long)(*(--(c)))) ; \
  70. /* fall thru */ \
  71. case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
  72. /* fall thru */ \
  73. case 6: l2|=((unsigned long)(*(--(c))))<<16; \
  74. /* fall thru */ \
  75. case 5: l2|=((unsigned long)(*(--(c))))<<24; \
  76. /* fall thru */ \
  77. case 4: l1 =((unsigned long)(*(--(c)))) ; \
  78. /* fall thru */ \
  79. case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
  80. /* fall thru */ \
  81. case 2: l1|=((unsigned long)(*(--(c))))<<16; \
  82. /* fall thru */ \
  83. case 1: l1|=((unsigned long)(*(--(c))))<<24; \
  84. } \
  85. }
  86. /* NOTE - c is not incremented as per l2n */
  87. #define l2nn(l1,l2,c,n) { \
  88. c+=n; \
  89. switch (n) { \
  90. case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
  91. /* fall thru */ \
  92. case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
  93. /* fall thru */ \
  94. case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
  95. /* fall thru */ \
  96. case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
  97. /* fall thru */ \
  98. case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
  99. /* fall thru */ \
  100. case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
  101. /* fall thru */ \
  102. case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
  103. /* fall thru */ \
  104. case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
  105. } \
  106. }
  107. #undef n2l
  108. #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
  109. l|=((unsigned long)(*((c)++)))<<16L, \
  110. l|=((unsigned long)(*((c)++)))<< 8L, \
  111. l|=((unsigned long)(*((c)++))))
  112. #undef l2n
  113. #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
  114. *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
  115. *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
  116. *((c)++)=(unsigned char)(((l) )&0xff))
  117. #define C_RC2(n) \
  118. t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \
  119. x0=(t<<1)|(t>>15); \
  120. t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \
  121. x1=(t<<2)|(t>>14); \
  122. t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \
  123. x2=(t<<3)|(t>>13); \
  124. t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \
  125. x3=(t<<5)|(t>>11);