~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/Decrypt.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// Decrypt.h
 
4
//
 
5
// Copyright 1996-2003 Glyph & Cog, LLC
 
6
//
 
7
//========================================================================
 
8
 
 
9
//========================================================================
 
10
//
 
11
// Modified under the Poppler project - http://poppler.freedesktop.org
 
12
//
 
13
// All changes made under the Poppler project to this file are licensed
 
14
// under GPL version 2 or later
 
15
//
 
16
// Copyright (C) 2008 Julien Rebetez <julien@fhtagn.net>
 
17
// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
 
18
//
 
19
// To see a description of the changes please see the Changelog file that
 
20
// came with your tarball or type make ChangeLog if you are building from git
 
21
//
 
22
//========================================================================
 
23
 
 
24
#ifndef DECRYPT_H
 
25
#define DECRYPT_H
 
26
 
 
27
#ifdef USE_GCC_PRAGMAS
 
28
#pragma interface
 
29
#endif
 
30
 
 
31
#include "goo/gtypes.h"
 
32
#include "goo/GooString.h"
 
33
#include "Object.h"
 
34
#include "Stream.h"
 
35
 
 
36
//------------------------------------------------------------------------
 
37
// Decrypt
 
38
//------------------------------------------------------------------------
 
39
 
 
40
class Decrypt {
 
41
public:
 
42
  static void md5(Guchar *msg, int msgLen, Guchar *digest);
 
43
 
 
44
  // Generate a file key.  The <fileKey> buffer must have space for at
 
45
  // least 16 bytes.  Checks <ownerPassword> and then <userPassword>
 
46
  // and returns true if either is correct.  Sets <ownerPasswordOk> if
 
47
  // the owner password was correct.  Either or both of the passwords
 
48
  // may be NULL, which is treated as an empty string.
 
49
  static GBool makeFileKey(int encVersion, int encRevision, int keyLength,
 
50
                           GooString *ownerKey, GooString *userKey,
 
51
                           int permissions, GooString *fileID,
 
52
                           GooString *ownerPassword, GooString *userPassword,
 
53
                           Guchar *fileKey, GBool encryptMetadata,
 
54
                           GBool *ownerPasswordOk);
 
55
 
 
56
private:
 
57
 
 
58
  static GBool makeFileKey2(int encVersion, int encRevision, int keyLength,
 
59
                            GooString *ownerKey, GooString *userKey,
 
60
                            int permissions, GooString *fileID,
 
61
                            GooString *userPassword, Guchar *fileKey,
 
62
                            GBool encryptMetadata);
 
63
};
 
64
 
 
65
//------------------------------------------------------------------------
 
66
// DecryptStream
 
67
//------------------------------------------------------------------------
 
68
 
 
69
struct DecryptRC4State {
 
70
  Guchar state[256];
 
71
  Guchar x, y;
 
72
  int buf;
 
73
};
 
74
 
 
75
struct DecryptAESState {
 
76
  Guint w[44];
 
77
  Guchar state[16];
 
78
  Guchar cbc[16];
 
79
  Guchar buf[16];
 
80
  int bufIdx;
 
81
};
 
82
 
 
83
class DecryptStream: public FilterStream {
 
84
public:
 
85
 
 
86
  DecryptStream(Stream *strA, Guchar *fileKey,
 
87
                CryptAlgorithm algoA, int keyLength,
 
88
                int objNum, int objGen);
 
89
  virtual ~DecryptStream();
 
90
  virtual StreamKind getKind() { return strWeird; }
 
91
  virtual void reset();
 
92
  virtual int getChar();
 
93
  virtual int lookChar();
 
94
  virtual int getPos();
 
95
  virtual GBool isBinary(GBool last);
 
96
  virtual Stream *getUndecodedStream() { return this; }
 
97
 
 
98
private:
 
99
 
 
100
  CryptAlgorithm algo;
 
101
  int objKeyLength;
 
102
  Guchar objKey[16 + 9];
 
103
  int charactersRead; // so that getPos() can be correct
 
104
 
 
105
  union {
 
106
    DecryptRC4State rc4;
 
107
    DecryptAESState aes;
 
108
  } state;
 
109
};
 
110
 
 
111
#endif