00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : AbstractMDHash 00006 * Package : Zeus.ZeusBase.Security 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 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 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 /* CODE INFORMATION: 00033 The main code of this class has been taken from the "OpenSSL" Library. 00034 Copyright information from OpenSSL: 00035 */ 00036 /* ==================================================================== 00037 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 00038 * 00039 * Redistribution and use in source and binary forms, with or without 00040 * modification, are permitted provided that the following conditions 00041 * are met: 00042 * 00043 * 1. Redistributions of source code must retain the above copyright 00044 * notice, this list of conditions and the following disclaimer. 00045 * 00046 * 2. Redistributions in binary form must reproduce the above copyright 00047 * notice, this list of conditions and the following disclaimer in 00048 * the documentation and/or other materials provided with the 00049 * distribution. 00050 * 00051 * 3. All advertising materials mentioning features or use of this 00052 * software must display the following acknowledgment: 00053 * "This product includes software developed by the OpenSSL Project 00054 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 00055 * 00056 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 00057 * endorse or promote products derived from this software without 00058 * prior written permission. For written permission, please contact 00059 * licensing@OpenSSL.org. 00060 * 00061 * 5. Products derived from this software may not be called "OpenSSL" 00062 * nor may "OpenSSL" appear in their names without prior written 00063 * permission of the OpenSSL Project. 00064 * 00065 * 6. Redistributions of any form whatsoever must retain the following 00066 * acknowledgment: 00067 * "This product includes software developed by the OpenSSL Project 00068 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 00069 * 00070 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 00071 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00072 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00073 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 00074 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00075 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00076 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00077 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00078 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00079 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00080 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00081 * OF THE POSSIBILITY OF SUCH DAMAGE. 00082 * ==================================================================== 00083 * 00084 */ 00085 00086 #ifndef AbstractMDHashH 00087 #define AbstractMDHashH 00088 00089 #include <zeusbase/Security/AbstractHash.hpp> 00090 00091 BEGIN_NAMESPACE_Zeus 00092 00093 /***************************************************************************/ 00097 /***************************************************************************/ 00098 zeusbase_class TAbstractMDHash : public TAbstractHash 00099 { 00100 public: 00101 TAbstractMDHash(); 00102 00103 virtual Retval getHMAC(const IByteArray& rKey, 00104 const IByteArray& rInput, 00105 IByteArray& rOutput); 00106 00107 protected: 00109 static const Uint8 m_ucFillBuffer[64]; 00110 00111 /*************************************************************************/ 00114 /*************************************************************************/ 00115 struct TypeMD_CTX 00116 { 00117 Uint32 A; 00118 Uint32 B; 00119 Uint32 C; 00120 Uint32 D; 00121 00122 Uint64 uldTotalLen; 00123 Uint32 ulBufferLen; 00124 Uint8* paucBuffer; 00125 }; 00126 00127 void finishCTX(TypeMD_CTX& rCtx, IByteArray& rOutput); 00128 void freeCTX(TypeMD_CTX& rCTX); 00129 void processBytes(TypeMD_CTX& rCtx, const IByteArray& rInput); 00130 void processBytes(TypeMD_CTX& rCtx, const Uint8* pucBuffer, Int iSize); 00131 00132 /*************************************************************************/ 00135 /*************************************************************************/ 00136 virtual Int getBlockSize() const = 0; 00137 00138 /*************************************************************************/ 00141 /*************************************************************************/ 00142 virtual void initCTX(TypeMD_CTX& rCTX) = 0; 00143 00144 /*************************************************************************/ 00148 /*************************************************************************/ 00149 virtual void processBlock(TypeMD_CTX& rCtx, const Uint8* pucBuffer, Int iBlockNum) = 0; 00150 00151 //Methods of AbstractHash 00152 virtual Retval generate(const IByteArray& rInput, IByteArray& rOutput); 00153 }; 00154 00155 /*****************************************************************************/ 00158 /*****************************************************************************/ 00159 inline void TAbstractMDHash::processBytes(TypeMD_CTX& rCtx, const IByteArray& rInput) 00160 { 00161 processBytes(rCtx, (Uint8*)rInput.getArray(), rInput.getCount()); 00162 } 00163 00164 00165 END_NAMESPACE_Zeus 00166 00167 #endif