1 /* 2 * Copyright (C) 2018 Rafael Ostertag 3 * 4 * This file is part of YAPET. 5 * 6 * YAPET is free software: you can redistribute it and/or modify it under the 7 * terms of the GNU General Public License as published by the Free Software 8 * Foundation, either version 3 of the License, or (at your option) any later 9 * version. 10 * 11 * YAPET is distributed in the hope that it will be useful, but WITHOUT ANY 12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 * details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * YAPET. If not, see <http://www.gnu.org/licenses/>. 18 * 19 * Additional permission under GNU GPL version 3 section 7 20 * 21 * If you modify this program, or any covered work, by linking or combining it 22 * with the OpenSSL project's OpenSSL library (or a modified version of that 23 * library), containing parts covered by the terms of the OpenSSL or SSLeay 24 * licenses, Rafael Ostertag grants you additional permission to convey the 25 * resulting work. Corresponding Source for a non-source form of such a 26 * combination shall include the source code for the parts of OpenSSL used as 27 * well as that of the covered work. 28 */ 29 30 #ifndef _KEY448_HH 31 #define _KEY448_HH 1 32 33 #include "key.hh" 34 #include "securearray.hh" 35 36 /** 37 * @brief Namespace for cryptographic stuff 38 * 39 * Namespace for cryptographic stuff. Has no front-end and relies on 40 * openssl. 41 */ 42 namespace yapet { 43 /** 44 * @brief Converts the password into the 448bits key 45 * 46 * Converts the password into the key which is used by the other 47 * cryptographic related classes. 48 * 49 * The key uses the maximum length of 448bits (56bytes) allowed 50 * for blowfish. 51 * 52 * The key is computed using three passes. The first pass hashes 53 * the password using the sha1 algorithm. This hash is then 54 * re-hashed using md5 which is then appended to the key generated 55 * by the previous pass (sha1 + md5). The last pass hashes the 56 * result of the former two passes using RIPEMD-160 and appended 57 * the result to the key (sha1 + md5 + ripemd160). 58 * 59 * The initialization vector is computed by hashing the key using 60 * the md5 algorithm and taking only the first eight bytes. 61 */ 62 class Key448 : public Key { 63 private: 64 /** 65 * @brief Holds the key 66 * 67 * This is the key used to encrypt and decrypt data. 68 */ 69 SecureArray _key; 70 /** 71 * @brief Holds the initialization vector 72 * 73 * The initialization vector used for encryption and 74 * decryption. 75 */ 76 SecureArray _ivec; 77 78 /** 79 * Only used to satisfy interface. No influence on key generation. 80 */ 81 MetaData _parameters; 82 83 public: 84 Key448(); 85 86 Key448(const Key448& k); 87 Key448& operator=(const Key448& k); 88 89 Key448(Key448&& k); 90 Key448& operator=(Key448&& key); ~Key448()91 ~Key448(){}; 92 93 /** 94 * This is a noop, this key does not support parameters. 95 */ 96 void keyingParameters(const MetaData& parameters); 97 98 /** 99 * Will always return empty meta data. 100 */ 101 const MetaData& keyingParameters() const; 102 103 void password(const SecureArray& password); 104 key() const105 SecureArray key() const { return _key; } 106 keySize() const107 SecureArray::size_type keySize() const { return _key.size(); } 108 ivec() const109 SecureArray ivec() const { return _ivec; } 110 ivecSize() const111 SecureArray::size_type ivecSize() const { return _ivec.size(); } 112 113 //! Compares two keys for equality 114 bool operator==(const Key448& k) const; 115 bool operator==(const Key& k) const; 116 117 //! Compares two keys for inequality 118 bool operator!=(const Key448& k) const; 119 bool operator!=(const Key& k) const; 120 }; 121 122 } // namespace yapet 123 124 #endif // _KEY448_HH 125