00001 /***************************************************************************** 00002 * Copyright (C) 2012 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : SecureHash160 00006 * Package : Zeus.ZeusBase.Security 00007 * Author : Benjamin Hadorn 00008 * Date : 01.01.2012 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 *****************************************************************************/ 00030 00031 #ifndef SecureHash160H 00032 #define SecureHash160H 00033 00034 #include <zeusbase/Security/AbstractHash.hpp> 00035 00036 BEGIN_NAMESPACE_Zeus 00037 00038 #define SHA160_DIGEST_SIZE 20 // 160 / 8 00039 #define SHA160_BLOCK_SIZE 64 // 512 / 8 00040 #define SHA160_LBLOCK (SHA160_BLOCK_SIZE/4) 00041 00042 /****************************************************************************/ 00046 /****************************************************************************/ 00047 zeusbase_class TSecureHash160 : public TAbstractHash 00048 { 00049 public: 00050 inline TSecureHash160() {} 00051 00052 void getHMAC(const IByteArray& rKey, 00053 const IByteArray& rInput, 00054 IByteArray& rOutput); 00055 00056 protected: 00057 00058 //Methods of AbstractHash 00059 virtual Retval generate(const IByteArray& rInput, IByteArray& rOutput); 00060 00061 /*************************************************************************/ 00064 /*************************************************************************/ 00065 struct TypeSHA160_CTX 00066 { 00067 Uint32 h[5]; 00068 00069 Uint64 uldTotalLen; 00070 Uint32 ulBufferLen; 00071 Uint8 aucBuffer[2*SHA160_BLOCK_SIZE]; 00072 }; 00073 00074 void finishCTX(TypeSHA160_CTX& rCtx, IByteArray& rOutput); 00075 void freeCTX(TypeSHA160_CTX& rCTX); 00076 void initCTX(TypeSHA160_CTX& rCtx); 00077 void processBytes(TypeSHA160_CTX& rCtx, const IByteArray& rInput); 00078 void processBytes(TypeSHA160_CTX& rCtx, const Uint8* puData, Uint uiSize); 00079 00080 void processBlock(TypeSHA160_CTX& rCtx, const Uint8* pucBuffer, Int iBlockNum); 00081 00082 private: 00083 }; 00084 00085 /*****************************************************************************/ 00088 /*****************************************************************************/ 00089 inline void TSecureHash160::processBytes(TypeSHA160_CTX& rCtx, const IByteArray& rInput) 00090 { 00091 processBytes(rCtx, (const Uint8*)rInput.getArray(), rInput.getCount()); 00092 } 00093 00094 END_NAMESPACE_Zeus 00095 00096 #endif