MCPcopy Create free account
hub / github.com/bwapi/bwapi / calc

Function calc

bwapi/Util/Source/Util/Sha1.cpp:111–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109 }
110
111 void calc(const void *src, const int bytelength, unsigned char *hash)
112 {
113 // Init the result array, and create references to the five unsigned integers for better readabillity.
114 unsigned int result[5]={0x67452301,0xEFCDAB89,0x98BADCFE,0x10325476,0xC3D2E1F0};
115
116 const unsigned char *sarray=(const unsigned char*)src;
117 // The variables
118 unsigned int w[80];
119 int j,i,i1;
120 j=0;
121 // Loop through all complete 64byte blocks.
122 for(i=0,i1=64; i<=(bytelength-64); i=i1,i1+=64)
123 {
124 int k=0;
125 for(j=i;j<i1;j+=4)
126 {
127 // This line will swap endian on big endian and keep endian on little endian.
128 w[k++]=(unsigned int)sarray[j+3]|(((unsigned int)sarray[j+2])<<8)|(((unsigned int)sarray[j+1])<<16)|(((unsigned int)sarray[j])<<24);
129 }
130 innerHash(result,w);
131 }
132 // fill in reminder
133 i1=bytelength-i;
134 memset(w,0,sizeof(unsigned int)*16);
135 for(j=0;j<i1;j++)
136 {
137 w[j>>2]|=(unsigned int)sarray[j+i]<<((3-(j&3))<<3);
138 }
139 w[j>>2]|=0x80<<((3-(j&3))<<3);
140 if(i1>=56)
141 {
142 innerHash(result,w);
143 memset(w,0,sizeof(unsigned int)*16);
144 }
145 w[15]=bytelength<<3;
146 innerHash(result,w);
147 // Store hash in result pointer, and make sure we get in in the correct order on both endian models.
148 for(i=20;--i>=0;)
149 {
150 hash[i]=(result[i>>2]>>(((3-i)&0x3)<<3))&0xFF;
151 }
152 }
153
154 void toHexString(const unsigned char *hash, char *hexstring)
155 {

Callers 1

calculateMapHashMethod · 0.85

Calls 1

innerHashFunction · 0.85

Tested by

no test coverage detected