Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Classes | Static Public Member Functions | Static Protected Member Functions | List of all members
kome::core::Sha1 Class Reference

the class computing SHA1 hash More...

#include <Sha1.h>

Classes

class  Sha1Context
 SHA1 context. More...
 

Static Public Member Functions

static std::string transformData (void *src, const unsigned int length)
 transform data More...
 
static std::string transformFile (const char *path)
 transform More...
 

Static Protected Member Functions

static unsigned long f (const long t, const unsigned long b, const unsigned long c, const unsigned long d)
 logical function used in SHA1 More...
 
static unsigned long K (const long t)
 constant word used in SHA1 More...
 

Detailed Description

the class computing SHA1 hash

Definition at line 22 of file Sha1.h.

Member Function Documentation

static unsigned long kome::core::Sha1::f ( const long  t,
const unsigned long  b,
const unsigned long  c,
const unsigned long  d 
)
staticprotected

logical function used in SHA1

Parameters
[in]tt count
[in]bvariable B
[in]cvariable C
[in]dvariable D
Returns
computed value

Definition at line 28 of file Sha1.cpp.

28  {
29  if( t < 20 ) {
30  return ( ( b & c ) | ( ~b & d ) );
31  }
32  if( t < 40 ) {
33  return ( b ^ c ^ d );
34  }
35  if( t < 60 ) {
36  return ( ( b & c ) | ( b & d ) | ( c & d ) );
37  }
38  if( t < 80 ) {
39  return ( b ^ c ^ d );
40  }
41  return 0;
42 }
static unsigned long kome::core::Sha1::K ( const long  t)
staticprotected

constant word used in SHA1

Parameters
[in]tt count
Returns
constant word

Definition at line 45 of file Sha1.cpp.

45  {
46  if( t < 20 ) {
47  return 0x5A827999;
48  }
49  if( t < 40 ) {
50  return 0x6ED9EBA1;
51  }
52  if( t < 60 ) {
53  return 0x8F1BBCDC;
54  }
55  if( t < 80 ) {
56  return 0xCA62C1D6;
57  }
58  return 0;
59 }
static std::string kome::core::Sha1::transformData ( void *  src,
const unsigned int  length 
)
static

transform data

Parameters
[in]srcsource data
[in]lengthdata length
Returns
SHA-1 string

Definition at line 62 of file Sha1.cpp.

62  {
63  // cast
64  unsigned char* uc = (unsigned char*)src;
65 
66  // context
67  Sha1Context context;
68  context.appendMessage( uc, length );
69  context.finish();
70 
71  // get string
72  std::string s;
73  for( unsigned int i = 0; i < 5; i++ ) {
74  s.append( FMT( "%08x", context.m_h[ i ] ) );
75  }
76 
77  return s;
78 }

Here is the call graph for this function:

static std::string kome::core::Sha1::transformFile ( const char *  path)
static

transform

Parameters
[in]pathfile path
Returns
SHA-1 string

Definition at line 81 of file Sha1.cpp.

81  {
82  // string
83  std::string s;
84 
85  // open the file
86  FILE* fp = fileopen( path, "rb" );
87  if( fp == NULL ) {
88  LOG_ERROR( FMT( "Failed to open the file. [%s]", path ) );
89  return s;
90  }
91 
92  // context
93  Sha1Context context;
94 
95  // read the file
96  unsigned char buff[ 0x1000 ];
97  int readSize = 0;
98  while( ( readSize = fread( buff, 1, 0x1000, fp ) ) > 0 ) {
99  context.appendMessage( buff, readSize );
100  }
101  context.finish();
102 
103  // close file
104  fclose( fp );
105 
106  // get string
107  for( unsigned int i = 0; i < 5; i++ ) {
108  s.append( FMT( "%08x", context.m_h[ i ] ) );
109  }
110 
111  return s;
112 }
#define NULL
Definition: CoreMacros.h:18
FILE * fileopen(const char *path, const char *mode)
opens file

Here is the call graph for this function:


The documentation for this class was generated from the following files: