pdf2json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (473) hide show
  1. data/README.markdown +9 -0
  2. data/bin/.gitkeep +0 -0
  3. data/ext/extconf.rb +30 -0
  4. data/lib/pdf2json.rb +8 -0
  5. data/pdf2json-0.52-source/AUTHORS +24 -0
  6. data/pdf2json-0.52-source/CHANGES +11 -0
  7. data/pdf2json-0.52-source/Makefile +84 -0
  8. data/pdf2json-0.52-source/Makefile.in +84 -0
  9. data/pdf2json-0.52-source/aclocal.m4 +274 -0
  10. data/pdf2json-0.52-source/aconf-win32.h +86 -0
  11. data/pdf2json-0.52-source/aconf.h +42 -0
  12. data/pdf2json-0.52-source/aconf.h.in +41 -0
  13. data/pdf2json-0.52-source/autom4te.cache/output.0 +6908 -0
  14. data/pdf2json-0.52-source/autom4te.cache/requests +76 -0
  15. data/pdf2json-0.52-source/autom4te.cache/traces.0 +466 -0
  16. data/pdf2json-0.52-source/config.log +1259 -0
  17. data/pdf2json-0.52-source/config.status +1050 -0
  18. data/pdf2json-0.52-source/configure +6908 -0
  19. data/pdf2json-0.52-source/configure.ac +93 -0
  20. data/pdf2json-0.52-source/doc/pdffonts.1 +130 -0
  21. data/pdf2json-0.52-source/doc/pdffonts.cat +107 -0
  22. data/pdf2json-0.52-source/doc/pdffonts.hlp +117 -0
  23. data/pdf2json-0.52-source/doc/pdfimages.1 +102 -0
  24. data/pdf2json-0.52-source/doc/pdfimages.cat +92 -0
  25. data/pdf2json-0.52-source/doc/pdfimages.hlp +101 -0
  26. data/pdf2json-0.52-source/doc/pdfinfo.1 +158 -0
  27. data/pdf2json-0.52-source/doc/pdfinfo.cat +119 -0
  28. data/pdf2json-0.52-source/doc/pdfinfo.hlp +129 -0
  29. data/pdf2json-0.52-source/doc/pdftoppm.1 +115 -0
  30. data/pdf2json-0.52-source/doc/pdftoppm.cat +105 -0
  31. data/pdf2json-0.52-source/doc/pdftoppm.hlp +114 -0
  32. data/pdf2json-0.52-source/doc/pdftops.1 +229 -0
  33. data/pdf2json-0.52-source/doc/pdftops.cat +221 -0
  34. data/pdf2json-0.52-source/doc/pdftops.hlp +231 -0
  35. data/pdf2json-0.52-source/doc/pdftotext.1 +137 -0
  36. data/pdf2json-0.52-source/doc/pdftotext.cat +120 -0
  37. data/pdf2json-0.52-source/doc/pdftotext.hlp +133 -0
  38. data/pdf2json-0.52-source/doc/sample-xpdfrc +91 -0
  39. data/pdf2json-0.52-source/doc/xpdf.1 +513 -0
  40. data/pdf2json-0.52-source/doc/xpdf.cat +476 -0
  41. data/pdf2json-0.52-source/doc/xpdf.hlp +489 -0
  42. data/pdf2json-0.52-source/doc/xpdfrc.5 +480 -0
  43. data/pdf2json-0.52-source/doc/xpdfrc.cat +474 -0
  44. data/pdf2json-0.52-source/doc/xpdfrc.hlp +479 -0
  45. data/pdf2json-0.52-source/fofi/.DS_Store +0 -0
  46. data/pdf2json-0.52-source/fofi/FoFiBase.cc +156 -0
  47. data/pdf2json-0.52-source/fofi/FoFiBase.h +57 -0
  48. data/pdf2json-0.52-source/fofi/FoFiBase.o +0 -0
  49. data/pdf2json-0.52-source/fofi/FoFiEncodings.cc +994 -0
  50. data/pdf2json-0.52-source/fofi/FoFiEncodings.h +36 -0
  51. data/pdf2json-0.52-source/fofi/FoFiEncodings.o +0 -0
  52. data/pdf2json-0.52-source/fofi/FoFiTrueType.cc +2027 -0
  53. data/pdf2json-0.52-source/fofi/FoFiTrueType.h +174 -0
  54. data/pdf2json-0.52-source/fofi/FoFiTrueType.o +0 -0
  55. data/pdf2json-0.52-source/fofi/FoFiType1.cc +252 -0
  56. data/pdf2json-0.52-source/fofi/FoFiType1.h +59 -0
  57. data/pdf2json-0.52-source/fofi/FoFiType1.o +0 -0
  58. data/pdf2json-0.52-source/fofi/FoFiType1C.cc +2603 -0
  59. data/pdf2json-0.52-source/fofi/FoFiType1C.h +233 -0
  60. data/pdf2json-0.52-source/fofi/FoFiType1C.o +0 -0
  61. data/pdf2json-0.52-source/fofi/Makefile +70 -0
  62. data/pdf2json-0.52-source/fofi/Makefile.dep +0 -0
  63. data/pdf2json-0.52-source/fofi/Makefile.in +70 -0
  64. data/pdf2json-0.52-source/fofi/libfofi.a +0 -0
  65. data/pdf2json-0.52-source/fofi/vms_make.com +0 -0
  66. data/pdf2json-0.52-source/freetype.win32/.DS_Store +0 -0
  67. data/pdf2json-0.52-source/freetype.win32/include/.DS_Store +0 -0
  68. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftconfig.h +528 -0
  69. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftheader.h +780 -0
  70. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftmodule.h +32 -0
  71. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftoption.h +733 -0
  72. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftstdlib.h +173 -0
  73. data/pdf2json-0.52-source/freetype.win32/include/freetype/freetype.h +3919 -0
  74. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftadvanc.h +179 -0
  75. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftbbox.h +94 -0
  76. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftbdf.h +209 -0
  77. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftbitmap.h +227 -0
  78. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftcache.h +1128 -0
  79. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftchapters.h +103 -0
  80. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftcid.h +166 -0
  81. data/pdf2json-0.52-source/freetype.win32/include/freetype/fterrdef.h +244 -0
  82. data/pdf2json-0.52-source/freetype.win32/include/freetype/fterrors.h +206 -0
  83. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftgasp.h +120 -0
  84. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftglyph.h +613 -0
  85. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftgxval.h +358 -0
  86. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftgzip.h +102 -0
  87. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftimage.h +1313 -0
  88. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftincrem.h +353 -0
  89. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftlcdfil.h +213 -0
  90. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftlist.h +277 -0
  91. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftlzw.h +99 -0
  92. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmac.h +274 -0
  93. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmm.h +378 -0
  94. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmodapi.h +483 -0
  95. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmoderr.h +155 -0
  96. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftotval.h +203 -0
  97. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftoutln.h +537 -0
  98. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftpfr.h +172 -0
  99. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftrender.h +230 -0
  100. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsizes.h +159 -0
  101. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsnames.h +200 -0
  102. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftstroke.h +716 -0
  103. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsynth.h +80 -0
  104. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsystem.h +347 -0
  105. data/pdf2json-0.52-source/freetype.win32/include/freetype/fttrigon.h +350 -0
  106. data/pdf2json-0.52-source/freetype.win32/include/freetype/fttypes.h +588 -0
  107. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftwinfnt.h +274 -0
  108. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftxf86.h +83 -0
  109. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/autohint.h +231 -0
  110. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftcalc.h +179 -0
  111. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftdebug.h +250 -0
  112. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftdriver.h +422 -0
  113. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftgloadr.h +168 -0
  114. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftmemory.h +380 -0
  115. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftobjs.h +1428 -0
  116. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftpic.h +67 -0
  117. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftrfork.h +196 -0
  118. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftserv.h +620 -0
  119. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftstream.h +539 -0
  120. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/fttrace.h +139 -0
  121. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftvalid.h +150 -0
  122. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/internal.h +51 -0
  123. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/pcftypes.h +56 -0
  124. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/psaux.h +873 -0
  125. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/pshints.h +712 -0
  126. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svbdf.h +77 -0
  127. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svcid.h +83 -0
  128. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svgldict.h +82 -0
  129. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svgxval.h +72 -0
  130. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svkern.h +51 -0
  131. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svmm.h +104 -0
  132. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svotval.h +55 -0
  133. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpfr.h +66 -0
  134. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpostnm.h +79 -0
  135. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpscmap.h +164 -0
  136. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpsinfo.h +92 -0
  137. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svsfnt.h +102 -0
  138. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svttcmap.h +106 -0
  139. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svtteng.h +53 -0
  140. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svttglyf.h +67 -0
  141. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svwinfnt.h +50 -0
  142. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svxf86nm.h +55 -0
  143. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/sfnt.h +897 -0
  144. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/t1types.h +270 -0
  145. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/tttypes.h +1543 -0
  146. data/pdf2json-0.52-source/freetype.win32/include/freetype/t1tables.h +504 -0
  147. data/pdf2json-0.52-source/freetype.win32/include/freetype/ttnameid.h +1247 -0
  148. data/pdf2json-0.52-source/freetype.win32/include/freetype/tttables.h +759 -0
  149. data/pdf2json-0.52-source/freetype.win32/include/freetype/tttags.h +107 -0
  150. data/pdf2json-0.52-source/freetype.win32/include/freetype/ttunpat.h +59 -0
  151. data/pdf2json-0.52-source/freetype.win32/include/ft2build.h +39 -0
  152. data/pdf2json-0.52-source/freetype.win32/lib/freetype_a.lib +0 -0
  153. data/pdf2json-0.52-source/goo/.DS_Store +0 -0
  154. data/pdf2json-0.52-source/goo/FixedPoint.cc +118 -0
  155. data/pdf2json-0.52-source/goo/FixedPoint.h +155 -0
  156. data/pdf2json-0.52-source/goo/FixedPoint.o +0 -0
  157. data/pdf2json-0.52-source/goo/GHash.cc +380 -0
  158. data/pdf2json-0.52-source/goo/GHash.h +78 -0
  159. data/pdf2json-0.52-source/goo/GHash.o +0 -0
  160. data/pdf2json-0.52-source/goo/GList.cc +97 -0
  161. data/pdf2json-0.52-source/goo/GList.h +96 -0
  162. data/pdf2json-0.52-source/goo/GList.o +0 -0
  163. data/pdf2json-0.52-source/goo/GMutex.h +49 -0
  164. data/pdf2json-0.52-source/goo/GString.cc +724 -0
  165. data/pdf2json-0.52-source/goo/GString.cc.fixed +718 -0
  166. data/pdf2json-0.52-source/goo/GString.h +136 -0
  167. data/pdf2json-0.52-source/goo/GString.o +0 -0
  168. data/pdf2json-0.52-source/goo/ImgWriter.o +0 -0
  169. data/pdf2json-0.52-source/goo/JpegWriter.o +0 -0
  170. data/pdf2json-0.52-source/goo/Makefile +72 -0
  171. data/pdf2json-0.52-source/goo/Makefile.dep +0 -0
  172. data/pdf2json-0.52-source/goo/Makefile.in +72 -0
  173. data/pdf2json-0.52-source/goo/PNGWriter.o +0 -0
  174. data/pdf2json-0.52-source/goo/gfile.cc +731 -0
  175. data/pdf2json-0.52-source/goo/gfile.h +138 -0
  176. data/pdf2json-0.52-source/goo/gfile.o +0 -0
  177. data/pdf2json-0.52-source/goo/gmem.cc +264 -0
  178. data/pdf2json-0.52-source/goo/gmem.h +79 -0
  179. data/pdf2json-0.52-source/goo/gmem.o +0 -0
  180. data/pdf2json-0.52-source/goo/gmempp.cc +32 -0
  181. data/pdf2json-0.52-source/goo/gmempp.o +0 -0
  182. data/pdf2json-0.52-source/goo/gtypes.h +29 -0
  183. data/pdf2json-0.52-source/goo/libGoo.a +0 -0
  184. data/pdf2json-0.52-source/goo/parseargs.c +190 -0
  185. data/pdf2json-0.52-source/goo/parseargs.h +71 -0
  186. data/pdf2json-0.52-source/goo/parseargs.o +0 -0
  187. data/pdf2json-0.52-source/goo/vms_directory.c +214 -0
  188. data/pdf2json-0.52-source/goo/vms_dirent.h +67 -0
  189. data/pdf2json-0.52-source/goo/vms_make.com +82 -0
  190. data/pdf2json-0.52-source/goo/vms_sys_dirent.h +54 -0
  191. data/pdf2json-0.52-source/goo/vms_unix_time.h +102 -0
  192. data/pdf2json-0.52-source/goo/vms_unix_times.c +42 -0
  193. data/pdf2json-0.52-source/goo/vms_unlink.c +22 -0
  194. data/pdf2json-0.52-source/ms_make.bat +199 -0
  195. data/pdf2json-0.52-source/splash/.DS_Store +0 -0
  196. data/pdf2json-0.52-source/splash/Makefile +103 -0
  197. data/pdf2json-0.52-source/splash/Makefile.dep +0 -0
  198. data/pdf2json-0.52-source/splash/Makefile.in +103 -0
  199. data/pdf2json-0.52-source/splash/Splash.cc +3310 -0
  200. data/pdf2json-0.52-source/splash/Splash.h +293 -0
  201. data/pdf2json-0.52-source/splash/Splash.o +0 -0
  202. data/pdf2json-0.52-source/splash/SplashBitmap.cc +188 -0
  203. data/pdf2json-0.52-source/splash/SplashBitmap.h +64 -0
  204. data/pdf2json-0.52-source/splash/SplashBitmap.o +0 -0
  205. data/pdf2json-0.52-source/splash/SplashClip.cc +382 -0
  206. data/pdf2json-0.52-source/splash/SplashClip.h +107 -0
  207. data/pdf2json-0.52-source/splash/SplashClip.o +0 -0
  208. data/pdf2json-0.52-source/splash/SplashErrorCodes.h +32 -0
  209. data/pdf2json-0.52-source/splash/SplashFTFont.cc +357 -0
  210. data/pdf2json-0.52-source/splash/SplashFTFont.h +58 -0
  211. data/pdf2json-0.52-source/splash/SplashFTFont.o +0 -0
  212. data/pdf2json-0.52-source/splash/SplashFTFontEngine.cc +179 -0
  213. data/pdf2json-0.52-source/splash/SplashFTFontEngine.h +65 -0
  214. data/pdf2json-0.52-source/splash/SplashFTFontEngine.o +0 -0
  215. data/pdf2json-0.52-source/splash/SplashFTFontFile.cc +114 -0
  216. data/pdf2json-0.52-source/splash/SplashFTFontFile.h +73 -0
  217. data/pdf2json-0.52-source/splash/SplashFTFontFile.o +0 -0
  218. data/pdf2json-0.52-source/splash/SplashFont.cc +176 -0
  219. data/pdf2json-0.52-source/splash/SplashFont.h +104 -0
  220. data/pdf2json-0.52-source/splash/SplashFont.o +0 -0
  221. data/pdf2json-0.52-source/splash/SplashFontEngine.cc +317 -0
  222. data/pdf2json-0.52-source/splash/SplashFontEngine.h +91 -0
  223. data/pdf2json-0.52-source/splash/SplashFontEngine.o +0 -0
  224. data/pdf2json-0.52-source/splash/SplashFontFile.cc +55 -0
  225. data/pdf2json-0.52-source/splash/SplashFontFile.h +60 -0
  226. data/pdf2json-0.52-source/splash/SplashFontFile.o +0 -0
  227. data/pdf2json-0.52-source/splash/SplashFontFileID.cc +23 -0
  228. data/pdf2json-0.52-source/splash/SplashFontFileID.h +30 -0
  229. data/pdf2json-0.52-source/splash/SplashFontFileID.o +0 -0
  230. data/pdf2json-0.52-source/splash/SplashGlyphBitmap.h +26 -0
  231. data/pdf2json-0.52-source/splash/SplashMath.h +89 -0
  232. data/pdf2json-0.52-source/splash/SplashPath.cc +184 -0
  233. data/pdf2json-0.52-source/splash/SplashPath.h +121 -0
  234. data/pdf2json-0.52-source/splash/SplashPath.o +0 -0
  235. data/pdf2json-0.52-source/splash/SplashPattern.cc +40 -0
  236. data/pdf2json-0.52-source/splash/SplashPattern.h +65 -0
  237. data/pdf2json-0.52-source/splash/SplashPattern.o +0 -0
  238. data/pdf2json-0.52-source/splash/SplashScreen.cc +383 -0
  239. data/pdf2json-0.52-source/splash/SplashScreen.h +56 -0
  240. data/pdf2json-0.52-source/splash/SplashScreen.o +0 -0
  241. data/pdf2json-0.52-source/splash/SplashState.cc +165 -0
  242. data/pdf2json-0.52-source/splash/SplashState.h +103 -0
  243. data/pdf2json-0.52-source/splash/SplashState.o +0 -0
  244. data/pdf2json-0.52-source/splash/SplashT1Font.cc +287 -0
  245. data/pdf2json-0.52-source/splash/SplashT1Font.h +57 -0
  246. data/pdf2json-0.52-source/splash/SplashT1Font.o +0 -0
  247. data/pdf2json-0.52-source/splash/SplashT1FontEngine.cc +124 -0
  248. data/pdf2json-0.52-source/splash/SplashT1FontEngine.h +53 -0
  249. data/pdf2json-0.52-source/splash/SplashT1FontEngine.o +0 -0
  250. data/pdf2json-0.52-source/splash/SplashT1FontFile.cc +97 -0
  251. data/pdf2json-0.52-source/splash/SplashT1FontFile.h +58 -0
  252. data/pdf2json-0.52-source/splash/SplashT1FontFile.o +0 -0
  253. data/pdf2json-0.52-source/splash/SplashTypes.h +132 -0
  254. data/pdf2json-0.52-source/splash/SplashXPath.cc +438 -0
  255. data/pdf2json-0.52-source/splash/SplashXPath.h +100 -0
  256. data/pdf2json-0.52-source/splash/SplashXPath.o +0 -0
  257. data/pdf2json-0.52-source/splash/SplashXPathScanner.cc +428 -0
  258. data/pdf2json-0.52-source/splash/SplashXPathScanner.h +87 -0
  259. data/pdf2json-0.52-source/splash/SplashXPathScanner.o +0 -0
  260. data/pdf2json-0.52-source/splash/libsplash.a +0 -0
  261. data/pdf2json-0.52-source/splash/vms_make.com +0 -0
  262. data/pdf2json-0.52-source/src/.DS_Store +0 -0
  263. data/pdf2json-0.52-source/src/GVector.h +101 -0
  264. data/pdf2json-0.52-source/src/ImgOutputDev.cc +1243 -0
  265. data/pdf2json-0.52-source/src/ImgOutputDev.h +307 -0
  266. data/pdf2json-0.52-source/src/ImgOutputDev.o +0 -0
  267. data/pdf2json-0.52-source/src/Makefile +68 -0
  268. data/pdf2json-0.52-source/src/Makefile.in +68 -0
  269. data/pdf2json-0.52-source/src/XmlFonts.cc +367 -0
  270. data/pdf2json-0.52-source/src/XmlFonts.h +91 -0
  271. data/pdf2json-0.52-source/src/XmlFonts.o +0 -0
  272. data/pdf2json-0.52-source/src/XmlLinks.cc +101 -0
  273. data/pdf2json-0.52-source/src/XmlLinks.h +54 -0
  274. data/pdf2json-0.52-source/src/XmlLinks.o +0 -0
  275. data/pdf2json-0.52-source/src/pdf2json +0 -0
  276. data/pdf2json-0.52-source/src/pdf2json.cc +343 -0
  277. data/pdf2json-0.52-source/src/pdf2json.o +0 -0
  278. data/pdf2json-0.52-source/src/pdf2xml.dtd +22 -0
  279. data/pdf2json-0.52-source/src/pdf2xmljson.dtd +9 -0
  280. data/pdf2json-0.52-source/xpdf/.DS_Store +0 -0
  281. data/pdf2json-0.52-source/xpdf/Annot.cc +1556 -0
  282. data/pdf2json-0.52-source/xpdf/Annot.h +142 -0
  283. data/pdf2json-0.52-source/xpdf/Annot.o +0 -0
  284. data/pdf2json-0.52-source/xpdf/Array.cc +73 -0
  285. data/pdf2json-0.52-source/xpdf/Array.h +58 -0
  286. data/pdf2json-0.52-source/xpdf/Array.o +0 -0
  287. data/pdf2json-0.52-source/xpdf/BuiltinFont.cc +65 -0
  288. data/pdf2json-0.52-source/xpdf/BuiltinFont.h +57 -0
  289. data/pdf2json-0.52-source/xpdf/BuiltinFont.o +0 -0
  290. data/pdf2json-0.52-source/xpdf/BuiltinFontTables.cc +4284 -0
  291. data/pdf2json-0.52-source/xpdf/BuiltinFontTables.h +23 -0
  292. data/pdf2json-0.52-source/xpdf/BuiltinFontTables.o +0 -0
  293. data/pdf2json-0.52-source/xpdf/CMap.cc +408 -0
  294. data/pdf2json-0.52-source/xpdf/CMap.h +102 -0
  295. data/pdf2json-0.52-source/xpdf/CMap.o +0 -0
  296. data/pdf2json-0.52-source/xpdf/Catalog.cc +374 -0
  297. data/pdf2json-0.52-source/xpdf/Catalog.h +97 -0
  298. data/pdf2json-0.52-source/xpdf/Catalog.o +0 -0
  299. data/pdf2json-0.52-source/xpdf/CharCodeToUnicode.cc +540 -0
  300. data/pdf2json-0.52-source/xpdf/CharCodeToUnicode.h +117 -0
  301. data/pdf2json-0.52-source/xpdf/CharCodeToUnicode.o +0 -0
  302. data/pdf2json-0.52-source/xpdf/CharTypes.h +24 -0
  303. data/pdf2json-0.52-source/xpdf/CompactFontTables.h +464 -0
  304. data/pdf2json-0.52-source/xpdf/CoreOutputDev.cc +61 -0
  305. data/pdf2json-0.52-source/xpdf/CoreOutputDev.h +61 -0
  306. data/pdf2json-0.52-source/xpdf/Decrypt.cc +776 -0
  307. data/pdf2json-0.52-source/xpdf/Decrypt.h +95 -0
  308. data/pdf2json-0.52-source/xpdf/Decrypt.o +0 -0
  309. data/pdf2json-0.52-source/xpdf/Dict.cc +95 -0
  310. data/pdf2json-0.52-source/xpdf/Dict.h +77 -0
  311. data/pdf2json-0.52-source/xpdf/Dict.o +0 -0
  312. data/pdf2json-0.52-source/xpdf/Error.cc +38 -0
  313. data/pdf2json-0.52-source/xpdf/Error.h +23 -0
  314. data/pdf2json-0.52-source/xpdf/Error.o +0 -0
  315. data/pdf2json-0.52-source/xpdf/ErrorCodes.h +36 -0
  316. data/pdf2json-0.52-source/xpdf/FontEncodingTables.cc +1824 -0
  317. data/pdf2json-0.52-source/xpdf/FontEncodingTables.h +20 -0
  318. data/pdf2json-0.52-source/xpdf/FontEncodingTables.o +0 -0
  319. data/pdf2json-0.52-source/xpdf/Function.cc +1573 -0
  320. data/pdf2json-0.52-source/xpdf/Function.h +229 -0
  321. data/pdf2json-0.52-source/xpdf/Function.o +0 -0
  322. data/pdf2json-0.52-source/xpdf/Gfx.cc +4187 -0
  323. data/pdf2json-0.52-source/xpdf/Gfx.h +312 -0
  324. data/pdf2json-0.52-source/xpdf/Gfx.o +0 -0
  325. data/pdf2json-0.52-source/xpdf/GfxFont.cc +1568 -0
  326. data/pdf2json-0.52-source/xpdf/GfxFont.h +320 -0
  327. data/pdf2json-0.52-source/xpdf/GfxFont.o +0 -0
  328. data/pdf2json-0.52-source/xpdf/GfxState.cc +4137 -0
  329. data/pdf2json-0.52-source/xpdf/GfxState.h +1244 -0
  330. data/pdf2json-0.52-source/xpdf/GfxState.o +0 -0
  331. data/pdf2json-0.52-source/xpdf/GlobalParams.cc +2924 -0
  332. data/pdf2json-0.52-source/xpdf/GlobalParams.cc.old +2908 -0
  333. data/pdf2json-0.52-source/xpdf/GlobalParams.h +466 -0
  334. data/pdf2json-0.52-source/xpdf/GlobalParams.h.old +463 -0
  335. data/pdf2json-0.52-source/xpdf/GlobalParams.o +0 -0
  336. data/pdf2json-0.52-source/xpdf/ImageOutputDev.cc +195 -0
  337. data/pdf2json-0.52-source/xpdf/ImageOutputDev.h +76 -0
  338. data/pdf2json-0.52-source/xpdf/ImageOutputDev.o +0 -0
  339. data/pdf2json-0.52-source/xpdf/JArithmeticDecoder.cc +322 -0
  340. data/pdf2json-0.52-source/xpdf/JArithmeticDecoder.h +109 -0
  341. data/pdf2json-0.52-source/xpdf/JArithmeticDecoder.o +0 -0
  342. data/pdf2json-0.52-source/xpdf/JBIG2Stream.cc +3413 -0
  343. data/pdf2json-0.52-source/xpdf/JBIG2Stream.h +145 -0
  344. data/pdf2json-0.52-source/xpdf/JBIG2Stream.o +0 -0
  345. data/pdf2json-0.52-source/xpdf/JPXStream.cc +3144 -0
  346. data/pdf2json-0.52-source/xpdf/JPXStream.h +351 -0
  347. data/pdf2json-0.52-source/xpdf/JPXStream.o +0 -0
  348. data/pdf2json-0.52-source/xpdf/Lexer.cc +485 -0
  349. data/pdf2json-0.52-source/xpdf/Lexer.h +80 -0
  350. data/pdf2json-0.52-source/xpdf/Lexer.o +0 -0
  351. data/pdf2json-0.52-source/xpdf/Link.cc +806 -0
  352. data/pdf2json-0.52-source/xpdf/Link.cc.old +784 -0
  353. data/pdf2json-0.52-source/xpdf/Link.h +415 -0
  354. data/pdf2json-0.52-source/xpdf/Link.h.old +369 -0
  355. data/pdf2json-0.52-source/xpdf/Link.o +0 -0
  356. data/pdf2json-0.52-source/xpdf/Makefile +232 -0
  357. data/pdf2json-0.52-source/xpdf/Makefile.dep +0 -0
  358. data/pdf2json-0.52-source/xpdf/Makefile.in +232 -0
  359. data/pdf2json-0.52-source/xpdf/NameToCharCode.cc +116 -0
  360. data/pdf2json-0.52-source/xpdf/NameToCharCode.h +42 -0
  361. data/pdf2json-0.52-source/xpdf/NameToCharCode.o +0 -0
  362. data/pdf2json-0.52-source/xpdf/NameToUnicodeTable.h +1097 -0
  363. data/pdf2json-0.52-source/xpdf/Object.cc +231 -0
  364. data/pdf2json-0.52-source/xpdf/Object.h +303 -0
  365. data/pdf2json-0.52-source/xpdf/Object.o +0 -0
  366. data/pdf2json-0.52-source/xpdf/Outline.cc +151 -0
  367. data/pdf2json-0.52-source/xpdf/Outline.h +76 -0
  368. data/pdf2json-0.52-source/xpdf/Outline.o +0 -0
  369. data/pdf2json-0.52-source/xpdf/OutputDev.cc +131 -0
  370. data/pdf2json-0.52-source/xpdf/OutputDev.h +253 -0
  371. data/pdf2json-0.52-source/xpdf/OutputDev.o +0 -0
  372. data/pdf2json-0.52-source/xpdf/PDFCore.cc +2044 -0
  373. data/pdf2json-0.52-source/xpdf/PDFCore.h +321 -0
  374. data/pdf2json-0.52-source/xpdf/PDFDoc.cc +404 -0
  375. data/pdf2json-0.52-source/xpdf/PDFDoc.h +183 -0
  376. data/pdf2json-0.52-source/xpdf/PDFDoc.o +0 -0
  377. data/pdf2json-0.52-source/xpdf/PDFDocEncoding.cc +44 -0
  378. data/pdf2json-0.52-source/xpdf/PDFDocEncoding.h +16 -0
  379. data/pdf2json-0.52-source/xpdf/PDFDocEncoding.o +0 -0
  380. data/pdf2json-0.52-source/xpdf/PSOutputDev.cc +6224 -0
  381. data/pdf2json-0.52-source/xpdf/PSOutputDev.h +395 -0
  382. data/pdf2json-0.52-source/xpdf/PSOutputDev.o +0 -0
  383. data/pdf2json-0.52-source/xpdf/PSTokenizer.cc +135 -0
  384. data/pdf2json-0.52-source/xpdf/PSTokenizer.h +41 -0
  385. data/pdf2json-0.52-source/xpdf/PSTokenizer.o +0 -0
  386. data/pdf2json-0.52-source/xpdf/Page.cc +454 -0
  387. data/pdf2json-0.52-source/xpdf/Page.h +187 -0
  388. data/pdf2json-0.52-source/xpdf/Page.o +0 -0
  389. data/pdf2json-0.52-source/xpdf/Parser.cc +227 -0
  390. data/pdf2json-0.52-source/xpdf/Parser.h +59 -0
  391. data/pdf2json-0.52-source/xpdf/Parser.o +0 -0
  392. data/pdf2json-0.52-source/xpdf/PreScanOutputDev.cc +257 -0
  393. data/pdf2json-0.52-source/xpdf/PreScanOutputDev.h +130 -0
  394. data/pdf2json-0.52-source/xpdf/PreScanOutputDev.o +0 -0
  395. data/pdf2json-0.52-source/xpdf/SecurityHandler.cc +390 -0
  396. data/pdf2json-0.52-source/xpdf/SecurityHandler.h +160 -0
  397. data/pdf2json-0.52-source/xpdf/SecurityHandler.o +0 -0
  398. data/pdf2json-0.52-source/xpdf/SplashOutputDev.cc +2845 -0
  399. data/pdf2json-0.52-source/xpdf/SplashOutputDev.h +247 -0
  400. data/pdf2json-0.52-source/xpdf/SplashOutputDev.o +0 -0
  401. data/pdf2json-0.52-source/xpdf/Stream-CCITT.h +459 -0
  402. data/pdf2json-0.52-source/xpdf/Stream.cc +4627 -0
  403. data/pdf2json-0.52-source/xpdf/Stream.h +858 -0
  404. data/pdf2json-0.52-source/xpdf/Stream.o +0 -0
  405. data/pdf2json-0.52-source/xpdf/TextOutputDev.cc +4090 -0
  406. data/pdf2json-0.52-source/xpdf/TextOutputDev.h +661 -0
  407. data/pdf2json-0.52-source/xpdf/TextOutputDev.o +0 -0
  408. data/pdf2json-0.52-source/xpdf/UTF8.h +56 -0
  409. data/pdf2json-0.52-source/xpdf/UnicodeMap.cc +302 -0
  410. data/pdf2json-0.52-source/xpdf/UnicodeMap.cc.old +293 -0
  411. data/pdf2json-0.52-source/xpdf/UnicodeMap.h +135 -0
  412. data/pdf2json-0.52-source/xpdf/UnicodeMap.h.old +123 -0
  413. data/pdf2json-0.52-source/xpdf/UnicodeMap.o +0 -0
  414. data/pdf2json-0.52-source/xpdf/UnicodeMapTables.h +361 -0
  415. data/pdf2json-0.52-source/xpdf/UnicodeTypeTable.cc +949 -0
  416. data/pdf2json-0.52-source/xpdf/UnicodeTypeTable.h +20 -0
  417. data/pdf2json-0.52-source/xpdf/UnicodeTypeTable.o +0 -0
  418. data/pdf2json-0.52-source/xpdf/XPDFApp.cc +447 -0
  419. data/pdf2json-0.52-source/xpdf/XPDFApp.h +114 -0
  420. data/pdf2json-0.52-source/xpdf/XPDFCore.cc +1655 -0
  421. data/pdf2json-0.52-source/xpdf/XPDFCore.h +251 -0
  422. data/pdf2json-0.52-source/xpdf/XPDFTree.cc +931 -0
  423. data/pdf2json-0.52-source/xpdf/XPDFTree.h +45 -0
  424. data/pdf2json-0.52-source/xpdf/XPDFTreeP.h +87 -0
  425. data/pdf2json-0.52-source/xpdf/XPDFViewer.cc +3488 -0
  426. data/pdf2json-0.52-source/xpdf/XPDFViewer.h +352 -0
  427. data/pdf2json-0.52-source/xpdf/XRef.cc +896 -0
  428. data/pdf2json-0.52-source/xpdf/XRef.h +133 -0
  429. data/pdf2json-0.52-source/xpdf/XRef.o +0 -0
  430. data/pdf2json-0.52-source/xpdf/XpdfPluginAPI.cc +262 -0
  431. data/pdf2json-0.52-source/xpdf/XpdfPluginAPI.h +341 -0
  432. data/pdf2json-0.52-source/xpdf/XpdfPluginAPI.o +0 -0
  433. data/pdf2json-0.52-source/xpdf/about-text.h +48 -0
  434. data/pdf2json-0.52-source/xpdf/about.xbm +6 -0
  435. data/pdf2json-0.52-source/xpdf/backArrow.xbm +6 -0
  436. data/pdf2json-0.52-source/xpdf/backArrowDis.xbm +6 -0
  437. data/pdf2json-0.52-source/xpdf/config.h +112 -0
  438. data/pdf2json-0.52-source/xpdf/dblLeftArrow.xbm +6 -0
  439. data/pdf2json-0.52-source/xpdf/dblLeftArrowDis.xbm +6 -0
  440. data/pdf2json-0.52-source/xpdf/dblRightArrow.xbm +6 -0
  441. data/pdf2json-0.52-source/xpdf/dblRightArrowDis.xbm +6 -0
  442. data/pdf2json-0.52-source/xpdf/find.xbm +6 -0
  443. data/pdf2json-0.52-source/xpdf/findDis.xbm +6 -0
  444. data/pdf2json-0.52-source/xpdf/forwardArrow.xbm +6 -0
  445. data/pdf2json-0.52-source/xpdf/forwardArrowDis.xbm +6 -0
  446. data/pdf2json-0.52-source/xpdf/leftArrow.xbm +5 -0
  447. data/pdf2json-0.52-source/xpdf/leftArrowDis.xbm +5 -0
  448. data/pdf2json-0.52-source/xpdf/libXpdf.a +0 -0
  449. data/pdf2json-0.52-source/xpdf/pdffonts +0 -0
  450. data/pdf2json-0.52-source/xpdf/pdffonts.cc +298 -0
  451. data/pdf2json-0.52-source/xpdf/pdffonts.o +0 -0
  452. data/pdf2json-0.52-source/xpdf/pdfimages +0 -0
  453. data/pdf2json-0.52-source/xpdf/pdfimages.cc +155 -0
  454. data/pdf2json-0.52-source/xpdf/pdfimages.o +0 -0
  455. data/pdf2json-0.52-source/xpdf/pdfinfo +0 -0
  456. data/pdf2json-0.52-source/xpdf/pdfinfo.cc +387 -0
  457. data/pdf2json-0.52-source/xpdf/pdfinfo.o +0 -0
  458. data/pdf2json-0.52-source/xpdf/pdftoppm.cc +203 -0
  459. data/pdf2json-0.52-source/xpdf/pdftops +0 -0
  460. data/pdf2json-0.52-source/xpdf/pdftops.cc +344 -0
  461. data/pdf2json-0.52-source/xpdf/pdftops.o +0 -0
  462. data/pdf2json-0.52-source/xpdf/pdftotext +0 -0
  463. data/pdf2json-0.52-source/xpdf/pdftotext.cc +333 -0
  464. data/pdf2json-0.52-source/xpdf/pdftotext.o +0 -0
  465. data/pdf2json-0.52-source/xpdf/print.xbm +6 -0
  466. data/pdf2json-0.52-source/xpdf/printDis.xbm +6 -0
  467. data/pdf2json-0.52-source/xpdf/rightArrow.xbm +5 -0
  468. data/pdf2json-0.52-source/xpdf/rightArrowDis.xbm +5 -0
  469. data/pdf2json-0.52-source/xpdf/vms_make.com +129 -0
  470. data/pdf2json-0.52-source/xpdf/xpdf.cc +344 -0
  471. data/pdf2json-0.52-source/xpdf/xpdfIcon.xpm +62 -0
  472. data/pdf2json.gemspec +29 -0
  473. metadata +518 -0
@@ -0,0 +1,61 @@
1
+ //========================================================================
2
+ //
3
+ // CoreOutputDev.cc
4
+ //
5
+ // Copyright 2004 Glyph & Cog, LLC
6
+ //
7
+ //========================================================================
8
+
9
+ #include <aconf.h>
10
+
11
+ #ifdef USE_GCC_PRAGMAS
12
+ #pragma implementation
13
+ #endif
14
+
15
+ #include "Object.h"
16
+ #include "TextOutputDev.h"
17
+ #include "CoreOutputDev.h"
18
+
19
+ //------------------------------------------------------------------------
20
+ // CoreOutputDev
21
+ //------------------------------------------------------------------------
22
+
23
+ CoreOutputDev::CoreOutputDev(SplashColorMode colorModeA, int bitmapRowPadA,
24
+ GBool reverseVideoA, SplashColorPtr paperColorA,
25
+ GBool incrementalUpdateA,
26
+ CoreOutRedrawCbk redrawCbkA,
27
+ void *redrawCbkDataA):
28
+ SplashOutputDev(colorModeA, bitmapRowPadA, reverseVideoA, paperColorA)
29
+ {
30
+ incrementalUpdate = incrementalUpdateA;
31
+ redrawCbk = redrawCbkA;
32
+ redrawCbkData = redrawCbkDataA;
33
+ }
34
+
35
+ CoreOutputDev::~CoreOutputDev() {
36
+ }
37
+
38
+ void CoreOutputDev::endPage() {
39
+ SplashOutputDev::endPage();
40
+ if (!incrementalUpdate) {
41
+ (*redrawCbk)(redrawCbkData, 0, 0, getBitmapWidth(), getBitmapHeight(),
42
+ gTrue);
43
+ }
44
+ }
45
+
46
+ void CoreOutputDev::dump() {
47
+ int x0, y0, x1, y1;
48
+
49
+ if (incrementalUpdate) {
50
+ getModRegion(&x0, &y0, &x1, &y1);
51
+ clearModRegion();
52
+ if (x1 >= x0 && y1 >= y0) {
53
+ (*redrawCbk)(redrawCbkData, x0, y0, x1, y1, gFalse);
54
+ }
55
+ }
56
+ }
57
+
58
+ void CoreOutputDev::clear() {
59
+ startDoc(NULL);
60
+ startPage(0, NULL);
61
+ }
@@ -0,0 +1,61 @@
1
+ //========================================================================
2
+ //
3
+ // CoreOutputDev.h
4
+ //
5
+ // Copyright 2004 Glyph & Cog, LLC
6
+ //
7
+ //========================================================================
8
+
9
+ #ifndef COREOUTPUTDEV_H
10
+ #define COREOUTPUTDEV_H
11
+
12
+ #ifdef USE_GCC_PRAGMAS
13
+ #pragma interface
14
+ #endif
15
+
16
+ #include "SplashTypes.h"
17
+ #include "SplashOutputDev.h"
18
+
19
+ class TextPage;
20
+
21
+ //------------------------------------------------------------------------
22
+
23
+ typedef void (*CoreOutRedrawCbk)(void *data, int x0, int y0, int x1, int y1,
24
+ GBool composited);
25
+
26
+ //------------------------------------------------------------------------
27
+ // CoreOutputDev
28
+ //------------------------------------------------------------------------
29
+
30
+ class CoreOutputDev: public SplashOutputDev {
31
+ public:
32
+
33
+ CoreOutputDev(SplashColorMode colorModeA, int bitmapRowPadA,
34
+ GBool reverseVideoA, SplashColorPtr paperColorA,
35
+ GBool incrementalUpdateA,
36
+ CoreOutRedrawCbk redrawCbkA,
37
+ void *redrawCbkDataA);
38
+
39
+ virtual ~CoreOutputDev();
40
+
41
+ //----- initialization and control
42
+
43
+ // End a page.
44
+ virtual void endPage();
45
+
46
+ // Dump page contents to display.
47
+ virtual void dump();
48
+
49
+ //----- special access
50
+
51
+ // Clear out the document (used when displaying an empty window).
52
+ void clear();
53
+
54
+ private:
55
+
56
+ GBool incrementalUpdate; // incrementally update the display?
57
+ CoreOutRedrawCbk redrawCbk;
58
+ void *redrawCbkData;
59
+ };
60
+
61
+ #endif
@@ -0,0 +1,776 @@
1
+ //========================================================================
2
+ //
3
+ // Decrypt.cc
4
+ //
5
+ // Copyright 1996-2003 Glyph & Cog, LLC
6
+ //
7
+ //========================================================================
8
+
9
+ #include <aconf.h>
10
+
11
+ #ifdef USE_GCC_PRAGMAS
12
+ #pragma implementation
13
+ #endif
14
+
15
+ #include <string.h>
16
+ #include "gmem.h"
17
+ #include "Decrypt.h"
18
+
19
+ static void rc4InitKey(Guchar *key, int keyLen, Guchar *state);
20
+ static Guchar rc4DecryptByte(Guchar *state, Guchar *x, Guchar *y, Guchar c);
21
+ static void aesKeyExpansion(DecryptAESState *s,
22
+ Guchar *objKey, int objKeyLen);
23
+ static void aesDecryptBlock(DecryptAESState *s, Guchar *in, GBool last);
24
+ static void md5(Guchar *msg, int msgLen, Guchar *digest);
25
+
26
+ static Guchar passwordPad[32] = {
27
+ 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41,
28
+ 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
29
+ 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
30
+ 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a
31
+ };
32
+
33
+ //------------------------------------------------------------------------
34
+ // Decrypt
35
+ //------------------------------------------------------------------------
36
+
37
+ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength,
38
+ GString *ownerKey, GString *userKey,
39
+ int permissions, GString *fileID,
40
+ GString *ownerPassword, GString *userPassword,
41
+ Guchar *fileKey, GBool encryptMetadata,
42
+ GBool *ownerPasswordOk) {
43
+ Guchar test[32], test2[32];
44
+ GString *userPassword2;
45
+ Guchar fState[256];
46
+ Guchar tmpKey[16];
47
+ Guchar fx, fy;
48
+ int len, i, j;
49
+
50
+ // try using the supplied owner password to generate the user password
51
+ *ownerPasswordOk = gFalse;
52
+ if (ownerPassword) {
53
+ len = ownerPassword->getLength();
54
+ if (len < 32) {
55
+ memcpy(test, ownerPassword->getCString(), len);
56
+ memcpy(test + len, passwordPad, 32 - len);
57
+ } else {
58
+ memcpy(test, ownerPassword->getCString(), 32);
59
+ }
60
+ md5(test, 32, test);
61
+ if (encRevision == 3) {
62
+ for (i = 0; i < 50; ++i) {
63
+ md5(test, 16, test);
64
+ }
65
+ }
66
+ if (encRevision == 2) {
67
+ rc4InitKey(test, keyLength, fState);
68
+ fx = fy = 0;
69
+ for (i = 0; i < 32; ++i) {
70
+ test2[i] = rc4DecryptByte(fState, &fx, &fy, ownerKey->getChar(i));
71
+ }
72
+ } else {
73
+ memcpy(test2, ownerKey->getCString(), 32);
74
+ for (i = 19; i >= 0; --i) {
75
+ for (j = 0; j < keyLength; ++j) {
76
+ tmpKey[j] = test[j] ^ i;
77
+ }
78
+ rc4InitKey(tmpKey, keyLength, fState);
79
+ fx = fy = 0;
80
+ for (j = 0; j < 32; ++j) {
81
+ test2[j] = rc4DecryptByte(fState, &fx, &fy, test2[j]);
82
+ }
83
+ }
84
+ }
85
+ userPassword2 = new GString((char *)test2, 32);
86
+ if (makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey,
87
+ permissions, fileID, userPassword2, fileKey,
88
+ encryptMetadata)) {
89
+ *ownerPasswordOk = gTrue;
90
+ delete userPassword2;
91
+ return gTrue;
92
+ }
93
+ delete userPassword2;
94
+ }
95
+
96
+ // try using the supplied user password
97
+ return makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey,
98
+ permissions, fileID, userPassword, fileKey,
99
+ encryptMetadata);
100
+ }
101
+
102
+ GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength,
103
+ GString *ownerKey, GString *userKey,
104
+ int permissions, GString *fileID,
105
+ GString *userPassword, Guchar *fileKey,
106
+ GBool encryptMetadata) {
107
+ Guchar *buf;
108
+ Guchar test[32];
109
+ Guchar fState[256];
110
+ Guchar tmpKey[16];
111
+ Guchar fx, fy;
112
+ int len, i, j;
113
+ GBool ok;
114
+
115
+ // generate file key
116
+ buf = (Guchar *)gmalloc(72 + fileID->getLength());
117
+ if (userPassword) {
118
+ len = userPassword->getLength();
119
+ if (len < 32) {
120
+ memcpy(buf, userPassword->getCString(), len);
121
+ memcpy(buf + len, passwordPad, 32 - len);
122
+ } else {
123
+ memcpy(buf, userPassword->getCString(), 32);
124
+ }
125
+ } else {
126
+ memcpy(buf, passwordPad, 32);
127
+ }
128
+ memcpy(buf + 32, ownerKey->getCString(), 32);
129
+ buf[64] = permissions & 0xff;
130
+ buf[65] = (permissions >> 8) & 0xff;
131
+ buf[66] = (permissions >> 16) & 0xff;
132
+ buf[67] = (permissions >> 24) & 0xff;
133
+ memcpy(buf + 68, fileID->getCString(), fileID->getLength());
134
+ len = 68 + fileID->getLength();
135
+ if (!encryptMetadata) {
136
+ buf[len++] = 0xff;
137
+ buf[len++] = 0xff;
138
+ buf[len++] = 0xff;
139
+ buf[len++] = 0xff;
140
+ }
141
+ md5(buf, len, fileKey);
142
+ if (encRevision == 3) {
143
+ for (i = 0; i < 50; ++i) {
144
+ md5(fileKey, keyLength, fileKey);
145
+ }
146
+ }
147
+
148
+ // test user password
149
+ if (encRevision == 2) {
150
+ rc4InitKey(fileKey, keyLength, fState);
151
+ fx = fy = 0;
152
+ for (i = 0; i < 32; ++i) {
153
+ test[i] = rc4DecryptByte(fState, &fx, &fy, userKey->getChar(i));
154
+ }
155
+ ok = memcmp(test, passwordPad, 32) == 0;
156
+ } else if (encRevision == 3) {
157
+ memcpy(test, userKey->getCString(), 32);
158
+ for (i = 19; i >= 0; --i) {
159
+ for (j = 0; j < keyLength; ++j) {
160
+ tmpKey[j] = fileKey[j] ^ i;
161
+ }
162
+ rc4InitKey(tmpKey, keyLength, fState);
163
+ fx = fy = 0;
164
+ for (j = 0; j < 32; ++j) {
165
+ test[j] = rc4DecryptByte(fState, &fx, &fy, test[j]);
166
+ }
167
+ }
168
+ memcpy(buf, passwordPad, 32);
169
+ memcpy(buf + 32, fileID->getCString(), fileID->getLength());
170
+ md5(buf, 32 + fileID->getLength(), buf);
171
+ ok = memcmp(test, buf, 16) == 0;
172
+ } else {
173
+ ok = gFalse;
174
+ }
175
+
176
+ gfree(buf);
177
+ return ok;
178
+ }
179
+
180
+ //------------------------------------------------------------------------
181
+ // DecryptStream
182
+ //------------------------------------------------------------------------
183
+
184
+ DecryptStream::DecryptStream(Stream *strA, Guchar *fileKey,
185
+ CryptAlgorithm algoA, int keyLength,
186
+ int objNum, int objGen):
187
+ FilterStream(strA)
188
+ {
189
+ int n, i;
190
+
191
+ algo = algoA;
192
+
193
+ // construct object key
194
+ for (i = 0; i < keyLength; ++i) {
195
+ objKey[i] = fileKey[i];
196
+ }
197
+ objKey[keyLength] = objNum & 0xff;
198
+ objKey[keyLength + 1] = (objNum >> 8) & 0xff;
199
+ objKey[keyLength + 2] = (objNum >> 16) & 0xff;
200
+ objKey[keyLength + 3] = objGen & 0xff;
201
+ objKey[keyLength + 4] = (objGen >> 8) & 0xff;
202
+ if (algo == cryptAES) {
203
+ objKey[keyLength + 5] = 0x73; // 's'
204
+ objKey[keyLength + 6] = 0x41; // 'A'
205
+ objKey[keyLength + 7] = 0x6c; // 'l'
206
+ objKey[keyLength + 8] = 0x54; // 'T'
207
+ n = keyLength + 9;
208
+ } else {
209
+ n = keyLength + 5;
210
+ }
211
+ md5(objKey, n, objKey);
212
+ if ((objKeyLength = keyLength + 5) > 16) {
213
+ objKeyLength = 16;
214
+ }
215
+ }
216
+
217
+ DecryptStream::~DecryptStream() {
218
+ delete str;
219
+ }
220
+
221
+ void DecryptStream::reset() {
222
+ int i;
223
+
224
+ str->reset();
225
+ switch (algo) {
226
+ case cryptRC4:
227
+ state.rc4.x = state.rc4.y = 0;
228
+ rc4InitKey(objKey, objKeyLength, state.rc4.state);
229
+ state.rc4.buf = EOF;
230
+ break;
231
+ case cryptAES:
232
+ aesKeyExpansion(&state.aes, objKey, objKeyLength);
233
+ for (i = 0; i < 16; ++i) {
234
+ state.aes.cbc[i] = str->getChar();
235
+ }
236
+ state.aes.bufIdx = 16;
237
+ break;
238
+ }
239
+ }
240
+
241
+ int DecryptStream::getChar() {
242
+ Guchar in[16];
243
+ int c, i;
244
+
245
+ c = EOF; // make gcc happy
246
+ switch (algo) {
247
+ case cryptRC4:
248
+ if (state.rc4.buf == EOF) {
249
+ c = str->getChar();
250
+ if (c != EOF) {
251
+ state.rc4.buf = rc4DecryptByte(state.rc4.state, &state.rc4.x,
252
+ &state.rc4.y, (Guchar)c);
253
+ }
254
+ }
255
+ c = state.rc4.buf;
256
+ state.rc4.buf = EOF;
257
+ break;
258
+ case cryptAES:
259
+ if (state.aes.bufIdx == 16) {
260
+ for (i = 0; i < 16; ++i) {
261
+ if ((c = str->getChar()) == EOF) {
262
+ return EOF;
263
+ }
264
+ in[i] = (Guchar)c;
265
+ }
266
+ aesDecryptBlock(&state.aes, in, str->lookChar() == EOF);
267
+ }
268
+ if (state.aes.bufIdx == 16) {
269
+ c = EOF;
270
+ } else {
271
+ c = state.aes.buf[state.aes.bufIdx++];
272
+ }
273
+ break;
274
+ }
275
+ return c;
276
+ }
277
+
278
+ int DecryptStream::lookChar() {
279
+ Guchar in[16];
280
+ int c, i;
281
+
282
+ c = EOF; // make gcc happy
283
+ switch (algo) {
284
+ case cryptRC4:
285
+ if (state.rc4.buf == EOF) {
286
+ c = str->getChar();
287
+ if (c != EOF) {
288
+ state.rc4.buf = rc4DecryptByte(state.rc4.state, &state.rc4.x,
289
+ &state.rc4.y, (Guchar)c);
290
+ }
291
+ }
292
+ c = state.rc4.buf;
293
+ break;
294
+ case cryptAES:
295
+ if (state.aes.bufIdx == 16) {
296
+ for (i = 0; i < 16; ++i) {
297
+ if ((c = str->getChar()) == EOF) {
298
+ return EOF;
299
+ }
300
+ in[i] = c;
301
+ }
302
+ aesDecryptBlock(&state.aes, in, str->lookChar() == EOF);
303
+ }
304
+ if (state.aes.bufIdx == 16) {
305
+ c = EOF;
306
+ } else {
307
+ c = state.aes.buf[state.aes.bufIdx];
308
+ }
309
+ break;
310
+ }
311
+ return c;
312
+ }
313
+
314
+ GBool DecryptStream::isBinary(GBool last) {
315
+ return str->isBinary(last);
316
+ }
317
+
318
+ //------------------------------------------------------------------------
319
+ // RC4-compatible decryption
320
+ //------------------------------------------------------------------------
321
+
322
+ static void rc4InitKey(Guchar *key, int keyLen, Guchar *state) {
323
+ Guchar index1, index2;
324
+ Guchar t;
325
+ int i;
326
+
327
+ for (i = 0; i < 256; ++i)
328
+ state[i] = i;
329
+ index1 = index2 = 0;
330
+ for (i = 0; i < 256; ++i) {
331
+ index2 = (key[index1] + state[i] + index2) % 256;
332
+ t = state[i];
333
+ state[i] = state[index2];
334
+ state[index2] = t;
335
+ index1 = (index1 + 1) % keyLen;
336
+ }
337
+ }
338
+
339
+ static Guchar rc4DecryptByte(Guchar *state, Guchar *x, Guchar *y, Guchar c) {
340
+ Guchar x1, y1, tx, ty;
341
+
342
+ x1 = *x = (*x + 1) % 256;
343
+ y1 = *y = (state[*x] + *y) % 256;
344
+ tx = state[x1];
345
+ ty = state[y1];
346
+ state[x1] = ty;
347
+ state[y1] = tx;
348
+ return c ^ state[(tx + ty) % 256];
349
+ }
350
+
351
+ //------------------------------------------------------------------------
352
+ // AES decryption
353
+ //------------------------------------------------------------------------
354
+
355
+ static Guchar sbox[256] = {
356
+ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
357
+ 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
358
+ 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
359
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
360
+ 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
361
+ 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
362
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
363
+ 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
364
+ 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
365
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
366
+ 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
367
+ 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
368
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
369
+ 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
370
+ 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
371
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
372
+ };
373
+
374
+ static Guchar invSbox[256] = {
375
+ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
376
+ 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
377
+ 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
378
+ 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
379
+ 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
380
+ 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
381
+ 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
382
+ 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
383
+ 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
384
+ 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
385
+ 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
386
+ 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
387
+ 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
388
+ 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
389
+ 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
390
+ 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
391
+ };
392
+
393
+ static Guint rcon[11] = {
394
+ 0x00000000, // unused
395
+ 0x01000000,
396
+ 0x02000000,
397
+ 0x04000000,
398
+ 0x08000000,
399
+ 0x10000000,
400
+ 0x20000000,
401
+ 0x40000000,
402
+ 0x80000000,
403
+ 0x1b000000,
404
+ 0x36000000
405
+ };
406
+
407
+ static inline Guint subWord(Guint x) {
408
+ return (sbox[x >> 24] << 24)
409
+ | (sbox[(x >> 16) & 0xff] << 16)
410
+ | (sbox[(x >> 8) & 0xff] << 8)
411
+ | sbox[x & 0xff];
412
+ }
413
+
414
+ static inline Guint rotWord(Guint x) {
415
+ return ((x << 8) & 0xffffffff) | (x >> 24);
416
+ }
417
+
418
+ static inline void invSubBytes(Guchar *state) {
419
+ int i;
420
+
421
+ for (i = 0; i < 16; ++i) {
422
+ state[i] = invSbox[state[i]];
423
+ }
424
+ }
425
+
426
+ static inline void invShiftRows(Guchar *state) {
427
+ Guchar t;
428
+
429
+ t = state[7];
430
+ state[7] = state[6];
431
+ state[6] = state[5];
432
+ state[5] = state[4];
433
+ state[4] = t;
434
+
435
+ t = state[8];
436
+ state[8] = state[10];
437
+ state[10] = t;
438
+ t = state[9];
439
+ state[9] = state[11];
440
+ state[11] = t;
441
+
442
+ t = state[12];
443
+ state[12] = state[13];
444
+ state[13] = state[14];
445
+ state[14] = state[15];
446
+ state[15] = t;
447
+ }
448
+
449
+ // {09} \cdot s
450
+ static inline Guchar mul09(Guchar s) {
451
+ Guchar s2, s4, s8;
452
+
453
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
454
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
455
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
456
+ return s ^ s8;
457
+ }
458
+
459
+ // {0b} \cdot s
460
+ static inline Guchar mul0b(Guchar s) {
461
+ Guchar s2, s4, s8;
462
+
463
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
464
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
465
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
466
+ return s ^ s2 ^ s8;
467
+ }
468
+
469
+ // {0d} \cdot s
470
+ static inline Guchar mul0d(Guchar s) {
471
+ Guchar s2, s4, s8;
472
+
473
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
474
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
475
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
476
+ return s ^ s4 ^ s8;
477
+ }
478
+
479
+ // {0e} \cdot s
480
+ static inline Guchar mul0e(Guchar s) {
481
+ Guchar s2, s4, s8;
482
+
483
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
484
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
485
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
486
+ return s2 ^ s4 ^ s8;
487
+ }
488
+
489
+ static inline void invMixColumns(Guchar *state) {
490
+ int c;
491
+ Guchar s0, s1, s2, s3;
492
+
493
+ for (c = 0; c < 4; ++c) {
494
+ s0 = state[c];
495
+ s1 = state[4+c];
496
+ s2 = state[8+c];
497
+ s3 = state[12+c];
498
+ state[c] = mul0e(s0) ^ mul0b(s1) ^ mul0d(s2) ^ mul09(s3);
499
+ state[4+c] = mul09(s0) ^ mul0e(s1) ^ mul0b(s2) ^ mul0d(s3);
500
+ state[8+c] = mul0d(s0) ^ mul09(s1) ^ mul0e(s2) ^ mul0b(s3);
501
+ state[12+c] = mul0b(s0) ^ mul0d(s1) ^ mul09(s2) ^ mul0e(s3);
502
+ }
503
+ }
504
+
505
+ static inline void invMixColumnsW(Guint *w) {
506
+ int c;
507
+ Guchar s0, s1, s2, s3;
508
+
509
+ for (c = 0; c < 4; ++c) {
510
+ s0 = w[c] >> 24;
511
+ s1 = w[c] >> 16;
512
+ s2 = w[c] >> 8;
513
+ s3 = w[c];
514
+ w[c] = ((mul0e(s0) ^ mul0b(s1) ^ mul0d(s2) ^ mul09(s3)) << 24)
515
+ | ((mul09(s0) ^ mul0e(s1) ^ mul0b(s2) ^ mul0d(s3)) << 16)
516
+ | ((mul0d(s0) ^ mul09(s1) ^ mul0e(s2) ^ mul0b(s3)) << 8)
517
+ | (mul0b(s0) ^ mul0d(s1) ^ mul09(s2) ^ mul0e(s3));
518
+ }
519
+ }
520
+
521
+ static inline void addRoundKey(Guchar *state, Guint *w) {
522
+ int c;
523
+
524
+ for (c = 0; c < 4; ++c) {
525
+ state[c] ^= w[c] >> 24;
526
+ state[4+c] ^= w[c] >> 16;
527
+ state[8+c] ^= w[c] >> 8;
528
+ state[12+c] ^= w[c];
529
+ }
530
+ }
531
+
532
+ static void aesKeyExpansion(DecryptAESState *s,
533
+ Guchar *objKey, int objKeyLen) {
534
+ Guint temp;
535
+ int i, round;
536
+
537
+ //~ this assumes objKeyLen == 16
538
+
539
+ for (i = 0; i < 4; ++i) {
540
+ s->w[i] = (objKey[4*i] << 24) + (objKey[4*i+1] << 16) +
541
+ (objKey[4*i+2] << 8) + objKey[4*i+3];
542
+ }
543
+ for (i = 4; i < 44; ++i) {
544
+ temp = s->w[i-1];
545
+ if (!(i & 3)) {
546
+ temp = subWord(rotWord(temp)) ^ rcon[i/4];
547
+ }
548
+ s->w[i] = s->w[i-4] ^ temp;
549
+ }
550
+ for (round = 1; round <= 9; ++round) {
551
+ invMixColumnsW(&s->w[round * 4]);
552
+ }
553
+ }
554
+
555
+ static void aesDecryptBlock(DecryptAESState *s, Guchar *in, GBool last) {
556
+ int c, round, n, i;
557
+
558
+ // initial state
559
+ for (c = 0; c < 4; ++c) {
560
+ s->state[c] = in[4*c];
561
+ s->state[4+c] = in[4*c+1];
562
+ s->state[8+c] = in[4*c+2];
563
+ s->state[12+c] = in[4*c+3];
564
+ }
565
+
566
+ // round 0
567
+ addRoundKey(s->state, &s->w[10 * 4]);
568
+
569
+ // rounds 1-9
570
+ for (round = 9; round >= 1; --round) {
571
+ invSubBytes(s->state);
572
+ invShiftRows(s->state);
573
+ invMixColumns(s->state);
574
+ addRoundKey(s->state, &s->w[round * 4]);
575
+ }
576
+
577
+ // round 10
578
+ invSubBytes(s->state);
579
+ invShiftRows(s->state);
580
+ addRoundKey(s->state, &s->w[0]);
581
+
582
+ // CBC
583
+ for (c = 0; c < 4; ++c) {
584
+ s->buf[4*c] = s->state[c] ^ s->cbc[4*c];
585
+ s->buf[4*c+1] = s->state[4+c] ^ s->cbc[4*c+1];
586
+ s->buf[4*c+2] = s->state[8+c] ^ s->cbc[4*c+2];
587
+ s->buf[4*c+3] = s->state[12+c] ^ s->cbc[4*c+3];
588
+ }
589
+
590
+ // save the input block for the next CBC
591
+ for (i = 0; i < 16; ++i) {
592
+ s->cbc[i] = in[i];
593
+ }
594
+
595
+ // remove padding
596
+ s->bufIdx = 0;
597
+ if (last) {
598
+ n = s->buf[15];
599
+ for (i = 15; i >= n; --i) {
600
+ s->buf[i] = s->buf[i-n];
601
+ }
602
+ s->bufIdx = n;
603
+ }
604
+ }
605
+
606
+ //------------------------------------------------------------------------
607
+ // MD5 message digest
608
+ //------------------------------------------------------------------------
609
+
610
+ // this works around a bug in older Sun compilers
611
+ static inline Gulong rotateLeft(Gulong x, int r) {
612
+ x &= 0xffffffff;
613
+ return ((x << r) | (x >> (32 - r))) & 0xffffffff;
614
+ }
615
+
616
+ static inline Gulong md5Round1(Gulong a, Gulong b, Gulong c, Gulong d,
617
+ Gulong Xk, Gulong s, Gulong Ti) {
618
+ return b + rotateLeft((a + ((b & c) | (~b & d)) + Xk + Ti), s);
619
+ }
620
+
621
+ static inline Gulong md5Round2(Gulong a, Gulong b, Gulong c, Gulong d,
622
+ Gulong Xk, Gulong s, Gulong Ti) {
623
+ return b + rotateLeft((a + ((b & d) | (c & ~d)) + Xk + Ti), s);
624
+ }
625
+
626
+ static inline Gulong md5Round3(Gulong a, Gulong b, Gulong c, Gulong d,
627
+ Gulong Xk, Gulong s, Gulong Ti) {
628
+ return b + rotateLeft((a + (b ^ c ^ d) + Xk + Ti), s);
629
+ }
630
+
631
+ static inline Gulong md5Round4(Gulong a, Gulong b, Gulong c, Gulong d,
632
+ Gulong Xk, Gulong s, Gulong Ti) {
633
+ return b + rotateLeft((a + (c ^ (b | ~d)) + Xk + Ti), s);
634
+ }
635
+
636
+ static void md5(Guchar *msg, int msgLen, Guchar *digest) {
637
+ Gulong x[16];
638
+ Gulong a, b, c, d, aa, bb, cc, dd;
639
+ int n64;
640
+ int i, j, k;
641
+
642
+ // compute number of 64-byte blocks
643
+ // (length + pad byte (0x80) + 8 bytes for length)
644
+ n64 = (msgLen + 1 + 8 + 63) / 64;
645
+
646
+ // initialize a, b, c, d
647
+ a = 0x67452301;
648
+ b = 0xefcdab89;
649
+ c = 0x98badcfe;
650
+ d = 0x10325476;
651
+
652
+ // loop through blocks
653
+ k = 0;
654
+ for (i = 0; i < n64; ++i) {
655
+
656
+ // grab a 64-byte block
657
+ for (j = 0; j < 16 && k < msgLen - 3; ++j, k += 4)
658
+ x[j] = (((((msg[k+3] << 8) + msg[k+2]) << 8) + msg[k+1]) << 8) + msg[k];
659
+ if (i == n64 - 1) {
660
+ if (k == msgLen - 3)
661
+ x[j] = 0x80000000 + (((msg[k+2] << 8) + msg[k+1]) << 8) + msg[k];
662
+ else if (k == msgLen - 2)
663
+ x[j] = 0x800000 + (msg[k+1] << 8) + msg[k];
664
+ else if (k == msgLen - 1)
665
+ x[j] = 0x8000 + msg[k];
666
+ else
667
+ x[j] = 0x80;
668
+ ++j;
669
+ while (j < 16)
670
+ x[j++] = 0;
671
+ x[14] = msgLen << 3;
672
+ }
673
+
674
+ // save a, b, c, d
675
+ aa = a;
676
+ bb = b;
677
+ cc = c;
678
+ dd = d;
679
+
680
+ // round 1
681
+ a = md5Round1(a, b, c, d, x[0], 7, 0xd76aa478);
682
+ d = md5Round1(d, a, b, c, x[1], 12, 0xe8c7b756);
683
+ c = md5Round1(c, d, a, b, x[2], 17, 0x242070db);
684
+ b = md5Round1(b, c, d, a, x[3], 22, 0xc1bdceee);
685
+ a = md5Round1(a, b, c, d, x[4], 7, 0xf57c0faf);
686
+ d = md5Round1(d, a, b, c, x[5], 12, 0x4787c62a);
687
+ c = md5Round1(c, d, a, b, x[6], 17, 0xa8304613);
688
+ b = md5Round1(b, c, d, a, x[7], 22, 0xfd469501);
689
+ a = md5Round1(a, b, c, d, x[8], 7, 0x698098d8);
690
+ d = md5Round1(d, a, b, c, x[9], 12, 0x8b44f7af);
691
+ c = md5Round1(c, d, a, b, x[10], 17, 0xffff5bb1);
692
+ b = md5Round1(b, c, d, a, x[11], 22, 0x895cd7be);
693
+ a = md5Round1(a, b, c, d, x[12], 7, 0x6b901122);
694
+ d = md5Round1(d, a, b, c, x[13], 12, 0xfd987193);
695
+ c = md5Round1(c, d, a, b, x[14], 17, 0xa679438e);
696
+ b = md5Round1(b, c, d, a, x[15], 22, 0x49b40821);
697
+
698
+ // round 2
699
+ a = md5Round2(a, b, c, d, x[1], 5, 0xf61e2562);
700
+ d = md5Round2(d, a, b, c, x[6], 9, 0xc040b340);
701
+ c = md5Round2(c, d, a, b, x[11], 14, 0x265e5a51);
702
+ b = md5Round2(b, c, d, a, x[0], 20, 0xe9b6c7aa);
703
+ a = md5Round2(a, b, c, d, x[5], 5, 0xd62f105d);
704
+ d = md5Round2(d, a, b, c, x[10], 9, 0x02441453);
705
+ c = md5Round2(c, d, a, b, x[15], 14, 0xd8a1e681);
706
+ b = md5Round2(b, c, d, a, x[4], 20, 0xe7d3fbc8);
707
+ a = md5Round2(a, b, c, d, x[9], 5, 0x21e1cde6);
708
+ d = md5Round2(d, a, b, c, x[14], 9, 0xc33707d6);
709
+ c = md5Round2(c, d, a, b, x[3], 14, 0xf4d50d87);
710
+ b = md5Round2(b, c, d, a, x[8], 20, 0x455a14ed);
711
+ a = md5Round2(a, b, c, d, x[13], 5, 0xa9e3e905);
712
+ d = md5Round2(d, a, b, c, x[2], 9, 0xfcefa3f8);
713
+ c = md5Round2(c, d, a, b, x[7], 14, 0x676f02d9);
714
+ b = md5Round2(b, c, d, a, x[12], 20, 0x8d2a4c8a);
715
+
716
+ // round 3
717
+ a = md5Round3(a, b, c, d, x[5], 4, 0xfffa3942);
718
+ d = md5Round3(d, a, b, c, x[8], 11, 0x8771f681);
719
+ c = md5Round3(c, d, a, b, x[11], 16, 0x6d9d6122);
720
+ b = md5Round3(b, c, d, a, x[14], 23, 0xfde5380c);
721
+ a = md5Round3(a, b, c, d, x[1], 4, 0xa4beea44);
722
+ d = md5Round3(d, a, b, c, x[4], 11, 0x4bdecfa9);
723
+ c = md5Round3(c, d, a, b, x[7], 16, 0xf6bb4b60);
724
+ b = md5Round3(b, c, d, a, x[10], 23, 0xbebfbc70);
725
+ a = md5Round3(a, b, c, d, x[13], 4, 0x289b7ec6);
726
+ d = md5Round3(d, a, b, c, x[0], 11, 0xeaa127fa);
727
+ c = md5Round3(c, d, a, b, x[3], 16, 0xd4ef3085);
728
+ b = md5Round3(b, c, d, a, x[6], 23, 0x04881d05);
729
+ a = md5Round3(a, b, c, d, x[9], 4, 0xd9d4d039);
730
+ d = md5Round3(d, a, b, c, x[12], 11, 0xe6db99e5);
731
+ c = md5Round3(c, d, a, b, x[15], 16, 0x1fa27cf8);
732
+ b = md5Round3(b, c, d, a, x[2], 23, 0xc4ac5665);
733
+
734
+ // round 4
735
+ a = md5Round4(a, b, c, d, x[0], 6, 0xf4292244);
736
+ d = md5Round4(d, a, b, c, x[7], 10, 0x432aff97);
737
+ c = md5Round4(c, d, a, b, x[14], 15, 0xab9423a7);
738
+ b = md5Round4(b, c, d, a, x[5], 21, 0xfc93a039);
739
+ a = md5Round4(a, b, c, d, x[12], 6, 0x655b59c3);
740
+ d = md5Round4(d, a, b, c, x[3], 10, 0x8f0ccc92);
741
+ c = md5Round4(c, d, a, b, x[10], 15, 0xffeff47d);
742
+ b = md5Round4(b, c, d, a, x[1], 21, 0x85845dd1);
743
+ a = md5Round4(a, b, c, d, x[8], 6, 0x6fa87e4f);
744
+ d = md5Round4(d, a, b, c, x[15], 10, 0xfe2ce6e0);
745
+ c = md5Round4(c, d, a, b, x[6], 15, 0xa3014314);
746
+ b = md5Round4(b, c, d, a, x[13], 21, 0x4e0811a1);
747
+ a = md5Round4(a, b, c, d, x[4], 6, 0xf7537e82);
748
+ d = md5Round4(d, a, b, c, x[11], 10, 0xbd3af235);
749
+ c = md5Round4(c, d, a, b, x[2], 15, 0x2ad7d2bb);
750
+ b = md5Round4(b, c, d, a, x[9], 21, 0xeb86d391);
751
+
752
+ // increment a, b, c, d
753
+ a += aa;
754
+ b += bb;
755
+ c += cc;
756
+ d += dd;
757
+ }
758
+
759
+ // break digest into bytes
760
+ digest[0] = (Guchar)(a & 0xff);
761
+ digest[1] = (Guchar)((a >>= 8) & 0xff);
762
+ digest[2] = (Guchar)((a >>= 8) & 0xff);
763
+ digest[3] = (Guchar)((a >>= 8) & 0xff);
764
+ digest[4] = (Guchar)(b & 0xff);
765
+ digest[5] = (Guchar)((b >>= 8) & 0xff);
766
+ digest[6] = (Guchar)((b >>= 8) & 0xff);
767
+ digest[7] = (Guchar)((b >>= 8) & 0xff);
768
+ digest[8] = (Guchar)(c & 0xff);
769
+ digest[9] = (Guchar)((c >>= 8) & 0xff);
770
+ digest[10] = (Guchar)((c >>= 8) & 0xff);
771
+ digest[11] = (Guchar)((c >>= 8) & 0xff);
772
+ digest[12] = (Guchar)(d & 0xff);
773
+ digest[13] = (Guchar)((d >>= 8) & 0xff);
774
+ digest[14] = (Guchar)((d >>= 8) & 0xff);
775
+ digest[15] = (Guchar)((d >>= 8) & 0xff);
776
+ }