Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_sha1.h

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library 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 GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 
00034 #ifndef __PANA_SHA1_H__
00035 #define __PANA_SHA1_H__
00036 
00037 #ifndef LITTLE_ENDIAN
00038 #define LITTLE_ENDIAN
00039 #endif // LITTLE_ENDIAN
00040 
00041 class PANA_Sha1
00042 {
00043     public:
00047             PANA_Sha1();
00048 
00052             virtual ~PANA_Sha1();
00053 
00054         // Rotate x bits to the left
00055         #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits))))
00056 
00057         #ifdef LITTLE_ENDIAN
00058                 #define SHABLK0(i) (m_block->l[i] = \
00059                         (ROL32(m_block->l[i],24) & 0xFF00FF00) | (ROL32(m_block->l[i],8) & 0x00FF00FF))
00060         #else
00061                 #define SHABLK0(i) (m_block->l[i])
00062         #endif
00063 
00064         #define SHABLK(i) (m_block->l[i&15] = ROL32(m_block->l[(i+13)&15] ^ m_block->l[(i+8)&15] \
00065                 ^ m_block->l[(i+2)&15] ^ m_block->l[i&15],1))
00066 
00067         // SHA-1 rounds
00068         #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
00069         #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
00070         #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); }
00071         #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); }
00072         #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); }
00073 
00074         typedef union {
00075                 unsigned char c[64];
00076                 unsigned long l[16];
00077         } SHA1_WORKSPACE_BLOCK;
00078 
00079         // Two different formats for ReportHash(...)
00080         enum {
00081                 REPORT_HEX = 0,
00082                 REPORT_DIGIT = 1
00083         };
00084 
00085             unsigned long m_state[5];
00086             unsigned long m_count[2];
00087             unsigned char m_buffer[64];
00088             unsigned char m_digest[20];
00089 
00093             void Reset();
00094 
00101             void Update(unsigned char* data, unsigned int len);
00102 
00106             void Final();
00107 
00114             void ReportHash(char *report, unsigned char type = REPORT_HEX);
00115 
00121             void GetHash(unsigned char *uDest);
00122 
00123     private:
00127         void Transform(unsigned long state[5], unsigned char buffer[64]);
00128 
00129         unsigned char m_workspace[64]; 
00131         SHA1_WORKSPACE_BLOCK* m_block; 
00132 };
00133 
00134 #endif // __PANA_SHA1_H__

Generated on Fri Jun 25 19:18:30 2004 for PANA by doxygen 1.3.5