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  ~UT_BlowfishEncryptFilter() override;
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  int getDataChunkLength( int buffer_size ) override;
38 
39  /// Writes out the length of the original stream to the buffer. It is used
40  /// when decrypting.
41  int beginFilter(char *buffer, int buffer_size,
42  int stream_size) override;
43 
44  /// Performs the encryption of the data in the buffer.
45  int doFilterChunk(char *buffer, int data_size,
46  int buffer_size) override;
47 
48  /// Writes out any remaining ciphertext that has not been written out yet,
49  /// and concludes encryption.
50  int endFilter( char *buffer, int buffer_size ) override;
51 
52  /// Gets the amount of memory owned by this UT_BlowfishEncryptFilter
53  virtual int64 getMemoryUsage(bool inclusive) const;
54 
55 private:
56  UT_Blowfish * myEncryptor; // helper doing the encryption job
57  bool myFullBlocksFlag; // true if no padding occured
58 };
59 
60 // Decrypts the stream encrypted with the filter above.
62 {
63 public:
64  // Constructor and destructor.
65  UT_BlowfishStreamDecryptor( const uint8 * key,
66  int key_length );
68 
71  = delete;
72 
73  /// Wrapper for UT_Blowfish::getEncryptionOutputSize()
74  static int getEncryptedSize( int plain_text_size );
75 
76  /// Wrapper for UT_Blowfish::getCryptBufferSize()
77  static int getCryptBufferSize( int max_buffer_size );
78 
79  /// Wrapper for UT_Blowfish::getBlockSize()
80  static int getBlockSize();
81 
82  /// Gets the preamble size. The pramble contains some meta-data such as
83  /// plain-text size, encryption version, and magic number.
84  static int getPreambleSize();
85 
86  /// Obtains the blowfish algorithm version used for the stream.
87  static bool getVersion( const char * preamble, int preamble_length,
88  int & version );
89 
90  /// Obtains the plain-text length that is encoded in the cipher.
91  static bool getPlainTextLength( const char * preamble,
92  int preamble_length, int64 & length );
93 
94 
95  /// Decrypts the input buffer into output buffer. See UT_Blowfish::decrypt()
96  /// for details.
97  bool decrypt( const uint8 * input, uint8 * output,
98  int input_size );
99 
100  /// Gets the amount of memory owned by this UT_BlowfishStreamDecryptor
101  int64 getMemoryUsage(bool inclusive) const;
102 
103 private:
104  UT_Blowfish * myDecryptor; // helper doing the decryption job
105 };
106 
107 #endif // __UT_BlowfishIO__
int getVersion(int version)
Definition: ImfVersion.h:99
virtual int getDataChunkLength(int buffer_size)
virtual int endFilter(char *, int)
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
#define UT_API
Definition: UT_API.h:14
virtual int beginFilter(char *, int, int)
unsigned char uint8
Definition: SYS_Types.h:36
Definition: core.h:760
long long int64
Definition: SYS_Types.h:116
GT_API const UT_StringHolder version
LeafData & operator=(const LeafData &)=delete
virtual int doFilterChunk(char *buffer, int data_size, int buffer_size)=0