16 using namespace kome::core;
21 #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
22 #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
28 unsigned long Sha1::f(
const long t,
const unsigned long b,
const unsigned long c,
const unsigned long d ) {
30 return ( ( b & c ) | ( ~b & d ) );
36 return ( ( b & c ) | ( b & d ) | ( c & d ) );
64 unsigned char* uc = (
unsigned char*)src;
73 for(
unsigned int i = 0; i < 5; i++ ) {
74 s.append( FMT(
"%08x", context.
m_h[ i ] ) );
88 LOG_ERROR( FMT(
"Failed to open the file. [%s]", path ) );
96 unsigned char buff[ 0x1000 ];
98 while( ( readSize = fread( buff, 1, 0x1000, fp ) ) > 0 ) {
107 for(
unsigned int i = 0; i < 5; i++ ) {
108 s.append( FMT(
"%08x", context.
m_h[ i ] ) );
137 for(
unsigned int i = 0; i < length; i++ ) {
138 m_block[ m_pos++ ] = msg[ i ];
146 fillzero( m_block,
sizeof( m_block ) );
163 unsigned long w[ 80 ];
164 for(
int t = 0; t < 16; t++ ) {
165 unsigned long wt = 0;
166 for(
int i = 0; i < 4; i++ ) {
168 wt |= m_block[ t * 4 + i ];
172 for(
int t = 16; t < 80; t++ ) {
173 unsigned long wt = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
178 unsigned long a = m_h[ 0 ];
179 unsigned long b = m_h[ 1 ];
180 unsigned long c = m_h[ 2 ];
181 unsigned long d = m_h[ 3 ];
182 unsigned long e = m_h[ 4 ];
184 for(
int t = 0; t < 80; t++ ) {
204 m_block[ m_pos ] = 0x80;
207 fillzero( m_block,
sizeof( m_block ) );
211 unsigned long highLength = m_length >> 29;
212 unsigned long lowLength = m_length << 3;
214 m_block[ 56 ] = (
unsigned char)( ( highLength >> 24 ) & 0xff );
215 m_block[ 57 ] = (
unsigned char)( ( highLength >> 16 ) & 0xff );
216 m_block[ 58 ] = (
unsigned char)( ( highLength >> 8 ) & 0xff );
217 m_block[ 59 ] = (
unsigned char)( ( highLength ) & 0xff );
218 m_block[ 60 ] = (
unsigned char)( ( lowLength >> 24 ) & 0xff );
219 m_block[ 61 ] = (
unsigned char)( ( lowLength >> 16 ) & 0xff );
220 m_block[ 62 ] = (
unsigned char)( ( lowLength >> 8 ) & 0xff );
221 m_block[ 63 ] = (
unsigned char)( ( lowLength ) & 0xff );
227 m_h[ 0 ] = 0x67452301;
228 m_h[ 1 ] = 0xEFCDAB89;
229 m_h[ 2 ] = 0x98BADCFE;
230 m_h[ 3 ] = 0x10325476;
231 m_h[ 4 ] = 0xC3D2E1F0;
234 fillzero( m_block,
sizeof( m_block ) );
static unsigned long f(const long t, const unsigned long b, const unsigned long c, const unsigned long d)
logical function used in SHA1
static std::string transformFile(const char *path)
transform
void finish()
finishes to append message
void appendMessage(unsigned char *msg, const unsigned long length)
appends message
void padBlock()
pads block
#define CIRCULAR_LEFT_SHIFT(v, bits)
void reset()
resets member variables
FILE * fileopen(const char *path, const char *mode)
opens file
static std::string transformData(void *src, const unsigned int length)
transform data
virtual ~Sha1Context()
destructor
void updateHash()
updates hash
static unsigned long K(const long t)
constant word used in SHA1
interfarces of Sha1 class
void fillzero(void *p, size_t n)
This function fills a block of memory zeros.