HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_BlowfishIO.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_BlowfishIO.h ( Library, C++)
7  *
8  * COMMENTS:
9  * Utility methods for reading and writing encrypted streams.
10  */
11 
12 #ifndef __UT_BlowfishIO__
13 #define __UT_BlowfishIO__
14 
15 #include "UT_API.h"
16 #include "UT_NTStreamUtil.h"
17 
18 class UT_Blowfish;
19 
20 
21 // Encrypts the stream using the blowfish algorithm.
23 {
24 public:
25  /// constructor and destructor.
26  UT_BlowfishEncryptFilter( const uint8* key_bytes,
27  int key_size );
28  virtual ~UT_BlowfishEncryptFilter();
29 
30  // Returns the size of the encrypted data based on its original
31  // (plain-text) size.
32  static int getFilteredSize( int original_size );
33 
34  /// This method returns the the maximum input size (no larger than the
35  /// specified buffer size) with which the filter can work, given the buffer
36  /// size.
37  virtual int getDataChunkLength( int buffer_size );
38 
39  /// Writes out the length of the original stream to the buffer. It is used
40  /// when decrypting.
41  virtual int beginFilter(char *buffer, int buffer_size, int stream_size);
42 
43  /// Performs the encryption of the data in the buffer.
44  virtual int doFilterChunk(char *buffer, int data_size, int buffer_size);
45 
46  /// Writes out any remaining ciphertext that has not been written out yet,
47  /// and concludes encryption.
48  virtual int endFilter( char *buffer, int buffer_size );
49 
50  /// Gets the amount of memory owned by this UT_BlowfishEncryptFilter
51  virtual int64 getMemoryUsage(bool inclusive) const;
52 
53 private:
54  UT_Blowfish * myEncryptor; // helper doing the encryption job
55  bool myFullBlocksFlag; // true if no padding occured
56 };
57 
58 // Decrypts the stream encrypted with the filter above.
60 {
61 public:
62  // Constructor and destructor.
63  UT_BlowfishStreamDecryptor( const uint8 * key,
64  int key_length );
66 
67  /// Wrapper for UT_Blowfish::getEncryptionOutputSize()
68  static int getEncryptedSize( int plain_text_size );
69 
70  /// Wrapper for UT_Blowfish::getCryptBufferSize()
71  static int getCryptBufferSize( int max_buffer_size );
72 
73  /// Wrapper for UT_Blowfish::getBlockSize()
74  static int getBlockSize();
75 
76  /// Gets the preamble size. The pramble contains some meta-data such as
77  /// plain-text size, encryption version, and magic number.
78  static int getPreambleSize();
79 
80  /// Obtains the blowfish algorithm version used for the stream.
81  static bool getVersion( const char * preamble, int preamble_length,
82  int & version );
83 
84  /// Obtains the plain-text length that is encoded in the cipher.
85  static bool getPlainTextLength( const char * preamble,
86  int preamble_length, int64 & length );
87 
88 
89  /// Decrypts the input buffer into output buffer. See UT_Blowfish::decrypt()
90  /// for details.
91  bool decrypt( const uint8 * input, uint8 * output,
92  int input_size );
93 
94  /// Gets the amount of memory owned by this UT_BlowfishStreamDecryptor
95  int64 getMemoryUsage(bool inclusive) const;
96 
97 private:
98  UT_Blowfish * myDecryptor; // helper doing the decryption job
99 };
100 
101 #endif // __UT_BlowfishIO__
102 
103 
104 
int getVersion(int version)
Definition: ImfVersion.h:116
virtual int getDataChunkLength(int buffer_size)
virtual int endFilter(char *, int)
#define UT_API
Definition: UT_API.h:13
GLuint buffer
Definition: glcorearb.h:659
virtual int beginFilter(char *, int, int)
long long int64
Definition: SYS_Types.h:107
GT_API const UT_StringHolder version
unsigned char uint8
Definition: SYS_Types.h:32
png_infop png_bytep png_size_t buffer_size
Definition: png.h:2124
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
virtual int doFilterChunk(char *buffer, int data_size, int buffer_size)=0