PixelLightAPI  .
ChecksumSHA1.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ChecksumSHA1.h                                 *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser 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  *  PixelLight 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 Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_CHECKSUMSHA1_H__
00024 #define __PLCORE_CHECKSUMSHA1_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Tools/Checksum.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    SHA-1 (Secure Hash Algorithm) checksum
00046 *
00047 *  @remarks
00048 *    The Secure Hash Algorithm SHA-1 is a cryptographically secure one-way hash algorithm.
00049 *    It was designed by the NIST (National Institute of Standards and Technology), along
00050 *    with the NSA (National Security Agency). SHA-1 is based on the Message Digest MD4
00051 *    algorithm design principles by Ronald L. Rivest of MIT.
00052 *
00053 *    This implementation is basing on the 100% free public domain implementation of the
00054 *    SHA-1 algorithm by Dominik Reichl (http://www.dominik-reichl.de/)
00055 *
00056 *  @note
00057 *    - SHA-1 produces a 160-bit/20-byte hash
00058 */
00059 class ChecksumSHA1 : public Checksum {
00060 
00061 
00062     //[-------------------------------------------------------]
00063     //[ Public functions                                      ]
00064     //[-------------------------------------------------------]
00065     public:
00066         /**
00067         *  @brief
00068         *    Constructor
00069         */
00070         PLCORE_API ChecksumSHA1();
00071 
00072         /**
00073         *  @brief
00074         *    Destructor
00075         */
00076         PLCORE_API virtual ~ChecksumSHA1();
00077 
00078 
00079     //[-------------------------------------------------------]
00080     //[ Private functions                                     ]
00081     //[-------------------------------------------------------]
00082     private:
00083         /**
00084         *  @brief
00085         *    SHA-1 transformation
00086         *
00087         *  @param[in, out] nState
00088         *    State
00089         *  @param[in]      nBuffer
00090         *    Buffer
00091         */
00092         void Transform(uint32 nState[], const uint8 nBuffer[]) const;
00093 
00094 
00095     //[-------------------------------------------------------]
00096     //[ Private structures                                    ]
00097     //[-------------------------------------------------------]
00098     private:
00099         /**
00100         *  @brief
00101         *    Workspace block
00102         */
00103         typedef union {
00104             uint8  c[64];
00105             uint32 l[16];
00106         } WorkspaceBlock;
00107 
00108 
00109     //[-------------------------------------------------------]
00110     //[ Private data                                          ]
00111     //[-------------------------------------------------------]
00112     private:
00113         uint32          m_nState[5];
00114         uint32          m_nCount[2];
00115         uint8           m_nBuffer[64];
00116         uint8           m_nWorkspace[64];
00117         WorkspaceBlock *m_pBlock;           /**< SHA1 pointer to the byte array above (always valid!) */
00118 
00119 
00120     //[-------------------------------------------------------]
00121     //[ Private virtual Checksum functions                    ]
00122     //[-------------------------------------------------------]
00123     private:
00124         virtual void Update(const uint8 nInput[], uint32 nInputLen) override;
00125         virtual String Final() override;
00126 
00127 
00128 };
00129 
00130 
00131 //[-------------------------------------------------------]
00132 //[ Namespace                                             ]
00133 //[-------------------------------------------------------]
00134 } // PLCore
00135 
00136 
00137 #endif // __PLCORE_CHECKSUMSHA1_H__
00138 


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:52
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported