| 
    
       /*
 
     | 
  
  
     | 
    
        Copyright (c) 2003, Dominik Reichl <dominik.reichl@t-online.de>
 
     | 
  
  
     | 
    
        All rights reserved.
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        LICENSE TERMS
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        Redistribution and use in source and binary forms, with or without
 
     | 
  
  
     | 
    
        modification, are permitted provided that the following conditions are met:
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        * Redistributions of source code must retain the above copyright notice, this
 
     | 
  
  
     | 
    
          list of conditions and the following disclaimer.
 
     | 
  
  
     | 
    
        * Redistributions in binary form must reproduce the above copyright notice,
 
     | 
  
  
     | 
    
          this list of conditions and the following disclaimer in the documentation
 
     | 
  
  
     | 
    
          and/or other materials provided with the distribution.
 
     | 
  
  
     | 
    
        * Neither the name of ReichlSoft nor the names of its contributors may be used
 
     | 
  
  
     | 
    
          to endorse or promote products derived from this software without specific
 
     | 
  
  
     | 
    
          prior written permission.
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        DISCLAIMER
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
     | 
  
  
     | 
    
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
     | 
  
  
     | 
    
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
     | 
  
  
     | 
    
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 
     | 
  
  
     | 
    
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
     | 
  
  
     | 
    
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
     | 
  
  
     | 
    
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
     | 
  
  
     | 
    
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
     | 
  
  
     | 
    
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
     | 
  
  
     | 
    
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
     | 
  
  
     | 
    
       */
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       // This free implementation is based on Dr Brian Gladmans free implementation.
 
     | 
  
  
     | 
    
       // The source has been heavily modified to integrate to ReHash.
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       // Here's the original header:
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       /*
 
     | 
  
  
     | 
    
        ---------------------------------------------------------------------------
 
     | 
  
  
     | 
    
        Copyright (c) 2002, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
 
     | 
  
  
     | 
    
        All rights reserved.
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        LICENSE TERMS
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        The free distribution and use of this software in both source and binary
 
     | 
  
  
     | 
    
        form is allowed (with or without changes) provided that:
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
          1. distributions of this source code include the above copyright
 
     | 
  
  
     | 
    
             notice, this list of conditions and the following disclaimer;
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
          2. distributions in binary form include the above copyright
 
     | 
  
  
     | 
    
             notice, this list of conditions and the following disclaimer
 
     | 
  
  
     | 
    
             in the documentation and/or other associated materials;
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
          3. the copyright holder's name is not used to endorse products
 
     | 
  
  
     | 
    
             built using this software without specific written permission.
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        ALTERNATIVELY, provided that this notice is retained in full, this product
 
     | 
  
  
     | 
    
        may be distributed under the terms of the GNU General Public License (GPL),
 
     | 
  
  
     | 
    
        in which case the provisions of the GPL apply INSTEAD OF those given above.
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        DISCLAIMER
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        This software is provided 'as is' with no explicit or implied warranties
 
     | 
  
  
     | 
    
        in respect of its properties, including, but not limited to, correctness
 
     | 
  
  
     | 
    
        and/or fitness for purpose.
 
     | 
  
  
     | 
    
        ---------------------------------------------------------------------------
 
     | 
  
  
     | 
    
        Issue Date: 26/08/2003
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
        This is a byte oriented version of SHA1 that operates on arrays of bytes
 
     | 
  
  
     | 
    
        stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor
 
     | 
  
  
     | 
    
       */
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       #ifndef ___SHA1_H___
 
     | 
  
  
     | 
    
       #define ___SHA1_H___
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       #include "hashalgo.h"
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       #define SHA1_BLOCK_SIZE  64
 
     | 
  
  
     | 
    
       #define SHA1_DIGEST_SIZE 20
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       class CSHA1Hash : public CHashAlgorithm
 
     | 
  
  
     | 
    
       {
 
     | 
  
  
     | 
    
       public:
 
     | 
  
  
     | 
    
       	CSHA1Hash();
 
     | 
  
  
     | 
    
       	~CSHA1Hash();
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       	const char *GetName() { return "SHA1"; }
 
     | 
  
  
     | 
    
       	const char *GetShortName() { return "sha1"; }
 
     | 
  
  
     | 
    
       	UINTPREF GetLength() { return 20; }
 
     | 
  
  
     | 
    
       	UINTPREF GetInternalLength() { return 64; }
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       	void Init(RH_DATA_INFO *pInfo);
 
     | 
  
  
     | 
    
       	void Update(const UWORD8 *pBuf, UINTPREF uLen);
 
     | 
  
  
     | 
    
       	void Final();
 
     | 
  
  
     | 
    
       	void GetHash(UWORD8 *pHash) { memcpy(pHash, m_final, 20); }
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       private:
 
     | 
  
  
     | 
    
       	void _Compile();
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       	UWORD32 m_count[2];
 
     | 
  
  
     | 
    
       	UWORD32 m_hash[5];
 
     | 
  
  
     | 
    
       	UWORD32 m_wbuf[16];
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       	UWORD8 m_final[20];
 
     | 
  
  
     | 
    
       };
 
     | 
  
  
     | 
    
       
     | 
  
  
     | 
    
       #endif // ___SHA1_H___
 
     |