forked from RATandC2/rogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHash.c
64 lines (58 loc) · 1.12 KB
/
Hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*!
*
* ROGUE
*
* GuidePoint Security LLC
*
* Threat and Attack Simulation Team
*
!*/
#include "Common.h"
/*!
*
* Purpose:
*
* Constructs a DJB2 hash representation of
* a string.
*
!*/
D_SEC( B ) UINT32 HashString( _In_ PVOID Buffer, _In_opt_ UINT32 Length )
{
UINT8 Chr = 0;
UINT32 Djb = 5381;
PUINT8 Ptr = NULL;
/* Set the initial buffer */
Ptr = C_PTR( Buffer );
while ( TRUE ) {
/* Get the current character */
Chr = * Ptr;
/* Is no length provided ? */
if ( ! Length ) {
/* NULL terminated */
if ( ! * Ptr ) {
/* Reached a null terminator. Abort */
break;
};
} else {
/* Did our position exceed the buffer? */
if ( ( UINT32 )( Ptr - ( PUINT8 ) Buffer ) >= Length ) {
/* Exceeded the length the buffer */
break;
};
/* NULL character? */
if ( ! * Ptr ) {
/* Increment and continue */
++Ptr; continue;
};
};
/* Is this a lowercase character? */
if ( Chr >= 'a' ) {
/* Decrement to uppercase */
Chr -= 0x20;
};
/* Create the character */
Djb = ( ( Djb << 5 ) + Djb ) + Chr; ++Ptr;
};
/* Return the hash */
return Djb ^ E_HSH_KEY;
};