CSHA1 Class Reference

#include <SHA1.h>

List of all members.

Public Member Functions

 CSHA1 ()
 ~CSHA1 ()
void Reset ()
void Update (UINT_8 *data, UINT_32 len)
void Final ()
void GetHash (UINT_8 *puDest)

Public Attributes

UINT_32 m_state [5]
UINT_32 m_count [2]
UINT_32 __reserved1 [1]
UINT_8 m_buffer [64]
UINT_8 m_digest [20]
UINT_32 __reserved2 [3]

Private Member Functions

void Transform (UINT_32 *state, UINT_8 *buffer)

Private Attributes

UINT_8 m_workspace [64]
SHA1_WORKSPACE_BLOCKm_block

Detailed Description

Definition at line 97 of file SHA1.h.


Constructor & Destructor Documentation

CSHA1::CSHA1 (  ) 

Definition at line 64 of file SHA1.cc.

00065 {
00066     m_block = (SHA1_WORKSPACE_BLOCK *)m_workspace;
00067 
00068     Reset();
00069 }

CSHA1::~CSHA1 (  ) 

Definition at line 71 of file SHA1.cc.

00072 {
00073     Reset();
00074 }


Member Function Documentation

void CSHA1::Final (  ) 

Definition at line 263 of file SHA1.cc.

Referenced by I3Identifier::createFromHash(), SimpleNodeEntry::getFaultyDelay(), DHT::handleGetRequest(), and OverlayKey::sha1().

00264 {
00265     UINT_32 i;
00266     UINT_8 finalcount[8];
00267 
00268     for(i = 0; i < 8; i++)
00269         finalcount[i] = (UINT_8)((m_count[((i >= 4) ? 0 : 1)]
00270                                   >> ((3 - (i & 3)) * 8) ) & 255); // Endian independent
00271 
00272     Update((UINT_8 *)"\200", 1);
00273 
00274     while ((m_count[0] & 504) != 448)
00275         Update((UINT_8 *)"\0", 1);
00276 
00277     Update(finalcount, 8); // Cause a SHA1Transform()
00278 
00279     for(i = 0; i < 20; i++) {
00280         m_digest[i] = (UINT_8)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255);
00281     }
00282 
00283     // Wipe variables for security reasons
00284 #ifdef SHA1_WIPE_VARIABLES
00285     i = 0;
00286     memset(m_buffer, 0, 64);
00287     memset(m_state, 0, 20);
00288     memset(m_count, 0, 8);
00289     memset(finalcount, 0, 8);
00290     Transform(m_state, m_buffer);
00291 #endif
00292 }

void CSHA1::GetHash ( UINT_8 *  puDest  ) 

Definition at line 326 of file SHA1.cc.

Referenced by I3Identifier::createFromHash(), SimpleNodeEntry::getFaultyDelay(), DHT::handleGetRequest(), and OverlayKey::sha1().

00327 {
00328     memcpy(puDest, m_digest, 20);
00329 }

void CSHA1::Reset (  ) 

Definition at line 76 of file SHA1.cc.

Referenced by I3Identifier::createFromHash(), CSHA1(), SimpleNodeEntry::getFaultyDelay(), DHT::handleGetRequest(), OverlayKey::sha1(), and ~CSHA1().

00077 {
00078     // SHA1 initialization constants
00079     m_state[0] = 0x67452301;
00080     m_state[1] = 0xEFCDAB89;
00081     m_state[2] = 0x98BADCFE;
00082     m_state[3] = 0x10325476;
00083     m_state[4] = 0xC3D2E1F0;
00084 
00085     m_count[0] = 0;
00086     m_count[1] = 0;
00087 }

void CSHA1::Transform ( UINT_32 *  state,
UINT_8 *  buffer 
) [private]

Definition at line 89 of file SHA1.cc.

Referenced by Final(), and Update().

00090 {
00091     // Copy state[] to working vars
00092     UINT_32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
00093 
00094     memcpy(m_block, buffer, 64);
00095 
00096     // 4 rounds of 20 operations each. Loop unrolled.
00097     _R0(a,b,c,d,e, 0);
00098     _R0(e,a,b,c,d, 1);
00099     _R0(d,e,a,b,c, 2);
00100     _R0(c,d,e,a,b, 3);
00101     _R0(b,c,d,e,a, 4);
00102     _R0(a,b,c,d,e, 5);
00103     _R0(e,a,b,c,d, 6);
00104     _R0(d,e,a,b,c, 7);
00105     _R0(c,d,e,a,b, 8);
00106     _R0(b,c,d,e,a, 9);
00107     _R0(a,b,c,d,e,10);
00108     _R0(e,a,b,c,d,11);
00109     _R0(d,e,a,b,c,12);
00110     _R0(c,d,e,a,b,13);
00111     _R0(b,c,d,e,a,14);
00112     _R0(a,b,c,d,e,15);
00113     _R1(e,a,b,c,d,16);
00114     _R1(d,e,a,b,c,17);
00115     _R1(c,d,e,a,b,18);
00116     _R1(b,c,d,e,a,19);
00117     _R2(a,b,c,d,e,20);
00118     _R2(e,a,b,c,d,21);
00119     _R2(d,e,a,b,c,22);
00120     _R2(c,d,e,a,b,23);
00121     _R2(b,c,d,e,a,24);
00122     _R2(a,b,c,d,e,25);
00123     _R2(e,a,b,c,d,26);
00124     _R2(d,e,a,b,c,27);
00125     _R2(c,d,e,a,b,28);
00126     _R2(b,c,d,e,a,29);
00127     _R2(a,b,c,d,e,30);
00128     _R2(e,a,b,c,d,31);
00129     _R2(d,e,a,b,c,32);
00130     _R2(c,d,e,a,b,33);
00131     _R2(b,c,d,e,a,34);
00132     _R2(a,b,c,d,e,35);
00133     _R2(e,a,b,c,d,36);
00134     _R2(d,e,a,b,c,37);
00135     _R2(c,d,e,a,b,38);
00136     _R2(b,c,d,e,a,39);
00137     _R3(a,b,c,d,e,40);
00138     _R3(e,a,b,c,d,41);
00139     _R3(d,e,a,b,c,42);
00140     _R3(c,d,e,a,b,43);
00141     _R3(b,c,d,e,a,44);
00142     _R3(a,b,c,d,e,45);
00143     _R3(e,a,b,c,d,46);
00144     _R3(d,e,a,b,c,47);
00145     _R3(c,d,e,a,b,48);
00146     _R3(b,c,d,e,a,49);
00147     _R3(a,b,c,d,e,50);
00148     _R3(e,a,b,c,d,51);
00149     _R3(d,e,a,b,c,52);
00150     _R3(c,d,e,a,b,53);
00151     _R3(b,c,d,e,a,54);
00152     _R3(a,b,c,d,e,55);
00153     _R3(e,a,b,c,d,56);
00154     _R3(d,e,a,b,c,57);
00155     _R3(c,d,e,a,b,58);
00156     _R3(b,c,d,e,a,59);
00157     _R4(a,b,c,d,e,60);
00158     _R4(e,a,b,c,d,61);
00159     _R4(d,e,a,b,c,62);
00160     _R4(c,d,e,a,b,63);
00161     _R4(b,c,d,e,a,64);
00162     _R4(a,b,c,d,e,65);
00163     _R4(e,a,b,c,d,66);
00164     _R4(d,e,a,b,c,67);
00165     _R4(c,d,e,a,b,68);
00166     _R4(b,c,d,e,a,69);
00167     _R4(a,b,c,d,e,70);
00168     _R4(e,a,b,c,d,71);
00169     _R4(d,e,a,b,c,72);
00170     _R4(c,d,e,a,b,73);
00171     _R4(b,c,d,e,a,74);
00172     _R4(a,b,c,d,e,75);
00173     _R4(e,a,b,c,d,76);
00174     _R4(d,e,a,b,c,77);
00175     _R4(c,d,e,a,b,78);
00176     _R4(b,c,d,e,a,79);
00177 
00178     // Add the working vars back into state
00179     state[0] += a;
00180     state[1] += b;
00181     state[2] += c;
00182     state[3] += d;
00183     state[4] += e;
00184 
00185     // Wipe variables
00186 #ifdef SHA1_WIPE_VARIABLES
00187 
00188     a = b = c = d = e = 0;
00189 #endif
00190 }

void CSHA1::Update ( UINT_8 *  data,
UINT_32  len 
)

Definition at line 193 of file SHA1.cc.

Referenced by I3Identifier::createFromHash(), Final(), SimpleNodeEntry::getFaultyDelay(), DHT::handleGetRequest(), and OverlayKey::sha1().

00194 {
00195     UINT_32 i, j;
00196 
00197     j = (m_count[0] >> 3) & 63;
00198 
00199     if((m_count[0] += len << 3) < (len << 3))
00200         m_count[1]++;
00201 
00202     m_count[1] += (len >> 29);
00203 
00204     if((j + len) > 63) {
00205         i = 64 - j;
00206         memcpy(&m_buffer[j], data, i);
00207         Transform(m_state, m_buffer);
00208 
00209         for( ; i + 63 < len; i += 64)
00210             Transform(m_state, &data[i]);
00211 
00212         j = 0;
00213     } else
00214         i = 0;
00215 
00216     memcpy(&m_buffer[j], &data[i], len - i);
00217 }


Member Data Documentation

UINT_32 CSHA1::__reserved1[1]

Definition at line 115 of file SHA1.h.

UINT_32 CSHA1::__reserved2[3]

Definition at line 118 of file SHA1.h.

Definition at line 146 of file SHA1.h.

Referenced by CSHA1(), and Transform().

UINT_8 CSHA1::m_buffer[64]

Definition at line 116 of file SHA1.h.

Referenced by Final(), and Update().

UINT_32 CSHA1::m_count[2]

Definition at line 114 of file SHA1.h.

Referenced by Final(), Reset(), and Update().

UINT_8 CSHA1::m_digest[20]

Definition at line 117 of file SHA1.h.

Referenced by Final(), and GetHash().

UINT_32 CSHA1::m_state[5]

Definition at line 113 of file SHA1.h.

Referenced by Final(), Reset(), and Update().

UINT_8 CSHA1::m_workspace[64] [private]

Definition at line 145 of file SHA1.h.

Referenced by CSHA1().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3