home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume29 / libdes / part03 < prev    next >
Internet Message Format  |  1992-04-04  |  39KB

  1. From: eay@psych.psy.uq.oz.au (Eric Young)
  2. Newsgroups: comp.sources.misc
  3. Subject: v29i045: libdes - DES encryption library, Part03/04
  4. Message-ID: <1992Apr3.224129.29668@aber.ac.uk>
  5. Date: 3 Apr 92 22:41:29 GMT
  6. Approved: aem@aber.ac.uk
  7. X-Md4-Signature: 0ccae4e73807ce4f2d66c7acf9386f0d
  8.  
  9. Submitted-by: eay@psych.psy.uq.oz.au (Eric Young)
  10. Posting-number: Volume 29, Issue 45
  11. Archive-name: libdes/part03
  12. Environment: UNIX
  13.  
  14. #! /bin/sh
  15. # it by saving it into a file and typing "sh file".  To overwrite existing
  16. # files, type "sh file -c".  You can also feed this as standard input via
  17. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  18. # will see the following message at the end:
  19. #        "End of archive 3 (of 4)."
  20. # Contents:  des.pl fcrypt.c
  21. # Wrapped by aem@aberfa on Wed Apr  1 15:53:25 1992
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'des.pl' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'des.pl'\"
  25. else
  26. echo shar: Extracting \"'des.pl'\" \(17482 characters\)
  27. sed "s/^X//" >'des.pl' <<'END_OF_FILE'
  28. X#!/usr/local/bin/perl
  29. X# Copyright (C) 1992 Eric Young
  30. X# des.pl - eric young 22/11/1991 eay@psych.psy.uq.oz.au
  31. X#
  32. X# This is an implementation of DES in perl.
  33. X# The two routines (des_set_key and des_ecb_encrypt)
  34. X# take 8 byte objects as arguments.
  35. X#
  36. X# des_set_key takes an 8 byte string as a key and returns a key schedule
  37. X# for use in calls to des_ecb_encrypt.
  38. X# des_ecb_encrypt takes three arguments, the first is a key schedule
  39. X# (make sure to pass it by reference with the *), the second is 1
  40. X# to encrypt, 0 to decrypt.  The third argument is an 8 byte object
  41. X# to encrypt.  The function returns an 8 byte object that has been
  42. X# DES encrypted.
  43. X#
  44. X# example:
  45. X# require 'des.pl'
  46. X#
  47. X# $key =pack("C8",0x12,0x23,0x45,0x67,0x89,0xab,0xcd,0xef);
  48. X# @ks=  &des_set_key($key);
  49. X#
  50. X# $outbytes= &des_ecb_encrypt(*ks,1,$data);
  51. X# @enc =unpack("C8",$outbytes);
  52. X#
  53. X
  54. Xpackage des;
  55. X
  56. X# The following 8 arrays are used in des_set_key
  57. X@skb0=(
  58. X# for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 
  59. X0x00000000,0x00000010,0x20000000,0x20000010,
  60. X0x00010000,0x00010010,0x20010000,0x20010010,
  61. X0x00000800,0x00000810,0x20000800,0x20000810,
  62. X0x00010800,0x00010810,0x20010800,0x20010810,
  63. X0x00000020,0x00000030,0x20000020,0x20000030,
  64. X0x00010020,0x00010030,0x20010020,0x20010030,
  65. X0x00000820,0x00000830,0x20000820,0x20000830,
  66. X0x00010820,0x00010830,0x20010820,0x20010830,
  67. X0x00080000,0x00080010,0x20080000,0x20080010,
  68. X0x00090000,0x00090010,0x20090000,0x20090010,
  69. X0x00080800,0x00080810,0x20080800,0x20080810,
  70. X0x00090800,0x00090810,0x20090800,0x20090810,
  71. X0x00080020,0x00080030,0x20080020,0x20080030,
  72. X0x00090020,0x00090030,0x20090020,0x20090030,
  73. X0x00080820,0x00080830,0x20080820,0x20080830,
  74. X0x00090820,0x00090830,0x20090820,0x20090830,
  75. X);
  76. X@skb1=(
  77. X# for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 
  78. X0x00000000,0x02000000,0x00002000,0x02002000,
  79. X0x00200000,0x02200000,0x00202000,0x02202000,
  80. X0x00000004,0x02000004,0x00002004,0x02002004,
  81. X0x00200004,0x02200004,0x00202004,0x02202004,
  82. X0x00000400,0x02000400,0x00002400,0x02002400,
  83. X0x00200400,0x02200400,0x00202400,0x02202400,
  84. X0x00000404,0x02000404,0x00002404,0x02002404,
  85. X0x00200404,0x02200404,0x00202404,0x02202404,
  86. X0x10000000,0x12000000,0x10002000,0x12002000,
  87. X0x10200000,0x12200000,0x10202000,0x12202000,
  88. X0x10000004,0x12000004,0x10002004,0x12002004,
  89. X0x10200004,0x12200004,0x10202004,0x12202004,
  90. X0x10000400,0x12000400,0x10002400,0x12002400,
  91. X0x10200400,0x12200400,0x10202400,0x12202400,
  92. X0x10000404,0x12000404,0x10002404,0x12002404,
  93. X0x10200404,0x12200404,0x10202404,0x12202404,
  94. X);
  95. X@skb2=(
  96. X# for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 
  97. X0x00000000,0x00000001,0x00040000,0x00040001,
  98. X0x01000000,0x01000001,0x01040000,0x01040001,
  99. X0x00000002,0x00000003,0x00040002,0x00040003,
  100. X0x01000002,0x01000003,0x01040002,0x01040003,
  101. X0x00000200,0x00000201,0x00040200,0x00040201,
  102. X0x01000200,0x01000201,0x01040200,0x01040201,
  103. X0x00000202,0x00000203,0x00040202,0x00040203,
  104. X0x01000202,0x01000203,0x01040202,0x01040203,
  105. X0x08000000,0x08000001,0x08040000,0x08040001,
  106. X0x09000000,0x09000001,0x09040000,0x09040001,
  107. X0x08000002,0x08000003,0x08040002,0x08040003,
  108. X0x09000002,0x09000003,0x09040002,0x09040003,
  109. X0x08000200,0x08000201,0x08040200,0x08040201,
  110. X0x09000200,0x09000201,0x09040200,0x09040201,
  111. X0x08000202,0x08000203,0x08040202,0x08040203,
  112. X0x09000202,0x09000203,0x09040202,0x09040203,
  113. X);
  114. X@skb3=(
  115. X# for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 
  116. X0x00000000,0x00100000,0x00000100,0x00100100,
  117. X0x00000008,0x00100008,0x00000108,0x00100108,
  118. X0x00001000,0x00101000,0x00001100,0x00101100,
  119. X0x00001008,0x00101008,0x00001108,0x00101108,
  120. X0x04000000,0x04100000,0x04000100,0x04100100,
  121. X0x04000008,0x04100008,0x04000108,0x04100108,
  122. X0x04001000,0x04101000,0x04001100,0x04101100,
  123. X0x04001008,0x04101008,0x04001108,0x04101108,
  124. X0x00020000,0x00120000,0x00020100,0x00120100,
  125. X0x00020008,0x00120008,0x00020108,0x00120108,
  126. X0x00021000,0x00121000,0x00021100,0x00121100,
  127. X0x00021008,0x00121008,0x00021108,0x00121108,
  128. X0x04020000,0x04120000,0x04020100,0x04120100,
  129. X0x04020008,0x04120008,0x04020108,0x04120108,
  130. X0x04021000,0x04121000,0x04021100,0x04121100,
  131. X0x04021008,0x04121008,0x04021108,0x04121108,
  132. X);
  133. X@skb4=(
  134. X# for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 
  135. X0x00000000,0x10000000,0x00010000,0x10010000,
  136. X0x00000004,0x10000004,0x00010004,0x10010004,
  137. X0x20000000,0x30000000,0x20010000,0x30010000,
  138. X0x20000004,0x30000004,0x20010004,0x30010004,
  139. X0x00100000,0x10100000,0x00110000,0x10110000,
  140. X0x00100004,0x10100004,0x00110004,0x10110004,
  141. X0x20100000,0x30100000,0x20110000,0x30110000,
  142. X0x20100004,0x30100004,0x20110004,0x30110004,
  143. X0x00001000,0x10001000,0x00011000,0x10011000,
  144. X0x00001004,0x10001004,0x00011004,0x10011004,
  145. X0x20001000,0x30001000,0x20011000,0x30011000,
  146. X0x20001004,0x30001004,0x20011004,0x30011004,
  147. X0x00101000,0x10101000,0x00111000,0x10111000,
  148. X0x00101004,0x10101004,0x00111004,0x10111004,
  149. X0x20101000,0x30101000,0x20111000,0x30111000,
  150. X0x20101004,0x30101004,0x20111004,0x30111004,
  151. X);
  152. X@skb5=(
  153. X# for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 
  154. X0x00000000,0x08000000,0x00000008,0x08000008,
  155. X0x00000400,0x08000400,0x00000408,0x08000408,
  156. X0x00020000,0x08020000,0x00020008,0x08020008,
  157. X0x00020400,0x08020400,0x00020408,0x08020408,
  158. X0x00000001,0x08000001,0x00000009,0x08000009,
  159. X0x00000401,0x08000401,0x00000409,0x08000409,
  160. X0x00020001,0x08020001,0x00020009,0x08020009,
  161. X0x00020401,0x08020401,0x00020409,0x08020409,
  162. X0x02000000,0x0A000000,0x02000008,0x0A000008,
  163. X0x02000400,0x0A000400,0x02000408,0x0A000408,
  164. X0x02020000,0x0A020000,0x02020008,0x0A020008,
  165. X0x02020400,0x0A020400,0x02020408,0x0A020408,
  166. X0x02000001,0x0A000001,0x02000009,0x0A000009,
  167. X0x02000401,0x0A000401,0x02000409,0x0A000409,
  168. X0x02020001,0x0A020001,0x02020009,0x0A020009,
  169. X0x02020401,0x0A020401,0x02020409,0x0A020409,
  170. X);
  171. X@skb6=(
  172. X# for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 
  173. X0x00000000,0x00000100,0x00080000,0x00080100,
  174. X0x01000000,0x01000100,0x01080000,0x01080100,
  175. X0x00000010,0x00000110,0x00080010,0x00080110,
  176. X0x01000010,0x01000110,0x01080010,0x01080110,
  177. X0x00200000,0x00200100,0x00280000,0x00280100,
  178. X0x01200000,0x01200100,0x01280000,0x01280100,
  179. X0x00200010,0x00200110,0x00280010,0x00280110,
  180. X0x01200010,0x01200110,0x01280010,0x01280110,
  181. X0x00000200,0x00000300,0x00080200,0x00080300,
  182. X0x01000200,0x01000300,0x01080200,0x01080300,
  183. X0x00000210,0x00000310,0x00080210,0x00080310,
  184. X0x01000210,0x01000310,0x01080210,0x01080310,
  185. X0x00200200,0x00200300,0x00280200,0x00280300,
  186. X0x01200200,0x01200300,0x01280200,0x01280300,
  187. X0x00200210,0x00200310,0x00280210,0x00280310,
  188. X0x01200210,0x01200310,0x01280210,0x01280310,
  189. X);
  190. X@skb7=(
  191. X# for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 
  192. X0x00000000,0x04000000,0x00040000,0x04040000,
  193. X0x00000002,0x04000002,0x00040002,0x04040002,
  194. X0x00002000,0x04002000,0x00042000,0x04042000,
  195. X0x00002002,0x04002002,0x00042002,0x04042002,
  196. X0x00000020,0x04000020,0x00040020,0x04040020,
  197. X0x00000022,0x04000022,0x00040022,0x04040022,
  198. X0x00002020,0x04002020,0x00042020,0x04042020,
  199. X0x00002022,0x04002022,0x00042022,0x04042022,
  200. X0x00000800,0x04000800,0x00040800,0x04040800,
  201. X0x00000802,0x04000802,0x00040802,0x04040802,
  202. X0x00002800,0x04002800,0x00042800,0x04042800,
  203. X0x00002802,0x04002802,0x00042802,0x04042802,
  204. X0x00000820,0x04000820,0x00040820,0x04040820,
  205. X0x00000822,0x04000822,0x00040822,0x04040822,
  206. X0x00002820,0x04002820,0x00042820,0x04042820,
  207. X0x00002822,0x04002822,0x00042822,0x04042822,
  208. X);
  209. X
  210. X@shifts2=(0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0);
  211. X
  212. X# used in ecb_encrypt
  213. X@SP0=(
  214. X0x00410100, 0x00010000, 0x40400000, 0x40410100,
  215. X0x00400000, 0x40010100, 0x40010000, 0x40400000,
  216. X0x40010100, 0x00410100, 0x00410000, 0x40000100,
  217. X0x40400100, 0x00400000, 0x00000000, 0x40010000,
  218. X0x00010000, 0x40000000, 0x00400100, 0x00010100,
  219. X0x40410100, 0x00410000, 0x40000100, 0x00400100,
  220. X0x40000000, 0x00000100, 0x00010100, 0x40410000,
  221. X0x00000100, 0x40400100, 0x40410000, 0x00000000,
  222. X0x00000000, 0x40410100, 0x00400100, 0x40010000,
  223. X0x00410100, 0x00010000, 0x40000100, 0x00400100,
  224. X0x40410000, 0x00000100, 0x00010100, 0x40400000,
  225. X0x40010100, 0x40000000, 0x40400000, 0x00410000,
  226. X0x40410100, 0x00010100, 0x00410000, 0x40400100,
  227. X0x00400000, 0x40000100, 0x40010000, 0x00000000,
  228. X0x00010000, 0x00400000, 0x40400100, 0x00410100,
  229. X0x40000000, 0x40410000, 0x00000100, 0x40010100,
  230. X);
  231. X@SP1=(
  232. X0x08021002, 0x00000000, 0x00021000, 0x08020000,
  233. X0x08000002, 0x00001002, 0x08001000, 0x00021000,
  234. X0x00001000, 0x08020002, 0x00000002, 0x08001000,
  235. X0x00020002, 0x08021000, 0x08020000, 0x00000002,
  236. X0x00020000, 0x08001002, 0x08020002, 0x00001000,
  237. X0x00021002, 0x08000000, 0x00000000, 0x00020002,
  238. X0x08001002, 0x00021002, 0x08021000, 0x08000002,
  239. X0x08000000, 0x00020000, 0x00001002, 0x08021002,
  240. X0x00020002, 0x08021000, 0x08001000, 0x00021002,
  241. X0x08021002, 0x00020002, 0x08000002, 0x00000000,
  242. X0x08000000, 0x00001002, 0x00020000, 0x08020002,
  243. X0x00001000, 0x08000000, 0x00021002, 0x08001002,
  244. X0x08021000, 0x00001000, 0x00000000, 0x08000002,
  245. X0x00000002, 0x08021002, 0x00021000, 0x08020000,
  246. X0x08020002, 0x00020000, 0x00001002, 0x08001000,
  247. X0x08001002, 0x00000002, 0x08020000, 0x00021000,
  248. X);
  249. X@SP2=(
  250. X0x20800000, 0x00808020, 0x00000020, 0x20800020,
  251. X0x20008000, 0x00800000, 0x20800020, 0x00008020,
  252. X0x00800020, 0x00008000, 0x00808000, 0x20000000,
  253. X0x20808020, 0x20000020, 0x20000000, 0x20808000,
  254. X0x00000000, 0x20008000, 0x00808020, 0x00000020,
  255. X0x20000020, 0x20808020, 0x00008000, 0x20800000,
  256. X0x20808000, 0x00800020, 0x20008020, 0x00808000,
  257. X0x00008020, 0x00000000, 0x00800000, 0x20008020,
  258. X0x00808020, 0x00000020, 0x20000000, 0x00008000,
  259. X0x20000020, 0x20008000, 0x00808000, 0x20800020,
  260. X0x00000000, 0x00808020, 0x00008020, 0x20808000,
  261. X0x20008000, 0x00800000, 0x20808020, 0x20000000,
  262. X0x20008020, 0x20800000, 0x00800000, 0x20808020,
  263. X0x00008000, 0x00800020, 0x20800020, 0x00008020,
  264. X0x00800020, 0x00000000, 0x20808000, 0x20000020,
  265. X0x20800000, 0x20008020, 0x00000020, 0x00808000,
  266. X);
  267. X@SP3=(
  268. X0x00080201, 0x02000200, 0x00000001, 0x02080201,
  269. X0x00000000, 0x02080000, 0x02000201, 0x00080001,
  270. X0x02080200, 0x02000001, 0x02000000, 0x00000201,
  271. X0x02000001, 0x00080201, 0x00080000, 0x02000000,
  272. X0x02080001, 0x00080200, 0x00000200, 0x00000001,
  273. X0x00080200, 0x02000201, 0x02080000, 0x00000200,
  274. X0x00000201, 0x00000000, 0x00080001, 0x02080200,
  275. X0x02000200, 0x02080001, 0x02080201, 0x00080000,
  276. X0x02080001, 0x00000201, 0x00080000, 0x02000001,
  277. X0x00080200, 0x02000200, 0x00000001, 0x02080000,
  278. X0x02000201, 0x00000000, 0x00000200, 0x00080001,
  279. X0x00000000, 0x02080001, 0x02080200, 0x00000200,
  280. X0x02000000, 0x02080201, 0x00080201, 0x00080000,
  281. X0x02080201, 0x00000001, 0x02000200, 0x00080201,
  282. X0x00080001, 0x00080200, 0x02080000, 0x02000201,
  283. X0x00000201, 0x02000000, 0x02000001, 0x02080200,
  284. X);
  285. X@SP4=(
  286. X0x01000000, 0x00002000, 0x00000080, 0x01002084,
  287. X0x01002004, 0x01000080, 0x00002084, 0x01002000,
  288. X0x00002000, 0x00000004, 0x01000004, 0x00002080,
  289. X0x01000084, 0x01002004, 0x01002080, 0x00000000,
  290. X0x00002080, 0x01000000, 0x00002004, 0x00000084,
  291. X0x01000080, 0x00002084, 0x00000000, 0x01000004,
  292. X0x00000004, 0x01000084, 0x01002084, 0x00002004,
  293. X0x01002000, 0x00000080, 0x00000084, 0x01002080,
  294. X0x01002080, 0x01000084, 0x00002004, 0x01002000,
  295. X0x00002000, 0x00000004, 0x01000004, 0x01000080,
  296. X0x01000000, 0x00002080, 0x01002084, 0x00000000,
  297. X0x00002084, 0x01000000, 0x00000080, 0x00002004,
  298. X0x01000084, 0x00000080, 0x00000000, 0x01002084,
  299. X0x01002004, 0x01002080, 0x00000084, 0x00002000,
  300. X0x00002080, 0x01002004, 0x01000080, 0x00000084,
  301. X0x00000004, 0x00002084, 0x01002000, 0x01000004,
  302. X);
  303. X@SP5=(
  304. X0x10000008, 0x00040008, 0x00000000, 0x10040400,
  305. X0x00040008, 0x00000400, 0x10000408, 0x00040000,
  306. X0x00000408, 0x10040408, 0x00040400, 0x10000000,
  307. X0x10000400, 0x10000008, 0x10040000, 0x00040408,
  308. X0x00040000, 0x10000408, 0x10040008, 0x00000000,
  309. X0x00000400, 0x00000008, 0x10040400, 0x10040008,
  310. X0x10040408, 0x10040000, 0x10000000, 0x00000408,
  311. X0x00000008, 0x00040400, 0x00040408, 0x10000400,
  312. X0x00000408, 0x10000000, 0x10000400, 0x00040408,
  313. X0x10040400, 0x00040008, 0x00000000, 0x10000400,
  314. X0x10000000, 0x00000400, 0x10040008, 0x00040000,
  315. X0x00040008, 0x10040408, 0x00040400, 0x00000008,
  316. X0x10040408, 0x00040400, 0x00040000, 0x10000408,
  317. X0x10000008, 0x10040000, 0x00040408, 0x00000000,
  318. X0x00000400, 0x10000008, 0x10000408, 0x10040400,
  319. X0x10040000, 0x00000408, 0x00000008, 0x10040008,
  320. X);
  321. X@SP6=(
  322. X0x00000800, 0x00000040, 0x00200040, 0x80200000,
  323. X0x80200840, 0x80000800, 0x00000840, 0x00000000,
  324. X0x00200000, 0x80200040, 0x80000040, 0x00200800,
  325. X0x80000000, 0x00200840, 0x00200800, 0x80000040,
  326. X0x80200040, 0x00000800, 0x80000800, 0x80200840,
  327. X0x00000000, 0x00200040, 0x80200000, 0x00000840,
  328. X0x80200800, 0x80000840, 0x00200840, 0x80000000,
  329. X0x80000840, 0x80200800, 0x00000040, 0x00200000,
  330. X0x80000840, 0x00200800, 0x80200800, 0x80000040,
  331. X0x00000800, 0x00000040, 0x00200000, 0x80200800,
  332. X0x80200040, 0x80000840, 0x00000840, 0x00000000,
  333. X0x00000040, 0x80200000, 0x80000000, 0x00200040,
  334. X0x00000000, 0x80200040, 0x00200040, 0x00000840,
  335. X0x80000040, 0x00000800, 0x80200840, 0x00200000,
  336. X0x00200840, 0x80000000, 0x80000800, 0x80200840,
  337. X0x80200000, 0x00200840, 0x00200800, 0x80000800,
  338. X);
  339. X@SP7=(
  340. X0x04100010, 0x04104000, 0x00004010, 0x00000000,
  341. X0x04004000, 0x00100010, 0x04100000, 0x04104010,
  342. X0x00000010, 0x04000000, 0x00104000, 0x00004010,
  343. X0x00104010, 0x04004010, 0x04000010, 0x04100000,
  344. X0x00004000, 0x00104010, 0x00100010, 0x04004000,
  345. X0x04104010, 0x04000010, 0x00000000, 0x00104000,
  346. X0x04000000, 0x00100000, 0x04004010, 0x04100010,
  347. X0x00100000, 0x00004000, 0x04104000, 0x00000010,
  348. X0x00100000, 0x00004000, 0x04000010, 0x04104010,
  349. X0x00004010, 0x04000000, 0x00000000, 0x00104000,
  350. X0x04100010, 0x04004010, 0x04004000, 0x00100010,
  351. X0x04104000, 0x00000010, 0x00100010, 0x04004000,
  352. X0x04104010, 0x00100000, 0x04100000, 0x04000010,
  353. X0x00104000, 0x00004010, 0x04004010, 0x04100000,
  354. X0x00000010, 0x04104000, 0x00104010, 0x00000000,
  355. X0x04000000, 0x04100010, 0x00004000, 0x00104010,
  356. X);
  357. X
  358. Xsub main'des_set_key
  359. X    {
  360. X    local($param)=@_;
  361. X    local(@key);
  362. X    local($c,$d,$i,$s,$t);
  363. X    local(@ks)=();
  364. X
  365. X    # Get the bytes in the order we want.
  366. X    @key=unpack("C8",$param);
  367. X
  368. X    $c=    ($key[0]    )|
  369. X        ($key[1]<< 8)|
  370. X        ($key[2]<<16)|
  371. X        ($key[3]<<24);
  372. X    $d=    ($key[4]    )|
  373. X        ($key[5]<< 8)|
  374. X        ($key[6]<<16)|
  375. X        ($key[7]<<24);
  376. X
  377. X    &doPC1(*c,*d);
  378. X
  379. X    for $i (@shifts2)
  380. X        {
  381. X        if ($i)
  382. X            {
  383. X            $c=($c>>2)|($c<<26);
  384. X            $d=($d>>2)|($d<<26);
  385. X            }
  386. X        else
  387. X            {
  388. X            $c=($c>>1)|($c<<27);
  389. X            $d=($d>>1)|($d<<27);
  390. X            }
  391. X        $c&=0x0fffffff;
  392. X        $d&=0x0fffffff;
  393. X        $s=    $skb0[ ($c    )&0x3f                 ]|
  394. X            $skb1[(($c>> 6)&0x03)|(($c>> 7)&0x3c)]|
  395. X            $skb2[(($c>>13)&0x0f)|(($c>>14)&0x30)]|
  396. X            $skb3[(($c>>20)&0x01)|(($c>>21)&0x06) |
  397. X                         (($c>>22)&0x38)];
  398. X        $t=     $skb4[ ($d    )&0x3f                ]|
  399. X            $skb5[(($d>> 7)&0x03)|(($d>> 8)&0x3c)]|
  400. X            $skb6[ ($d>>15)&0x3f                 ]|
  401. X            $skb7[(($d>>21)&0x0f)|(($d>>22)&0x30)];
  402. X        push(@ks,($t<<16)|($s&0x0000ffff));
  403. X        $s=      ($s>>16)|($t&0xffff0000) ;
  404. X        push(@ks,($s<<4)|($s>>28));
  405. X        }
  406. X    @ks;
  407. X    }
  408. X
  409. Xsub doPC1
  410. X    {
  411. X    local(*a,*b)=@_;
  412. X    local($t);
  413. X
  414. X    $t=(($b>>4)^$a)&0x0f0f0f0f;
  415. X    $b^=($t<<4);
  416. X    $a^=$t;
  417. X
  418. X    # do $a first 
  419. X    $t=(($a<<18)^$a)&0xcccc0000;
  420. X    $a=$a^$t^($t>>18);
  421. X    $t=(($a<<17)^$a)&0xaaaa0000;
  422. X    $a=$a^$t^($t>>17);
  423. X    $t=(($a<< 8)^$a)&0x00ff0000;
  424. X    $a=$a^$t^($t>> 8);
  425. X    $t=(($a<<17)^$a)&0xaaaa0000;
  426. X    $a=$a^$t^($t>>17);
  427. X
  428. X    # now do $b
  429. X    $t=(($b<<24)^$b)&0xff000000;
  430. X    $b=$b^$t^($t>>24);
  431. X    $t=(($b<< 8)^$b)&0x00ff0000;
  432. X    $b=$b^$t^($t>> 8);
  433. X    $t=(($b<<14)^$b)&0x33330000;
  434. X    $b=$b^$t^($t>>14);
  435. X    $b=(($b&0x00aa00aa)<<7)|(($b&0x55005500)>>7)|($b&0xaa55aa55);
  436. X    $b=($b>>8)|(($a&0xf0000000)>>4);
  437. X    $a&=0x0fffffff;
  438. X    }
  439. X
  440. Xsub doIP
  441. X    {
  442. X    local(*a,*b)=@_;
  443. X    local($t);
  444. X
  445. X    $t=(($b>> 4)^$a)&0x0f0f0f0f;
  446. X    $b^=($t<< 4); $a^=$t;
  447. X    $t=(($a>>16)^$b)&0x0000ffff;
  448. X    $a^=($t<<16); $b^=$t;
  449. X    $t=(($b>> 2)^$a)&0x33333333;
  450. X    $b^=($t<< 2); $a^=$t;
  451. X    $t=(($a>> 8)^$b)&0x00ff00ff;
  452. X    $a^=($t<< 8); $b^=$t;
  453. X    $t=(($b>> 1)^$a)&0x55555555;
  454. X    $b^=($t<< 1); $a^=$t;
  455. X    $t=$a;
  456. X    $a=$b;
  457. X    $b=$t;
  458. X    }
  459. X
  460. Xsub doFP
  461. X    {
  462. X    local(*a,*b)=@_;
  463. X    local($t);
  464. X
  465. X    $t=(($b>> 1)^$a)&0x55555555;
  466. X    $b^=($t<< 1); $a^=$t;
  467. X    $t=(($a>> 8)^$b)&0x00ff00ff;
  468. X    $a^=($t<< 8); $b^=$t;
  469. X    $t=(($b>> 2)^$a)&0x33333333;
  470. X    $b^=($t<< 2); $a^=$t;
  471. X    $t=(($a>>16)^$b)&0x0000ffff;
  472. X    $a^=($t<<16); $b^=$t;
  473. X    $t=(($b>> 4)^$a)&0x0f0f0f0f;
  474. X    $b^=($t<< 4); $a^=$t;
  475. X    }
  476. X
  477. Xsub main'des_ecb_encrypt
  478. X    {
  479. X    local(*ks,$encrypt,$in)=@_;
  480. X    local($l,$r,$inc,$start,$end,$i,$t,$u,@input);
  481. X    
  482. X    @input=unpack("C8",$in);
  483. X    # Get the bytes in the order we want.
  484. X    $l=    ($input[0]    )|
  485. X        ($input[1]<< 8)|
  486. X        ($input[2]<<16)|
  487. X        ($input[3]<<24);
  488. X    $r=    ($input[4]    )|
  489. X        ($input[5]<< 8)|
  490. X        ($input[6]<<16)|
  491. X        ($input[7]<<24);
  492. X
  493. X    &doIP(*l,*r);
  494. X    if ($encrypt)
  495. X        {
  496. X        for ($i=0; $i<32; $i+=4)
  497. X            {
  498. X            $t=($r<<1)|($r>>31);
  499. X            $u=$t^$ks[$i  ];
  500. X            $t=$t^$ks[$i+1];
  501. X            $t=($t>>4)|($t<<28);
  502. X            $l^=    $SP1[ $t     &0x3f]|
  503. X                $SP3[($t>> 8)&0x3f]|
  504. X                $SP5[($t>>16)&0x3f]|
  505. X                $SP7[($t>>24)&0x3f]|
  506. X                $SP0[ $u     &0x3f]|
  507. X                $SP2[($u>> 8)&0x3f]|
  508. X                $SP4[($u>>16)&0x3f]|
  509. X                $SP6[($u>>24)&0x3f];
  510. X
  511. X            $t=($l<<1)|($l>>31);
  512. X            $u=$t^$ks[$i+2];
  513. X            $t=$t^$ks[$i+3];
  514. X            $t=($t>>4)|($t<<28);
  515. X            $r^=    $SP1[ $t     &0x3f]|
  516. X                $SP3[($t>> 8)&0x3f]|
  517. X                $SP5[($t>>16)&0x3f]|
  518. X                $SP7[($t>>24)&0x3f]|
  519. X                $SP0[ $u     &0x3f]|
  520. X                $SP2[($u>> 8)&0x3f]|
  521. X                $SP4[($u>>16)&0x3f]|
  522. X                $SP6[($u>>24)&0x3f];
  523. X            }
  524. X        }
  525. X    else    
  526. X        {
  527. X        for ($i=30; $i>0; $i-=4)
  528. X            {
  529. X            $t=($r<<1)|($r>>31);
  530. X            $u=$t^$ks[$i  ];
  531. X            $t=$t^$ks[$i+1];
  532. X            $t=($t>>4)|($t<<28);
  533. X            $l^=    $SP1[ $t     &0x3f]|
  534. X                $SP3[($t>> 8)&0x3f]|
  535. X                $SP5[($t>>16)&0x3f]|
  536. X                $SP7[($t>>24)&0x3f]|
  537. X                $SP0[ $u     &0x3f]|
  538. X                $SP2[($u>> 8)&0x3f]|
  539. X                $SP4[($u>>16)&0x3f]|
  540. X                $SP6[($u>>24)&0x3f];
  541. X
  542. X            $t=($l<<1)|($l>>31);
  543. X            $u=$t^$ks[$i-2];
  544. X            $t=$t^$ks[$i-1];
  545. X            $t=($t>>4)|($t<<28);
  546. X            $r^=    $SP1[ $t     &0x3f]|
  547. X                $SP3[($t>> 8)&0x3f]|
  548. X                $SP5[($t>>16)&0x3f]|
  549. X                $SP7[($t>>24)&0x3f]|
  550. X                $SP0[ $u     &0x3f]|
  551. X                $SP2[($u>> 8)&0x3f]|
  552. X                $SP4[($u>>16)&0x3f]|
  553. X                $SP6[($u>>24)&0x3f];
  554. X            }
  555. X        }
  556. X    &doFP(*l,*r);
  557. X    pack("C8",$l&0xff,$l>>8,$l>>16,$l>>24,
  558. X          $r&0xff,$r>>8,$r>>16,$r>>24);
  559. X    }
  560. END_OF_FILE
  561. if test 17482 -ne `wc -c <'des.pl'`; then
  562.     echo shar: \"'des.pl'\" unpacked with wrong size!
  563. fi
  564. # end of 'des.pl'
  565. fi
  566. if test -f 'fcrypt.c' -a "${1}" != "-c" ; then 
  567.   echo shar: Will not clobber existing file \"'fcrypt.c'\"
  568. else
  569. echo shar: Extracting \"'fcrypt.c'\" \(18467 characters\)
  570. sed "s/^X//" >'fcrypt.c' <<'END_OF_FILE'
  571. X/* fcrypt.c */
  572. X#include <stdio.h>
  573. X/* Copyright (C) 1992 Eric Young - see COPYING for more details */
  574. X
  575. X/* Eric Young.
  576. X * This version of crypt has been developed from my MIT compatable
  577. X * DES library.
  578. X * The library is available at pub/DES at ftp.psy.uq.oz.au
  579. X * eay@psych.psy.uq.oz.au
  580. X */
  581. X
  582. Xtypedef unsigned char des_cblock[8];
  583. Xtypedef struct des_ks_struct
  584. X    {
  585. X    des_cblock _;
  586. X    } des_key_schedule[16];
  587. X
  588. X#define DES_KEY_SZ     (sizeof(des_cblock))
  589. X#define DES_ENCRYPT    1
  590. X#define DES_DECRYPT    0
  591. X
  592. Xtypedef unsigned char uchar;
  593. Xtypedef unsigned short ushort;
  594. Xtypedef unsigned int uint;
  595. Xtypedef unsigned long ulong;
  596. X
  597. X#define ITERATIONS 16
  598. X#define HALF_ITERATIONS 8
  599. X
  600. X#define c2l(c,l)    (l =((ulong)(*((c)++)))    , \
  601. X             l|=((ulong)(*((c)++)))<< 8, \
  602. X             l|=((ulong)(*((c)++)))<<16, \
  603. X             l|=((ulong)(*((c)++)))<<24)
  604. X
  605. X#define l2c(l,c)    (*((c)++)=(uchar)(((l)    )&0xff), \
  606. X             *((c)++)=(uchar)(((l)>> 8)&0xff), \
  607. X             *((c)++)=(uchar)(((l)>>16)&0xff), \
  608. X             *((c)++)=(uchar)(((l)>>24)&0xff))
  609. X
  610. Xstatic unsigned long SPtrans[8][64]={
  611. X/* nibble 0 */
  612. X0x00410100, 0x00010000, 0x40400000, 0x40410100,
  613. X0x00400000, 0x40010100, 0x40010000, 0x40400000,
  614. X0x40010100, 0x00410100, 0x00410000, 0x40000100,
  615. X0x40400100, 0x00400000, 0x00000000, 0x40010000,
  616. X0x00010000, 0x40000000, 0x00400100, 0x00010100,
  617. X0x40410100, 0x00410000, 0x40000100, 0x00400100,
  618. X0x40000000, 0x00000100, 0x00010100, 0x40410000,
  619. X0x00000100, 0x40400100, 0x40410000, 0x00000000,
  620. X0x00000000, 0x40410100, 0x00400100, 0x40010000,
  621. X0x00410100, 0x00010000, 0x40000100, 0x00400100,
  622. X0x40410000, 0x00000100, 0x00010100, 0x40400000,
  623. X0x40010100, 0x40000000, 0x40400000, 0x00410000,
  624. X0x40410100, 0x00010100, 0x00410000, 0x40400100,
  625. X0x00400000, 0x40000100, 0x40010000, 0x00000000,
  626. X0x00010000, 0x00400000, 0x40400100, 0x00410100,
  627. X0x40000000, 0x40410000, 0x00000100, 0x40010100,
  628. X
  629. X/* nibble 1 */
  630. X0x08021002, 0x00000000, 0x00021000, 0x08020000,
  631. X0x08000002, 0x00001002, 0x08001000, 0x00021000,
  632. X0x00001000, 0x08020002, 0x00000002, 0x08001000,
  633. X0x00020002, 0x08021000, 0x08020000, 0x00000002,
  634. X0x00020000, 0x08001002, 0x08020002, 0x00001000,
  635. X0x00021002, 0x08000000, 0x00000000, 0x00020002,
  636. X0x08001002, 0x00021002, 0x08021000, 0x08000002,
  637. X0x08000000, 0x00020000, 0x00001002, 0x08021002,
  638. X0x00020002, 0x08021000, 0x08001000, 0x00021002,
  639. X0x08021002, 0x00020002, 0x08000002, 0x00000000,
  640. X0x08000000, 0x00001002, 0x00020000, 0x08020002,
  641. X0x00001000, 0x08000000, 0x00021002, 0x08001002,
  642. X0x08021000, 0x00001000, 0x00000000, 0x08000002,
  643. X0x00000002, 0x08021002, 0x00021000, 0x08020000,
  644. X0x08020002, 0x00020000, 0x00001002, 0x08001000,
  645. X0x08001002, 0x00000002, 0x08020000, 0x00021000,
  646. X
  647. X/* nibble 2 */
  648. X0x20800000, 0x00808020, 0x00000020, 0x20800020,
  649. X0x20008000, 0x00800000, 0x20800020, 0x00008020,
  650. X0x00800020, 0x00008000, 0x00808000, 0x20000000,
  651. X0x20808020, 0x20000020, 0x20000000, 0x20808000,
  652. X0x00000000, 0x20008000, 0x00808020, 0x00000020,
  653. X0x20000020, 0x20808020, 0x00008000, 0x20800000,
  654. X0x20808000, 0x00800020, 0x20008020, 0x00808000,
  655. X0x00008020, 0x00000000, 0x00800000, 0x20008020,
  656. X0x00808020, 0x00000020, 0x20000000, 0x00008000,
  657. X0x20000020, 0x20008000, 0x00808000, 0x20800020,
  658. X0x00000000, 0x00808020, 0x00008020, 0x20808000,
  659. X0x20008000, 0x00800000, 0x20808020, 0x20000000,
  660. X0x20008020, 0x20800000, 0x00800000, 0x20808020,
  661. X0x00008000, 0x00800020, 0x20800020, 0x00008020,
  662. X0x00800020, 0x00000000, 0x20808000, 0x20000020,
  663. X0x20800000, 0x20008020, 0x00000020, 0x00808000,
  664. X
  665. X/* nibble 3 */
  666. X0x00080201, 0x02000200, 0x00000001, 0x02080201,
  667. X0x00000000, 0x02080000, 0x02000201, 0x00080001,
  668. X0x02080200, 0x02000001, 0x02000000, 0x00000201,
  669. X0x02000001, 0x00080201, 0x00080000, 0x02000000,
  670. X0x02080001, 0x00080200, 0x00000200, 0x00000001,
  671. X0x00080200, 0x02000201, 0x02080000, 0x00000200,
  672. X0x00000201, 0x00000000, 0x00080001, 0x02080200,
  673. X0x02000200, 0x02080001, 0x02080201, 0x00080000,
  674. X0x02080001, 0x00000201, 0x00080000, 0x02000001,
  675. X0x00080200, 0x02000200, 0x00000001, 0x02080000,
  676. X0x02000201, 0x00000000, 0x00000200, 0x00080001,
  677. X0x00000000, 0x02080001, 0x02080200, 0x00000200,
  678. X0x02000000, 0x02080201, 0x00080201, 0x00080000,
  679. X0x02080201, 0x00000001, 0x02000200, 0x00080201,
  680. X0x00080001, 0x00080200, 0x02080000, 0x02000201,
  681. X0x00000201, 0x02000000, 0x02000001, 0x02080200,
  682. X
  683. X/* nibble 4 */
  684. X0x01000000, 0x00002000, 0x00000080, 0x01002084,
  685. X0x01002004, 0x01000080, 0x00002084, 0x01002000,
  686. X0x00002000, 0x00000004, 0x01000004, 0x00002080,
  687. X0x01000084, 0x01002004, 0x01002080, 0x00000000,
  688. X0x00002080, 0x01000000, 0x00002004, 0x00000084,
  689. X0x01000080, 0x00002084, 0x00000000, 0x01000004,
  690. X0x00000004, 0x01000084, 0x01002084, 0x00002004,
  691. X0x01002000, 0x00000080, 0x00000084, 0x01002080,
  692. X0x01002080, 0x01000084, 0x00002004, 0x01002000,
  693. X0x00002000, 0x00000004, 0x01000004, 0x01000080,
  694. X0x01000000, 0x00002080, 0x01002084, 0x00000000,
  695. X0x00002084, 0x01000000, 0x00000080, 0x00002004,
  696. X0x01000084, 0x00000080, 0x00000000, 0x01002084,
  697. X0x01002004, 0x01002080, 0x00000084, 0x00002000,
  698. X0x00002080, 0x01002004, 0x01000080, 0x00000084,
  699. X0x00000004, 0x00002084, 0x01002000, 0x01000004,
  700. X
  701. X/* nibble 5 */
  702. X0x10000008, 0x00040008, 0x00000000, 0x10040400,
  703. X0x00040008, 0x00000400, 0x10000408, 0x00040000,
  704. X0x00000408, 0x10040408, 0x00040400, 0x10000000,
  705. X0x10000400, 0x10000008, 0x10040000, 0x00040408,
  706. X0x00040000, 0x10000408, 0x10040008, 0x00000000,
  707. X0x00000400, 0x00000008, 0x10040400, 0x10040008,
  708. X0x10040408, 0x10040000, 0x10000000, 0x00000408,
  709. X0x00000008, 0x00040400, 0x00040408, 0x10000400,
  710. X0x00000408, 0x10000000, 0x10000400, 0x00040408,
  711. X0x10040400, 0x00040008, 0x00000000, 0x10000400,
  712. X0x10000000, 0x00000400, 0x10040008, 0x00040000,
  713. X0x00040008, 0x10040408, 0x00040400, 0x00000008,
  714. X0x10040408, 0x00040400, 0x00040000, 0x10000408,
  715. X0x10000008, 0x10040000, 0x00040408, 0x00000000,
  716. X0x00000400, 0x10000008, 0x10000408, 0x10040400,
  717. X0x10040000, 0x00000408, 0x00000008, 0x10040008,
  718. X
  719. X/* nibble 6 */
  720. X0x00000800, 0x00000040, 0x00200040, 0x80200000,
  721. X0x80200840, 0x80000800, 0x00000840, 0x00000000,
  722. X0x00200000, 0x80200040, 0x80000040, 0x00200800,
  723. X0x80000000, 0x00200840, 0x00200800, 0x80000040,
  724. X0x80200040, 0x00000800, 0x80000800, 0x80200840,
  725. X0x00000000, 0x00200040, 0x80200000, 0x00000840,
  726. X0x80200800, 0x80000840, 0x00200840, 0x80000000,
  727. X0x80000840, 0x80200800, 0x00000040, 0x00200000,
  728. X0x80000840, 0x00200800, 0x80200800, 0x80000040,
  729. X0x00000800, 0x00000040, 0x00200000, 0x80200800,
  730. X0x80200040, 0x80000840, 0x00000840, 0x00000000,
  731. X0x00000040, 0x80200000, 0x80000000, 0x00200040,
  732. X0x00000000, 0x80200040, 0x00200040, 0x00000840,
  733. X0x80000040, 0x00000800, 0x80200840, 0x00200000,
  734. X0x00200840, 0x80000000, 0x80000800, 0x80200840,
  735. X0x80200000, 0x00200840, 0x00200800, 0x80000800,
  736. X
  737. X/* nibble 7 */
  738. X0x04100010, 0x04104000, 0x00004010, 0x00000000,
  739. X0x04004000, 0x00100010, 0x04100000, 0x04104010,
  740. X0x00000010, 0x04000000, 0x00104000, 0x00004010,
  741. X0x00104010, 0x04004010, 0x04000010, 0x04100000,
  742. X0x00004000, 0x00104010, 0x00100010, 0x04004000,
  743. X0x04104010, 0x04000010, 0x00000000, 0x00104000,
  744. X0x04000000, 0x00100000, 0x04004010, 0x04100010,
  745. X0x00100000, 0x00004000, 0x04104000, 0x00000010,
  746. X0x00100000, 0x00004000, 0x04000010, 0x04104010,
  747. X0x00004010, 0x04000000, 0x00000000, 0x00104000,
  748. X0x04100010, 0x04004010, 0x04004000, 0x00100010,
  749. X0x04104000, 0x00000010, 0x00100010, 0x04004000,
  750. X0x04104010, 0x00100000, 0x04100000, 0x04000010,
  751. X0x00104000, 0x00004010, 0x04004010, 0x04100000,
  752. X0x00000010, 0x04104000, 0x00104010, 0x00000000,
  753. X0x04000000, 0x04100010, 0x00004000, 0x00104010};
  754. Xstatic ulong skb[8][64]={
  755. X/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
  756. X0x00000000,0x00000010,0x20000000,0x20000010,
  757. X0x00010000,0x00010010,0x20010000,0x20010010,
  758. X0x00000800,0x00000810,0x20000800,0x20000810,
  759. X0x00010800,0x00010810,0x20010800,0x20010810,
  760. X0x00000020,0x00000030,0x20000020,0x20000030,
  761. X0x00010020,0x00010030,0x20010020,0x20010030,
  762. X0x00000820,0x00000830,0x20000820,0x20000830,
  763. X0x00010820,0x00010830,0x20010820,0x20010830,
  764. X0x00080000,0x00080010,0x20080000,0x20080010,
  765. X0x00090000,0x00090010,0x20090000,0x20090010,
  766. X0x00080800,0x00080810,0x20080800,0x20080810,
  767. X0x00090800,0x00090810,0x20090800,0x20090810,
  768. X0x00080020,0x00080030,0x20080020,0x20080030,
  769. X0x00090020,0x00090030,0x20090020,0x20090030,
  770. X0x00080820,0x00080830,0x20080820,0x20080830,
  771. X0x00090820,0x00090830,0x20090820,0x20090830,
  772. X/* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
  773. X0x00000000,0x02000000,0x00002000,0x02002000,
  774. X0x00200000,0x02200000,0x00202000,0x02202000,
  775. X0x00000004,0x02000004,0x00002004,0x02002004,
  776. X0x00200004,0x02200004,0x00202004,0x02202004,
  777. X0x00000400,0x02000400,0x00002400,0x02002400,
  778. X0x00200400,0x02200400,0x00202400,0x02202400,
  779. X0x00000404,0x02000404,0x00002404,0x02002404,
  780. X0x00200404,0x02200404,0x00202404,0x02202404,
  781. X0x10000000,0x12000000,0x10002000,0x12002000,
  782. X0x10200000,0x12200000,0x10202000,0x12202000,
  783. X0x10000004,0x12000004,0x10002004,0x12002004,
  784. X0x10200004,0x12200004,0x10202004,0x12202004,
  785. X0x10000400,0x12000400,0x10002400,0x12002400,
  786. X0x10200400,0x12200400,0x10202400,0x12202400,
  787. X0x10000404,0x12000404,0x10002404,0x12002404,
  788. X0x10200404,0x12200404,0x10202404,0x12202404,
  789. X/* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
  790. X0x00000000,0x00000001,0x00040000,0x00040001,
  791. X0x01000000,0x01000001,0x01040000,0x01040001,
  792. X0x00000002,0x00000003,0x00040002,0x00040003,
  793. X0x01000002,0x01000003,0x01040002,0x01040003,
  794. X0x00000200,0x00000201,0x00040200,0x00040201,
  795. X0x01000200,0x01000201,0x01040200,0x01040201,
  796. X0x00000202,0x00000203,0x00040202,0x00040203,
  797. X0x01000202,0x01000203,0x01040202,0x01040203,
  798. X0x08000000,0x08000001,0x08040000,0x08040001,
  799. X0x09000000,0x09000001,0x09040000,0x09040001,
  800. X0x08000002,0x08000003,0x08040002,0x08040003,
  801. X0x09000002,0x09000003,0x09040002,0x09040003,
  802. X0x08000200,0x08000201,0x08040200,0x08040201,
  803. X0x09000200,0x09000201,0x09040200,0x09040201,
  804. X0x08000202,0x08000203,0x08040202,0x08040203,
  805. X0x09000202,0x09000203,0x09040202,0x09040203,
  806. X/* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
  807. X0x00000000,0x00100000,0x00000100,0x00100100,
  808. X0x00000008,0x00100008,0x00000108,0x00100108,
  809. X0x00001000,0x00101000,0x00001100,0x00101100,
  810. X0x00001008,0x00101008,0x00001108,0x00101108,
  811. X0x04000000,0x04100000,0x04000100,0x04100100,
  812. X0x04000008,0x04100008,0x04000108,0x04100108,
  813. X0x04001000,0x04101000,0x04001100,0x04101100,
  814. X0x04001008,0x04101008,0x04001108,0x04101108,
  815. X0x00020000,0x00120000,0x00020100,0x00120100,
  816. X0x00020008,0x00120008,0x00020108,0x00120108,
  817. X0x00021000,0x00121000,0x00021100,0x00121100,
  818. X0x00021008,0x00121008,0x00021108,0x00121108,
  819. X0x04020000,0x04120000,0x04020100,0x04120100,
  820. X0x04020008,0x04120008,0x04020108,0x04120108,
  821. X0x04021000,0x04121000,0x04021100,0x04121100,
  822. X0x04021008,0x04121008,0x04021108,0x04121108,
  823. X/* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
  824. X0x00000000,0x10000000,0x00010000,0x10010000,
  825. X0x00000004,0x10000004,0x00010004,0x10010004,
  826. X0x20000000,0x30000000,0x20010000,0x30010000,
  827. X0x20000004,0x30000004,0x20010004,0x30010004,
  828. X0x00100000,0x10100000,0x00110000,0x10110000,
  829. X0x00100004,0x10100004,0x00110004,0x10110004,
  830. X0x20100000,0x30100000,0x20110000,0x30110000,
  831. X0x20100004,0x30100004,0x20110004,0x30110004,
  832. X0x00001000,0x10001000,0x00011000,0x10011000,
  833. X0x00001004,0x10001004,0x00011004,0x10011004,
  834. X0x20001000,0x30001000,0x20011000,0x30011000,
  835. X0x20001004,0x30001004,0x20011004,0x30011004,
  836. X0x00101000,0x10101000,0x00111000,0x10111000,
  837. X0x00101004,0x10101004,0x00111004,0x10111004,
  838. X0x20101000,0x30101000,0x20111000,0x30111000,
  839. X0x20101004,0x30101004,0x20111004,0x30111004,
  840. X/* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
  841. X0x00000000,0x08000000,0x00000008,0x08000008,
  842. X0x00000400,0x08000400,0x00000408,0x08000408,
  843. X0x00020000,0x08020000,0x00020008,0x08020008,
  844. X0x00020400,0x08020400,0x00020408,0x08020408,
  845. X0x00000001,0x08000001,0x00000009,0x08000009,
  846. X0x00000401,0x08000401,0x00000409,0x08000409,
  847. X0x00020001,0x08020001,0x00020009,0x08020009,
  848. X0x00020401,0x08020401,0x00020409,0x08020409,
  849. X0x02000000,0x0A000000,0x02000008,0x0A000008,
  850. X0x02000400,0x0A000400,0x02000408,0x0A000408,
  851. X0x02020000,0x0A020000,0x02020008,0x0A020008,
  852. X0x02020400,0x0A020400,0x02020408,0x0A020408,
  853. X0x02000001,0x0A000001,0x02000009,0x0A000009,
  854. X0x02000401,0x0A000401,0x02000409,0x0A000409,
  855. X0x02020001,0x0A020001,0x02020009,0x0A020009,
  856. X0x02020401,0x0A020401,0x02020409,0x0A020409,
  857. X/* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
  858. X0x00000000,0x00000100,0x00080000,0x00080100,
  859. X0x01000000,0x01000100,0x01080000,0x01080100,
  860. X0x00000010,0x00000110,0x00080010,0x00080110,
  861. X0x01000010,0x01000110,0x01080010,0x01080110,
  862. X0x00200000,0x00200100,0x00280000,0x00280100,
  863. X0x01200000,0x01200100,0x01280000,0x01280100,
  864. X0x00200010,0x00200110,0x00280010,0x00280110,
  865. X0x01200010,0x01200110,0x01280010,0x01280110,
  866. X0x00000200,0x00000300,0x00080200,0x00080300,
  867. X0x01000200,0x01000300,0x01080200,0x01080300,
  868. X0x00000210,0x00000310,0x00080210,0x00080310,
  869. X0x01000210,0x01000310,0x01080210,0x01080310,
  870. X0x00200200,0x00200300,0x00280200,0x00280300,
  871. X0x01200200,0x01200300,0x01280200,0x01280300,
  872. X0x00200210,0x00200310,0x00280210,0x00280310,
  873. X0x01200210,0x01200310,0x01280210,0x01280310,
  874. X/* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
  875. X0x00000000,0x04000000,0x00040000,0x04040000,
  876. X0x00000002,0x04000002,0x00040002,0x04040002,
  877. X0x00002000,0x04002000,0x00042000,0x04042000,
  878. X0x00002002,0x04002002,0x00042002,0x04042002,
  879. X0x00000020,0x04000020,0x00040020,0x04040020,
  880. X0x00000022,0x04000022,0x00040022,0x04040022,
  881. X0x00002020,0x04002020,0x00042020,0x04042020,
  882. X0x00002022,0x04002022,0x00042022,0x04042022,
  883. X0x00000800,0x04000800,0x00040800,0x04040800,
  884. X0x00000802,0x04000802,0x00040802,0x04040802,
  885. X0x00002800,0x04002800,0x00042800,0x04042800,
  886. X0x00002802,0x04002802,0x00042802,0x04042802,
  887. X0x00000820,0x04000820,0x00040820,0x04040820,
  888. X0x00000822,0x04000822,0x00040822,0x04040822,
  889. X0x00002820,0x04002820,0x00042820,0x04042820,
  890. X0x00002822,0x04002822,0x00042822,0x04042822,
  891. X};
  892. X
  893. X/* See ecb_encrypt.c for a pseudo description of these macros. */
  894. X#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
  895. X    (b)^=(t),\
  896. X    (a)^=((t)<<(n)))
  897. X
  898. X#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
  899. X    (a)=(a)^(t)^(t>>(16-(n))))\
  900. X
  901. Xstatic char shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
  902. X
  903. Xstatic int body();
  904. X
  905. Xstatic int des_set_key(key,schedule)
  906. Xdes_cblock *key;
  907. Xdes_key_schedule schedule;
  908. X    {
  909. X    register unsigned long c,d,t,s;
  910. X    register unsigned char *in;
  911. X    unsigned long *k;
  912. X    register int i;
  913. X
  914. X    k=(unsigned long *)schedule;
  915. X    in=(uchar *)key;
  916. X
  917. X    c2l(in,c);
  918. X    c2l(in,d);
  919. X
  920. X    /* do PC1 in 60 simple operations */ 
  921. X    PERM_OP(d,c,t,4,0x0f0f0f0f);
  922. X    HPERM_OP(c,t,-2, 0xcccc0000);
  923. X    HPERM_OP(c,t,-1, 0xaaaa0000);
  924. X    HPERM_OP(c,t, 8, 0x00ff0000);
  925. X    HPERM_OP(c,t,-1, 0xaaaa0000);
  926. X    HPERM_OP(d,t,-8, 0xff000000);
  927. X    HPERM_OP(d,t, 8, 0x00ff0000);
  928. X    HPERM_OP(d,t, 2, 0x33330000);
  929. X    d=((d&0x00aa00aa)<<7)|((d&0x55005500)>>7)|(d&0xaa55aa55);
  930. X    d=(d>>8)|((c&0xf0000000)>>4);
  931. X    c&=0x0fffffff;
  932. X
  933. X    for (i=0; i<ITERATIONS; i++)
  934. X        {
  935. X        if (shifts2[i])
  936. X            { c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26)); }
  937. X        else
  938. X            { c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); }
  939. X        c&=0x0fffffff;
  940. X        d&=0x0fffffff;
  941. X        /* could be a few less shifts but I am to lazy at this
  942. X         * point in time to investigate */
  943. X        s=    skb[0][ (c    )&0x3f                ]|
  944. X            skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]|
  945. X            skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]|
  946. X            skb[3][((c>>20)&0x01)|((c>>21)&0x06) |
  947. X                                  ((c>>22)&0x38)];
  948. X        t=    skb[4][ (d    )&0x3f                ]|
  949. X            skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]|
  950. X            skb[6][ (d>>15)&0x3f                ]|
  951. X            skb[7][((d>>21)&0x0f)|((d>>22)&0x30)];
  952. X
  953. X        /* table contained 0213 4657 */
  954. X        *(k++)=((t<<16)|(s&0x0000ffff));
  955. X        s=     ((s>>16)|(t&0xffff0000));
  956. X        
  957. X        s=(s<<4)|(s>>28);
  958. X        *(k++)=s;
  959. X        }
  960. X    return(0);
  961. X    }
  962. X
  963. X/******************************************************************
  964. X * modified stuff for crypt.
  965. X ******************************************************************/
  966. X
  967. X#define D_ENCRYPT(L,R,S)    \
  968. X    t=(R<<1)|(R>>31); \
  969. X    v=(t^(t>>16)); \
  970. X    u=(v&E0); \
  971. X    v=(v&E1); \
  972. X    u=(u^(u<<16))^t^s[S  ]; \
  973. X    t=(v^(v<<16))^t^s[S+1]; \
  974. X    t=(t>>4)|(t<<28); \
  975. X    L^=    SPtrans[1][(t    )&0x3f]| \
  976. X        SPtrans[3][(t>> 8)&0x3f]| \
  977. X        SPtrans[5][(t>>16)&0x3f]| \
  978. X        SPtrans[7][(t>>24)&0x3f]| \
  979. X        SPtrans[0][(u    )&0x3f]| \
  980. X        SPtrans[2][(u>> 8)&0x3f]| \
  981. X        SPtrans[4][(u>>16)&0x3f]| \
  982. X        SPtrans[6][(u>>24)&0x3f];
  983. X
  984. X#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
  985. X    (b)^=(t),\
  986. X    (a)^=((t)<<(n)))
  987. X
  988. Xuchar con_salt[128]={
  989. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  990. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  991. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  992. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  993. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  994. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  995. X0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
  996. X0x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
  997. X0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
  998. X0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
  999. X0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
  1000. X0x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
  1001. X0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
  1002. X0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
  1003. X0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
  1004. X0x3D,0x3E,0x3F,0x00,0x00,0x00,0x00,0x00,
  1005. X};
  1006. X
  1007. Xuchar cov_2char[64]={
  1008. X0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
  1009. X0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
  1010. X0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
  1011. X0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
  1012. X0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
  1013. X0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
  1014. X0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
  1015. X0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
  1016. X};
  1017. X
  1018. Xchar *crypt(buf,salt)
  1019. Xchar *buf;
  1020. Xchar *salt;
  1021. X    {
  1022. X    unsigned int i,j,k,x,y;
  1023. X    ulong Eswap0=0,Eswap1=0;
  1024. X    ulong out[2],ll;
  1025. X    des_cblock key;
  1026. X    des_key_schedule ks;
  1027. X    static uchar buff[20];
  1028. X    uchar bb[9];
  1029. X    uchar *b=bb;
  1030. X    uchar c,u;
  1031. X
  1032. X    x=buff[0]=salt[0];
  1033. X    Eswap0=con_salt[x];
  1034. X    x=buff[1]=salt[1];
  1035. X    Eswap1=con_salt[x]<<4;
  1036. X
  1037. X    for (i=0; i<8; i++)
  1038. X        {
  1039. X        c= *(buf++);
  1040. X        if (!c) break;
  1041. X        key[i]=(c<<1);
  1042. X        }
  1043. X    for (; i<8; i++)
  1044. X        key[i]=0;
  1045. X
  1046. X    des_set_key((des_cblock *)(key),ks);
  1047. X    body(&out[0],&out[1],ks,Eswap0,Eswap1);
  1048. X
  1049. X    ll=out[0]; l2c(ll,b);
  1050. X    ll=out[1]; l2c(ll,b);
  1051. X    y=0;
  1052. X    u=0x80;
  1053. X    bb[8]=0;
  1054. X    for (i=2; i<13; i++)
  1055. X        {
  1056. X        c=0;
  1057. X        for (j=0; j<6; j++)
  1058. X            {
  1059. X            c<<=1;
  1060. X            if (bb[y] & u) c|=1;
  1061. X            u>>=1;
  1062. X            if (!u)
  1063. X                {
  1064. X                y++;
  1065. X                u=0x80;
  1066. X                }
  1067. X            }
  1068. X        buff[i]=cov_2char[c];
  1069. X        }
  1070. X    return((char *)buff);
  1071. X    }
  1072. X
  1073. Xstatic int body(out0,out1,ks,Eswap0,Eswap1)
  1074. Xulong *out0,*out1;
  1075. Xdes_key_schedule *ks;
  1076. Xulong Eswap0,Eswap1;
  1077. X    {
  1078. X    register unsigned long l,r,t,u,v;
  1079. X    register unsigned long *s;
  1080. X    register int i,j;
  1081. X    register unsigned long E0,E1;
  1082. X
  1083. X    l=0;
  1084. X    r=0;
  1085. X
  1086. X    s=(ulong *)ks;
  1087. X    E0=Eswap0;
  1088. X    E1=Eswap1;
  1089. X
  1090. X    for (j=0; j<25; j++)
  1091. X        {
  1092. X        for (i=0; i<(ITERATIONS*2); i+=4)
  1093. X            {
  1094. X            D_ENCRYPT(l,r,  i);    /*  1 */
  1095. X            D_ENCRYPT(r,l,  i+2);    /*  2 */
  1096. X            }
  1097. X        t=l;
  1098. X        l=r;
  1099. X        r=t;
  1100. X        }
  1101. X    t=l;
  1102. X    l=r;
  1103. X    r=t;
  1104. X    PERM_OP(r,l,t, 1,0x55555555);
  1105. X    PERM_OP(l,r,t, 8,0x00ff00ff);
  1106. X    PERM_OP(r,l,t, 2,0x33333333);
  1107. X    PERM_OP(l,r,t,16,0x0000ffff);
  1108. X    PERM_OP(r,l,t, 4,0x0f0f0f0f);
  1109. X
  1110. X    *out0=l;
  1111. X    *out1=r;
  1112. X    return(0);
  1113. X    }
  1114. END_OF_FILE
  1115. if test 18467 -ne `wc -c <'fcrypt.c'`; then
  1116.     echo shar: \"'fcrypt.c'\" unpacked with wrong size!
  1117. fi
  1118. # end of 'fcrypt.c'
  1119. fi
  1120. echo shar: End of archive 3 \(of 4\).
  1121. cp /dev/null ark3isdone
  1122. MISSING=""
  1123. for I in 1 2 3 4 ; do
  1124.     if test ! -f ark${I}isdone ; then
  1125.     MISSING="${MISSING} ${I}"
  1126.     fi
  1127. done
  1128. if test "${MISSING}" = "" ; then
  1129.     echo You have unpacked all 4 archives.
  1130.     rm -f ark[1-9]isdone
  1131. else
  1132.     echo You still need to unpack the following archives:
  1133.     echo "        " ${MISSING}
  1134. fi
  1135. ##  End of shell archive.
  1136. exit 0
  1137. exit 0 # Just in case...
  1138.