PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/enctype_shared.c

https://gitlab.com/lheckemann/gslist
C | 181 lines | 139 code | 21 blank | 21 comment | 11 complexity | 07f109dbd9b0192e4e5578e84da3bfb9 MD5 | raw file
  1. /*
  2. Copyright 2005,2006,2007,2008 Luigi Auriemma
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. http://www.gnu.org/licenses/gpl.txt
  15. */
  16. void encshare2(unsigned int *tbuff, unsigned int *tbuffp, int len) {
  17. unsigned int t1,
  18. t2,
  19. t3,
  20. t4,
  21. t5,
  22. *limit,
  23. *p;
  24. t2 = tbuff[304];
  25. t1 = tbuff[305];
  26. t3 = tbuff[306];
  27. t5 = tbuff[307];
  28. limit = tbuffp + len;
  29. while(tbuffp < limit) {
  30. p = tbuff + t2 + 272;
  31. while(t5 < 65536) {
  32. t1 += t5;
  33. p++;
  34. t3 += t1;
  35. t1 += t3;
  36. p[-17] = t1;
  37. p[-1] = t3;
  38. t4 = (t3 << 24) | (t3 >> 8);
  39. p[15] = t5;
  40. t5 <<= 1;
  41. t2++;
  42. t1 ^= tbuff[t1 & 0xff];
  43. t4 ^= tbuff[t4 & 0xff];
  44. t3 = (t4 << 24) | (t4 >> 8);
  45. t4 = (t1 >> 24) | (t1 << 8);
  46. t4 ^= tbuff[t4 & 0xff];
  47. t3 ^= tbuff[t3 & 0xff];
  48. t1 = (t4 >> 24) | (t4 << 8);
  49. }
  50. t3 ^= t1;
  51. *tbuffp++ = t3;
  52. t2--;
  53. t1 = tbuff[t2 + 256];
  54. t5 = tbuff[t2 + 272];
  55. t1 = ~t1;
  56. t3 = (t1 << 24) | (t1 >> 8);
  57. t3 ^= tbuff[t3 & 0xff];
  58. t5 ^= tbuff[t5 & 0xff];
  59. t1 = (t3 << 24) | (t3 >> 8);
  60. t4 = (t5 >> 24) | (t5 << 8);
  61. t1 ^= tbuff[t1 & 0xff];
  62. t4 ^= tbuff[t4 & 0xff];
  63. t3 = (t4 >> 24) | (t4 << 8);
  64. t5 = (tbuff[t2 + 288] << 1) + 1;
  65. }
  66. tbuff[304] = t2;
  67. tbuff[305] = t1;
  68. tbuff[306] = t3;
  69. tbuff[307] = t5;
  70. }
  71. void encshare1(unsigned int *tbuff, unsigned char *datap, int len) {
  72. unsigned char *p,
  73. *s;
  74. p = s = (unsigned char *)(tbuff + 309);
  75. encshare2(tbuff, (unsigned int *)p, 16);
  76. while(len--) {
  77. if((p - s) == 63) {
  78. p = s;
  79. encshare2(tbuff, (unsigned int *)p, 16);
  80. }
  81. *datap ^= *p;
  82. datap++;
  83. p++;
  84. }
  85. }
  86. void encshare3(unsigned int *data, int n1, int n2) {
  87. unsigned int t1,
  88. t2,
  89. t3,
  90. t4;
  91. int i;
  92. t2 = n1;
  93. t1 = 0;
  94. t4 = 1;
  95. data[304] = 0;
  96. for(i = 32768; i; i >>= 1) {
  97. t2 += t4;
  98. t1 += t2;
  99. t2 += t1;
  100. if(n2 & i) {
  101. t2 = ~t2;
  102. t4 = (t4 << 1) + 1;
  103. t3 = (t2 << 24) | (t2 >> 8);
  104. t3 ^= data[t3 & 0xff];
  105. t1 ^= data[t1 & 0xff];
  106. t2 = (t3 << 24) | (t3 >> 8);
  107. t3 = (t1 >> 24) | (t1 << 8);
  108. t2 ^= data[t2 & 0xff];
  109. t3 ^= data[t3 & 0xff];
  110. t1 = (t3 >> 24) | (t3 << 8);
  111. } else {
  112. data[data[304] + 256] = t2;
  113. data[data[304] + 272] = t1;
  114. data[data[304] + 288] = t4;
  115. data[304]++;
  116. t3 = (t1 << 24) | (t1 >> 8);
  117. t2 ^= data[t2 & 0xff];
  118. t3 ^= data[t3 & 0xff];
  119. t1 = (t3 << 24) | (t3 >> 8);
  120. t3 = (t2 >> 24) | (t2 << 8);
  121. t3 ^= data[t3 & 0xff];
  122. t1 ^= data[t1 & 0xff];
  123. t2 = (t3 >> 24) | (t3 << 8);
  124. t4 <<= 1;
  125. }
  126. }
  127. data[305] = t2;
  128. data[306] = t1;
  129. data[307] = t4;
  130. data[308] = n1;
  131. // t1 ^= t2;
  132. }
  133. void encshare4(unsigned char *src, int size, unsigned int *dest) {
  134. unsigned int tmp;
  135. int i;
  136. unsigned char pos,
  137. x,
  138. y;
  139. for(i = 0; i < 256; i++) dest[i] = 0;
  140. for(y = 0; y < 4; y++) {
  141. for(i = 0; i < 256; i++) {
  142. dest[i] = (dest[i] << 8) + i;
  143. }
  144. for(pos = y, x = 0; x < 2; x++) {
  145. for(i = 0; i < 256; i++) {
  146. tmp = dest[i];
  147. pos += tmp + src[i % size];
  148. dest[i] = dest[pos];
  149. dest[pos] = tmp;
  150. }
  151. }
  152. }
  153. for(i = 0; i < 256; i++) dest[i] ^= i;
  154. encshare3(dest, 0, 0);
  155. }