-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysha1.cpp
More file actions
45 lines (31 loc) · 1.07 KB
/
mysha1.cpp
File metadata and controls
45 lines (31 loc) · 1.07 KB
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
// my patches to sha1
// I have overwritten (replaced) sha1.h
#include "sha1.cpp"
//using namespace std;
// Don't have to worry about end case
// Just stream the bits from the files in 64 byte blocks
# define buffer_size 1
int SHA1::update_hashpiece(std::ifstream &is, int piecelength, int &fileindex, std::vector<string> &filelist){
char bigbuf[piecelength];
is.read(bigbuf,piecelength);
buffer.append(bigbuf, is.gcount());
while(buffer.size()!=piecelength){
is.close();
if (++fileindex==filelist.size()) break;
is.open(filelist[fileindex], std::ios::binary);
if(!is.is_open()) return 1;
is.read(bigbuf, piecelength - buffer.size());
buffer.append(bigbuf, is.gcount());
}
uint32_t block[BLOCK_INTS];
while ((transforms+1)*BLOCK_BYTES<=buffer.size()){
buffer_to_block(buffer.substr(transforms*BLOCK_BYTES, BLOCK_BYTES), block);
transform(digest, block, transforms);
}
buffer=buffer.substr(transforms*BLOCK_BYTES);
// assert (buffer.size()<BLOCK_BYTES);
// return buffer.size()>=BLOCK_BYTES;
return 0;
}
//int main(int argc, char *argv[]){
//}