crypt/key.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: key.h,v 1.6 2008-02-11 16:51:38 rafi Exp $
00004 //
00005 // YAPET -- Yet Another Password Encryption Tool
00006 // Copyright (C) 2008  Rafael Ostertag
00007 //
00008 // This program is free software: you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation, either version 3 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 //
00021 
00022 #ifndef _KEY_H
00023 #define _KEY_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #ifdef HAVE_INTTYPES_H
00030 # include <inttypes.h>
00031 #endif
00032 
00033 #include <openssl/evp.h>
00034 
00035 #include "yapetexception.h"
00036 
00043 namespace YAPET {
00063     class Key {
00064     private:
00065         enum { 
00069         KEYLENGTH = 56,
00073         MD5_LEN = 16,
00074 
00078         SHA1_LEN = 20,
00082         RIPEMD160_LEN = 20,
00086         IVECLENGTH = 8
00087         };
00088         
00094         uint8_t key[KEYLENGTH];
00101         uint8_t IVec[IVECLENGTH];
00102 
00104         void cleanup();
00105 
00106     public:
00108         Key(const char* password) throw(YAPETException);
00109         Key(const Key& k);
00110         ~Key();
00111 
00125         inline const uint8_t* getKey(int& key_len) const {
00126         key_len = KEYLENGTH;
00127         return key;
00128         }
00129 
00140         inline const uint8_t* getKey() const { return key; }
00141         
00156         inline const uint8_t* getIVec(int& ivec_len) const {
00157         ivec_len = IVECLENGTH;
00158         return IVec;
00159         }
00160 
00172         inline const uint8_t* getIVec() const { return IVec; }
00173 
00181         inline uint32_t size() const { return KEYLENGTH; }
00182 
00191         inline uint32_t ivec_size() const { return IVECLENGTH; }
00192 
00206         inline const uint8_t* operator()(int& key_len) const { return getKey(key_len); }
00207 
00218         inline const uint8_t* operator()() const { return key; }
00219 
00225         inline operator uint8_t*() { return key; }
00226 
00232         inline operator const uint8_t*() const { return key; }
00233 
00234         const Key& operator=(const Key& k);
00236         bool operator==(const Key& k) const;
00238         bool operator!=(const Key& k) const { return !operator==(k); }
00239     };
00240         
00241 }
00242 
00243 #endif // _KEY_H

Generated on Wed Feb 27 16:15:41 2008 for YAPET by  doxygen 1.5.4