00001 // -*- c++ -*- 00002 // 00003 // $Id: key.h 2361 2009-06-11 15:06:39Z rafi $ 00004 // 00005 // Copyright (C) 2008, 2009 Rafael Ostertag 00006 // 00007 // This file is part of YAPET. 00008 // 00009 // YAPET is free software: you can redistribute it and/or modify it under the 00010 // terms of the GNU General Public License as published by the Free Software 00011 // Foundation, either version 3 of the License, or (at your option) any later 00012 // version. 00013 // 00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY 00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00017 // details. 00018 // 00019 // You should have received a copy of the GNU General Public License along with 00020 // YAPET. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 // Additional permission under GNU GPL version 3 section 7 00023 // 00024 // If you modify this program, or any covered work, by linking or combining it 00025 // with the OpenSSL project's OpenSSL library (or a modified version of that 00026 // library), containing parts covered by the terms of the OpenSSL or SSLeay 00027 // licenses, Rafael Ostertag grants you additional permission to convey the 00028 // resulting work. Corresponding Source for a non-source form of such a 00029 // combination shall include the source code for the parts of OpenSSL used as 00030 // well as that of the covered work. 00031 // 00032 00033 #ifndef _KEY_H 00034 #define _KEY_H 00035 00036 #ifdef HAVE_CONFIG_H 00037 # include <config.h> 00038 #endif 00039 00040 #ifdef HAVE_INTTYPES_H 00041 # include <inttypes.h> 00042 #endif 00043 00044 #include <openssl/evp.h> 00045 00046 #include "yapetexception.h" 00047 00054 namespace YAPET { 00074 class Key { 00075 private: 00076 enum { 00080 KEYLENGTH = 56, 00084 MD5_LEN = 16, 00085 00089 SHA1_LEN = 20, 00093 RIPEMD160_LEN = 20, 00097 IVECLENGTH = 8 00098 }; 00099 00105 uint8_t key[KEYLENGTH]; 00112 uint8_t IVec[IVECLENGTH]; 00113 00115 void cleanup(); 00116 00117 public: 00119 Key(const char* password) throw(YAPETException); 00120 Key(const Key& k); 00121 ~Key(); 00122 00136 inline const uint8_t* getKey(int& key_len) const { 00137 key_len = KEYLENGTH; 00138 return key; 00139 } 00140 00151 inline const uint8_t* getKey() const { return key; } 00152 00167 inline const uint8_t* getIVec(int& ivec_len) const { 00168 ivec_len = IVECLENGTH; 00169 return IVec; 00170 } 00171 00183 inline const uint8_t* getIVec() const { return IVec; } 00184 00192 inline uint32_t size() const { return KEYLENGTH; } 00193 00202 inline uint32_t ivec_size() const { return IVECLENGTH; } 00203 00217 inline const uint8_t* operator()(int& key_len) const { return getKey(key_len); } 00218 00229 inline const uint8_t* operator()() const { return key; } 00230 00236 inline operator uint8_t*() { return key; } 00237 00243 inline operator const uint8_t*() const { return key; } 00244 00245 const Key& operator=(const Key& k); 00247 bool operator==(const Key& k) const; 00249 bool operator!=(const Key& k) const { return !operator==(k); } 00250 }; 00251 00252 } 00253 00254 #endif // _KEY_H