No Description

aes_via_ace.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
  3. The redistribution and use of this software (with or without changes)
  4. is allowed without the payment of fees or royalties provided that:
  5. source code distributions include the above copyright notice, this
  6. list of conditions and the following disclaimer;
  7. binary distributions include the above copyright notice, this list
  8. of conditions and the following disclaimer in their documentation.
  9. This software is provided 'as is' with no explicit or implied warranties
  10. in respect of its operation, including, but not limited to, correctness
  11. and fitness for purpose.
  12. ---------------------------------------------------------------------------
  13. Issue Date: 20/12/2007
  14. */
  15. #ifndef AES_VIA_ACE_H
  16. #define AES_VIA_ACE_H
  17. #if defined( _MSC_VER )
  18. # define INLINE __inline
  19. #elif defined( __GNUC__ )
  20. # define INLINE static inline
  21. #else
  22. # error VIA ACE requires Microsoft or GNU C
  23. #endif
  24. #define NEH_GENERATE 1
  25. #define NEH_LOAD 2
  26. #define NEH_HYBRID 3
  27. #define MAX_READ_ATTEMPTS 1000
  28. /* VIA Nehemiah RNG and ACE Feature Mask Values */
  29. #define NEH_CPU_IS_VIA 0x00000001
  30. #define NEH_CPU_READ 0x00000010
  31. #define NEH_CPU_MASK 0x00000011
  32. #define NEH_RNG_PRESENT 0x00000004
  33. #define NEH_RNG_ENABLED 0x00000008
  34. #define NEH_ACE_PRESENT 0x00000040
  35. #define NEH_ACE_ENABLED 0x00000080
  36. #define NEH_RNG_FLAGS (NEH_RNG_PRESENT | NEH_RNG_ENABLED)
  37. #define NEH_ACE_FLAGS (NEH_ACE_PRESENT | NEH_ACE_ENABLED)
  38. #define NEH_FLAGS_MASK (NEH_RNG_FLAGS | NEH_ACE_FLAGS)
  39. /* VIA Nehemiah Advanced Cryptography Engine (ACE) Control Word Values */
  40. #define NEH_GEN_KEY 0x00000000 /* generate key schedule */
  41. #define NEH_LOAD_KEY 0x00000080 /* load schedule from memory */
  42. #define NEH_ENCRYPT 0x00000000 /* encryption */
  43. #define NEH_DECRYPT 0x00000200 /* decryption */
  44. #define NEH_KEY128 0x00000000+0x0a /* 128 bit key */
  45. #define NEH_KEY192 0x00000400+0x0c /* 192 bit key */
  46. #define NEH_KEY256 0x00000800+0x0e /* 256 bit key */
  47. #define NEH_ENC_GEN (NEH_ENCRYPT | NEH_GEN_KEY)
  48. #define NEH_DEC_GEN (NEH_DECRYPT | NEH_GEN_KEY)
  49. #define NEH_ENC_LOAD (NEH_ENCRYPT | NEH_LOAD_KEY)
  50. #define NEH_DEC_LOAD (NEH_DECRYPT | NEH_LOAD_KEY)
  51. #define NEH_ENC_GEN_DATA {\
  52. NEH_ENC_GEN | NEH_KEY128, 0, 0, 0,\
  53. NEH_ENC_GEN | NEH_KEY192, 0, 0, 0,\
  54. NEH_ENC_GEN | NEH_KEY256, 0, 0, 0 }
  55. #define NEH_ENC_LOAD_DATA {\
  56. NEH_ENC_LOAD | NEH_KEY128, 0, 0, 0,\
  57. NEH_ENC_LOAD | NEH_KEY192, 0, 0, 0,\
  58. NEH_ENC_LOAD | NEH_KEY256, 0, 0, 0 }
  59. #define NEH_ENC_HYBRID_DATA {\
  60. NEH_ENC_GEN | NEH_KEY128, 0, 0, 0,\
  61. NEH_ENC_LOAD | NEH_KEY192, 0, 0, 0,\
  62. NEH_ENC_LOAD | NEH_KEY256, 0, 0, 0 }
  63. #define NEH_DEC_GEN_DATA {\
  64. NEH_DEC_GEN | NEH_KEY128, 0, 0, 0,\
  65. NEH_DEC_GEN | NEH_KEY192, 0, 0, 0,\
  66. NEH_DEC_GEN | NEH_KEY256, 0, 0, 0 }
  67. #define NEH_DEC_LOAD_DATA {\
  68. NEH_DEC_LOAD | NEH_KEY128, 0, 0, 0,\
  69. NEH_DEC_LOAD | NEH_KEY192, 0, 0, 0,\
  70. NEH_DEC_LOAD | NEH_KEY256, 0, 0, 0 }
  71. #define NEH_DEC_HYBRID_DATA {\
  72. NEH_DEC_GEN | NEH_KEY128, 0, 0, 0,\
  73. NEH_DEC_LOAD | NEH_KEY192, 0, 0, 0,\
  74. NEH_DEC_LOAD | NEH_KEY256, 0, 0, 0 }
  75. #define neh_enc_gen_key(x) ((x) == 128 ? (NEH_ENC_GEN | NEH_KEY128) : \
  76. (x) == 192 ? (NEH_ENC_GEN | NEH_KEY192) : (NEH_ENC_GEN | NEH_KEY256))
  77. #define neh_enc_load_key(x) ((x) == 128 ? (NEH_ENC_LOAD | NEH_KEY128) : \
  78. (x) == 192 ? (NEH_ENC_LOAD | NEH_KEY192) : (NEH_ENC_LOAD | NEH_KEY256))
  79. #define neh_enc_hybrid_key(x) ((x) == 128 ? (NEH_ENC_GEN | NEH_KEY128) : \
  80. (x) == 192 ? (NEH_ENC_LOAD | NEH_KEY192) : (NEH_ENC_LOAD | NEH_KEY256))
  81. #define neh_dec_gen_key(x) ((x) == 128 ? (NEH_DEC_GEN | NEH_KEY128) : \
  82. (x) == 192 ? (NEH_DEC_GEN | NEH_KEY192) : (NEH_DEC_GEN | NEH_KEY256))
  83. #define neh_dec_load_key(x) ((x) == 128 ? (NEH_DEC_LOAD | NEH_KEY128) : \
  84. (x) == 192 ? (NEH_DEC_LOAD | NEH_KEY192) : (NEH_DEC_LOAD | NEH_KEY256))
  85. #define neh_dec_hybrid_key(x) ((x) == 128 ? (NEH_DEC_GEN | NEH_KEY128) : \
  86. (x) == 192 ? (NEH_DEC_LOAD | NEH_KEY192) : (NEH_DEC_LOAD | NEH_KEY256))
  87. #if defined( _MSC_VER ) && ( _MSC_VER > 1200 )
  88. #define aligned_auto(type, name, no, stride) __declspec(align(stride)) type name[no]
  89. #else
  90. #define aligned_auto(type, name, no, stride) \
  91. unsigned char _##name[no * sizeof(type) + stride]; \
  92. type *name = (type*)(16 * ((((unsigned long)(_##name)) + stride - 1) / stride))
  93. #endif
  94. #if defined( _MSC_VER ) && ( _MSC_VER > 1200 )
  95. #define aligned_array(type, name, no, stride) __declspec(align(stride)) type name[no]
  96. #elif defined( __GNUC__ )
  97. #define aligned_array(type, name, no, stride) type name[no] __attribute__ ((aligned(stride)))
  98. #else
  99. #define aligned_array(type, name, no, stride) type name[no]
  100. #endif
  101. /* VIA ACE codeword */
  102. static unsigned char via_flags = 0;
  103. #if defined ( _MSC_VER ) && ( _MSC_VER > 800 )
  104. #define NEH_REKEY __asm pushfd __asm popfd
  105. #define NEH_AES __asm _emit 0xf3 __asm _emit 0x0f __asm _emit 0xa7
  106. #define NEH_ECB NEH_AES __asm _emit 0xc8
  107. #define NEH_CBC NEH_AES __asm _emit 0xd0
  108. #define NEH_CFB NEH_AES __asm _emit 0xe0
  109. #define NEH_OFB NEH_AES __asm _emit 0xe8
  110. #define NEH_RNG __asm _emit 0x0f __asm _emit 0xa7 __asm _emit 0xc0
  111. INLINE int has_cpuid(void)
  112. { char ret_value;
  113. __asm
  114. { pushfd /* save EFLAGS register */
  115. mov eax,[esp] /* copy it to eax */
  116. mov edx,0x00200000 /* CPUID bit position */
  117. xor eax,edx /* toggle the CPUID bit */
  118. push eax /* attempt to set EFLAGS to */
  119. popfd /* the new value */
  120. pushfd /* get the new EFLAGS value */
  121. pop eax /* into eax */
  122. xor eax,[esp] /* xor with original value */
  123. and eax,edx /* has CPUID bit changed? */
  124. setne al /* set to 1 if we have been */
  125. mov ret_value,al /* able to change it */
  126. popfd /* restore original EFLAGS */
  127. }
  128. return (int)ret_value;
  129. }
  130. INLINE int is_via_cpu(void)
  131. { char ret_value;
  132. __asm
  133. { push ebx
  134. xor eax,eax /* use CPUID to get vendor */
  135. cpuid /* identity string */
  136. xor eax,eax /* is it "CentaurHauls" ? */
  137. sub ebx,0x746e6543 /* 'Cent' */
  138. or eax,ebx
  139. sub edx,0x48727561 /* 'aurH' */
  140. or eax,edx
  141. sub ecx,0x736c7561 /* 'auls' */
  142. or eax,ecx
  143. sete al /* set to 1 if it is VIA ID */
  144. mov dl,NEH_CPU_READ /* mark CPU type as read */
  145. or dl,al /* & store result in flags */
  146. mov [via_flags],dl /* set VIA detected flag */
  147. mov ret_value,al /* able to change it */
  148. pop ebx
  149. }
  150. return (int)ret_value;
  151. }
  152. INLINE int read_via_flags(void)
  153. { char ret_value = 0;
  154. __asm
  155. { mov eax,0xC0000000 /* Centaur extended CPUID */
  156. cpuid
  157. mov edx,0xc0000001 /* >= 0xc0000001 if support */
  158. cmp eax,edx /* for VIA extended feature */
  159. jnae no_rng /* flags is available */
  160. mov eax,edx /* read Centaur extended */
  161. cpuid /* feature flags */
  162. mov eax,NEH_FLAGS_MASK /* mask out and save */
  163. and eax,edx /* the RNG and ACE flags */
  164. or [via_flags],al /* present & enabled flags */
  165. mov ret_value,al /* able to change it */
  166. no_rng:
  167. }
  168. return (int)ret_value;
  169. }
  170. INLINE unsigned int via_rng_in(void *buf)
  171. { char ret_value = 0x1f;
  172. __asm
  173. { push edi
  174. mov edi,buf /* input buffer address */
  175. xor edx,edx /* try to fetch 8 bytes */
  176. NEH_RNG /* do RNG read operation */
  177. and ret_value,al /* count of bytes returned */
  178. pop edi
  179. }
  180. return (int)ret_value;
  181. }
  182. INLINE void via_ecb_op5(
  183. const void *k, const void *c, const void *s, void *d, int l)
  184. { __asm
  185. { push ebx
  186. NEH_REKEY
  187. mov ebx, (k)
  188. mov edx, (c)
  189. mov esi, (s)
  190. mov edi, (d)
  191. mov ecx, (l)
  192. NEH_ECB
  193. pop ebx
  194. }
  195. }
  196. INLINE void via_cbc_op6(
  197. const void *k, const void *c, const void *s, void *d, int l, void *v)
  198. { __asm
  199. { push ebx
  200. NEH_REKEY
  201. mov ebx, (k)
  202. mov edx, (c)
  203. mov esi, (s)
  204. mov edi, (d)
  205. mov ecx, (l)
  206. mov eax, (v)
  207. NEH_CBC
  208. pop ebx
  209. }
  210. }
  211. INLINE void via_cbc_op7(
  212. const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
  213. { __asm
  214. { push ebx
  215. NEH_REKEY
  216. mov ebx, (k)
  217. mov edx, (c)
  218. mov esi, (s)
  219. mov edi, (d)
  220. mov ecx, (l)
  221. mov eax, (v)
  222. NEH_CBC
  223. mov esi, eax
  224. mov edi, (w)
  225. movsd
  226. movsd
  227. movsd
  228. movsd
  229. pop ebx
  230. }
  231. }
  232. INLINE void via_cfb_op6(
  233. const void *k, const void *c, const void *s, void *d, int l, void *v)
  234. { __asm
  235. { push ebx
  236. NEH_REKEY
  237. mov ebx, (k)
  238. mov edx, (c)
  239. mov esi, (s)
  240. mov edi, (d)
  241. mov ecx, (l)
  242. mov eax, (v)
  243. NEH_CFB
  244. pop ebx
  245. }
  246. }
  247. INLINE void via_cfb_op7(
  248. const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
  249. { __asm
  250. { push ebx
  251. NEH_REKEY
  252. mov ebx, (k)
  253. mov edx, (c)
  254. mov esi, (s)
  255. mov edi, (d)
  256. mov ecx, (l)
  257. mov eax, (v)
  258. NEH_CFB
  259. mov esi, eax
  260. mov edi, (w)
  261. movsd
  262. movsd
  263. movsd
  264. movsd
  265. pop ebx
  266. }
  267. }
  268. INLINE void via_ofb_op6(
  269. const void *k, const void *c, const void *s, void *d, int l, void *v)
  270. { __asm
  271. { push ebx
  272. NEH_REKEY
  273. mov ebx, (k)
  274. mov edx, (c)
  275. mov esi, (s)
  276. mov edi, (d)
  277. mov ecx, (l)
  278. mov eax, (v)
  279. NEH_OFB
  280. pop ebx
  281. }
  282. }
  283. #elif defined( __GNUC__ )
  284. #define NEH_REKEY asm("pushfl\n popfl\n\t")
  285. #define NEH_ECB asm(".byte 0xf3, 0x0f, 0xa7, 0xc8\n\t")
  286. #define NEH_CBC asm(".byte 0xf3, 0x0f, 0xa7, 0xd0\n\t")
  287. #define NEH_CFB asm(".byte 0xf3, 0x0f, 0xa7, 0xe0\n\t")
  288. #define NEH_OFB asm(".byte 0xf3, 0x0f, 0xa7, 0xe8\n\t")
  289. #define NEH_RNG asm(".byte 0x0f, 0xa7, 0xc0\n\t");
  290. INLINE int has_cpuid(void)
  291. { int val;
  292. asm("pushfl\n\t");
  293. asm("movl 0(%esp),%eax\n\t");
  294. asm("xor $0x00200000,%eax\n\t");
  295. asm("pushl %eax\n\t");
  296. asm("popfl\n\t");
  297. asm("pushfl\n\t");
  298. asm("popl %eax\n\t");
  299. asm("xorl 0(%esp),%edx\n\t");
  300. asm("andl $0x00200000,%eax\n\t");
  301. asm("movl %%eax,%0\n\t" : "=m" (val));
  302. asm("popfl\n\t");
  303. return val ? 1 : 0;
  304. }
  305. INLINE int is_via_cpu(void)
  306. { int val;
  307. asm("pushl %ebx\n\t");
  308. asm("xorl %eax,%eax\n\t");
  309. asm("cpuid\n\t");
  310. asm("xorl %eax,%eax\n\t");
  311. asm("subl $0x746e6543,%ebx\n\t");
  312. asm("orl %ebx,%eax\n\t");
  313. asm("subl $0x48727561,%edx\n\t");
  314. asm("orl %edx,%eax\n\t");
  315. asm("subl $0x736c7561,%ecx\n\t");
  316. asm("orl %ecx,%eax\n\t");
  317. asm("movl %%eax,%0\n\t" : "=m" (val));
  318. asm("popl %ebx\n\t");
  319. val = (val ? 0 : 1);
  320. via_flags = (val | NEH_CPU_READ);
  321. return val;
  322. }
  323. INLINE int read_via_flags(void)
  324. { unsigned char val;
  325. asm("movl $0xc0000000,%eax\n\t");
  326. asm("cpuid\n\t");
  327. asm("movl $0xc0000001,%edx\n\t");
  328. asm("cmpl %edx,%eax\n\t");
  329. asm("setae %al\n\t");
  330. asm("movb %%al,%0\n\t" : "=m" (val));
  331. if(!val) return 0;
  332. asm("movl $0xc0000001,%eax\n\t");
  333. asm("cpuid\n\t");
  334. asm("movb %%dl,%0\n\t" : "=m" (val));
  335. val &= NEH_FLAGS_MASK;
  336. via_flags |= val;
  337. return (int) val;
  338. }
  339. INLINE int via_rng_in(void *buf)
  340. { int val;
  341. asm("pushl %edi\n\t");
  342. asm("movl %0,%%edi\n\t" : : "m" (buf));
  343. asm("xorl %edx,%edx\n\t");
  344. NEH_RNG
  345. asm("andl $0x0000001f,%eax\n\t");
  346. asm("movl %%eax,%0\n\t" : "=m" (val));
  347. asm("popl %edi\n\t");
  348. return val;
  349. }
  350. INLINE volatile void via_ecb_op5(
  351. const void *k, const void *c, const void *s, void *d, int l)
  352. {
  353. asm("pushl %ebx\n\t");
  354. NEH_REKEY;
  355. asm("movl %0, %%ebx\n\t" : : "m" (k));
  356. asm("movl %0, %%edx\n\t" : : "m" (c));
  357. asm("movl %0, %%esi\n\t" : : "m" (s));
  358. asm("movl %0, %%edi\n\t" : : "m" (d));
  359. asm("movl %0, %%ecx\n\t" : : "m" (l));
  360. NEH_ECB;
  361. asm("popl %ebx\n\t");
  362. }
  363. INLINE volatile void via_cbc_op6(
  364. const void *k, const void *c, const void *s, void *d, int l, void *v)
  365. {
  366. asm("pushl %ebx\n\t");
  367. NEH_REKEY;
  368. asm("movl %0, %%ebx\n\t" : : "m" (k));
  369. asm("movl %0, %%edx\n\t" : : "m" (c));
  370. asm("movl %0, %%esi\n\t" : : "m" (s));
  371. asm("movl %0, %%edi\n\t" : : "m" (d));
  372. asm("movl %0, %%ecx\n\t" : : "m" (l));
  373. asm("movl %0, %%eax\n\t" : : "m" (v));
  374. NEH_CBC;
  375. asm("popl %ebx\n\t");
  376. }
  377. INLINE volatile void via_cbc_op7(
  378. const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
  379. {
  380. asm("pushl %ebx\n\t");
  381. NEH_REKEY;
  382. asm("movl %0, %%ebx\n\t" : : "m" (k));
  383. asm("movl %0, %%edx\n\t" : : "m" (c));
  384. asm("movl %0, %%esi\n\t" : : "m" (s));
  385. asm("movl %0, %%edi\n\t" : : "m" (d));
  386. asm("movl %0, %%ecx\n\t" : : "m" (l));
  387. asm("movl %0, %%eax\n\t" : : "m" (v));
  388. NEH_CBC;
  389. asm("movl %eax,%esi\n\t");
  390. asm("movl %0, %%edi\n\t" : : "m" (w));
  391. asm("movsl; movsl; movsl; movsl\n\t");
  392. asm("popl %ebx\n\t");
  393. }
  394. INLINE volatile void via_cfb_op6(
  395. const void *k, const void *c, const void *s, void *d, int l, void *v)
  396. {
  397. asm("pushl %ebx\n\t");
  398. NEH_REKEY;
  399. asm("movl %0, %%ebx\n\t" : : "m" (k));
  400. asm("movl %0, %%edx\n\t" : : "m" (c));
  401. asm("movl %0, %%esi\n\t" : : "m" (s));
  402. asm("movl %0, %%edi\n\t" : : "m" (d));
  403. asm("movl %0, %%ecx\n\t" : : "m" (l));
  404. asm("movl %0, %%eax\n\t" : : "m" (v));
  405. NEH_CFB;
  406. asm("popl %ebx\n\t");
  407. }
  408. INLINE volatile void via_cfb_op7(
  409. const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
  410. {
  411. asm("pushl %ebx\n\t");
  412. NEH_REKEY;
  413. asm("movl %0, %%ebx\n\t" : : "m" (k));
  414. asm("movl %0, %%edx\n\t" : : "m" (c));
  415. asm("movl %0, %%esi\n\t" : : "m" (s));
  416. asm("movl %0, %%edi\n\t" : : "m" (d));
  417. asm("movl %0, %%ecx\n\t" : : "m" (l));
  418. asm("movl %0, %%eax\n\t" : : "m" (v));
  419. NEH_CFB;
  420. asm("movl %eax,%esi\n\t");
  421. asm("movl %0, %%edi\n\t" : : "m" (w));
  422. asm("movsl; movsl; movsl; movsl\n\t");
  423. asm("popl %ebx\n\t");
  424. }
  425. INLINE volatile void via_ofb_op6(
  426. const void *k, const void *c, const void *s, void *d, int l, void *v)
  427. {
  428. asm("pushl %ebx\n\t");
  429. NEH_REKEY;
  430. asm("movl %0, %%ebx\n\t" : : "m" (k));
  431. asm("movl %0, %%edx\n\t" : : "m" (c));
  432. asm("movl %0, %%esi\n\t" : : "m" (s));
  433. asm("movl %0, %%edi\n\t" : : "m" (d));
  434. asm("movl %0, %%ecx\n\t" : : "m" (l));
  435. asm("movl %0, %%eax\n\t" : : "m" (v));
  436. NEH_OFB;
  437. asm("popl %ebx\n\t");
  438. }
  439. #else
  440. #error VIA ACE is not available with this compiler
  441. #endif
  442. INLINE int via_ace_test(void)
  443. {
  444. return has_cpuid() && is_via_cpu() && ((read_via_flags() & NEH_ACE_FLAGS) == NEH_ACE_FLAGS);
  445. }
  446. #define VIA_ACE_AVAILABLE (((via_flags & NEH_ACE_FLAGS) == NEH_ACE_FLAGS) \
  447. || (via_flags & NEH_CPU_READ) && (via_flags & NEH_CPU_IS_VIA) || via_ace_test())
  448. INLINE int via_rng_test(void)
  449. {
  450. return has_cpuid() && is_via_cpu() && ((read_via_flags() & NEH_RNG_FLAGS) == NEH_RNG_FLAGS);
  451. }
  452. #define VIA_RNG_AVAILABLE (((via_flags & NEH_RNG_FLAGS) == NEH_RNG_FLAGS) \
  453. || (via_flags & NEH_CPU_READ) && (via_flags & NEH_CPU_IS_VIA) || via_rng_test())
  454. INLINE int read_via_rng(void *buf, int count)
  455. { int nbr, max_reads, lcnt = count;
  456. unsigned char *p, *q;
  457. aligned_auto(unsigned char, bp, 64, 16);
  458. if(!VIA_RNG_AVAILABLE)
  459. return 0;
  460. do
  461. {
  462. max_reads = MAX_READ_ATTEMPTS;
  463. do
  464. nbr = via_rng_in(bp);
  465. while
  466. (nbr == 0 && --max_reads);
  467. lcnt -= nbr;
  468. p = (unsigned char*)buf; q = bp;
  469. while(nbr--)
  470. *p++ = *q++;
  471. }
  472. while
  473. (lcnt && max_reads);
  474. return count - lcnt;
  475. }
  476. #endif