00001 // Filename: encryptStream.I 00002 // Created by: drose (01Sep04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: IDecryptStream::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE IDecryptStream:: 00022 IDecryptStream() : istream(&_buf) { 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: IDecryptStream::Constructor 00027 // Access: Published 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE IDecryptStream:: 00031 IDecryptStream(istream *source, bool owns_source, 00032 const string &password) : istream(&_buf) { 00033 open(source, owns_source, password); 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: IDecryptStream::open 00038 // Access: Published 00039 // Description: 00040 //////////////////////////////////////////////////////////////////// 00041 INLINE IDecryptStream &IDecryptStream:: 00042 open(istream *source, bool owns_source, const string &password) { 00043 clear((ios_iostate)0); 00044 _buf.open_read(source, owns_source, password); 00045 return *this; 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: IDecryptStream::close 00050 // Access: Published 00051 // Description: Resets the EncryptStream to empty, but does not actually 00052 // close the source istream unless owns_source was true. 00053 //////////////////////////////////////////////////////////////////// 00054 INLINE IDecryptStream &IDecryptStream:: 00055 close() { 00056 _buf.close_read(); 00057 return *this; 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: IDecryptStream::get_algorithm 00062 // Access: Published 00063 // Description: Returns the encryption algorithm that was read from 00064 // the stream. 00065 //////////////////////////////////////////////////////////////////// 00066 INLINE const string &IDecryptStream:: 00067 get_algorithm() const { 00068 return _buf.get_algorithm(); 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: IDecryptStream::get_key_length 00073 // Access: Published 00074 // Description: Returns the encryption key length, in bits, that was 00075 // read from the stream. 00076 //////////////////////////////////////////////////////////////////// 00077 INLINE int IDecryptStream:: 00078 get_key_length() const { 00079 return _buf.get_key_length(); 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: IDecryptStream::get_iteration_count 00084 // Access: Published 00085 // Description: Returns the value that was was read from the stream. 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE int IDecryptStream:: 00088 get_iteration_count() const { 00089 return _buf.get_iteration_count(); 00090 } 00091 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: OEncryptStream::Constructor 00095 // Access: Published 00096 // Description: 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE OEncryptStream:: 00099 OEncryptStream() : ostream(&_buf) { 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: OEncryptStream::Constructor 00104 // Access: Published 00105 // Description: 00106 //////////////////////////////////////////////////////////////////// 00107 INLINE OEncryptStream:: 00108 OEncryptStream(ostream *dest, bool owns_dest, const string &password) : 00109 ostream(&_buf) 00110 { 00111 open(dest, owns_dest, password); 00112 } 00113 00114 //////////////////////////////////////////////////////////////////// 00115 // Function: OEncryptStream::open 00116 // Access: Published 00117 // Description: 00118 //////////////////////////////////////////////////////////////////// 00119 INLINE OEncryptStream &OEncryptStream:: 00120 open(ostream *dest, bool owns_dest, const string &password) { 00121 clear((ios_iostate)0); 00122 _buf.open_write(dest, owns_dest, password); 00123 return *this; 00124 } 00125 00126 //////////////////////////////////////////////////////////////////// 00127 // Function: OEncryptStream::close 00128 // Access: Published 00129 // Description: Resets the EncryptStream to empty, but does not actually 00130 // close the dest ostream unless owns_dest was true. 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE OEncryptStream &OEncryptStream:: 00133 close() { 00134 _buf.close_write(); 00135 return *this; 00136 } 00137 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: OEncryptStream::set_algorithm 00141 // Access: Published 00142 // Description: Specifies the encryption algorithm that should be 00143 // used for future calls to open(). The default 00144 // is whatever is specified by the encryption-algorithm 00145 // config variable. The complete set of available 00146 // algorithms is defined by the current version of 00147 // OpenSSL. 00148 // 00149 // If an invalid algorithm is specified, there is no 00150 // immediate error return code, but open() will 00151 // fail. 00152 //////////////////////////////////////////////////////////////////// 00153 INLINE void OEncryptStream:: 00154 set_algorithm(const string &algorithm) { 00155 _buf.set_algorithm(algorithm); 00156 } 00157 00158 //////////////////////////////////////////////////////////////////// 00159 // Function: OEncryptStream::set_key_length 00160 // Access: Published 00161 // Description: Specifies the length of the key, in bits, that should 00162 // be used to encrypt the stream in future calls to 00163 // open(). The default is whatever is specified 00164 // by the encryption-key-length config variable. 00165 // 00166 // If an invalid key_length for the chosen algorithm is 00167 // specified, there is no immediate error return code, 00168 // but open() will fail. 00169 //////////////////////////////////////////////////////////////////// 00170 INLINE void OEncryptStream:: 00171 set_key_length(int key_length) { 00172 _buf.set_key_length(key_length); 00173 } 00174 00175 //////////////////////////////////////////////////////////////////// 00176 // Function: OEncryptStream::set_iteration_count 00177 // Access: Published 00178 // Description: Specifies the number of times to repeatedly hash the 00179 // key before writing it to the stream in future calls 00180 // to open(). Its purpose is to make it 00181 // computationally more expensive for an attacker to 00182 // search the key space exhaustively. This should be a 00183 // multiple of 1,000 and should not exceed about 65 00184 // million; the value 0 indicates just one application 00185 // of the hashing algorithm. 00186 // 00187 // The default is whatever is specified by the 00188 // encryption-iteration-count config variable. 00189 //////////////////////////////////////////////////////////////////// 00190 INLINE void OEncryptStream:: 00191 set_iteration_count(int iteration_count) { 00192 _buf.set_iteration_count(iteration_count); 00193 }