|
17 | 17 | #include <dirent.h> |
18 | 18 | #include <algorithm> |
19 | 19 | #include <sys/stat.h> |
20 | | -#include <openssl/md5.h> |
| 20 | +#include <openssl/sha.h> |
21 | 21 |
|
22 | 22 | using namespace std; |
23 | 23 |
|
24 | 24 | const char* arg0; |
25 | 25 |
|
26 | | -// Key=path, Value=MD5: |
| 26 | +// Key=path, Value=SHA256: |
27 | 27 | typedef pair<string, string> Pair; |
28 | 28 | typedef map<string, string> Map; |
29 | 29 |
|
@@ -64,27 +64,26 @@ static bool LoadFile( |
64 | 64 | return true; |
65 | 65 | } |
66 | 66 |
|
67 | | -static bool FindMD5( |
| 67 | +static bool FindSHA( |
68 | 68 | const char* path, |
69 | | - string& md5) |
| 69 | + string& sha256) |
70 | 70 | { |
71 | 71 | vector<char> data; |
72 | 72 |
|
73 | 73 | if (!LoadFile(path, data)) |
74 | 74 | return false; |
75 | 75 |
|
76 | 76 | { |
77 | | - MD5_CTX ctx; |
78 | | - MD5_Init(&ctx); |
79 | | - MD5_Update(&ctx, &data[0], data.size()); |
80 | | - unsigned char digest[MD5_DIGEST_LENGTH]; |
81 | | - MD5_Final(digest, &ctx); |
82 | | - |
83 | | - for (size_t i = 0; i < MD5_DIGEST_LENGTH; i++) |
| 77 | + SHA256_CTX ctx; |
| 78 | + SHA256_Init(&ctx); |
| 79 | + SHA256_Update(&ctx, &data[0], data.size()); |
| 80 | + unsigned char digest[SHA256_DIGEST_LENGTH]; |
| 81 | + SHA256_Final(digest, &ctx); |
| 82 | + for (size_t i = 0; i < SHA256_DIGEST_LENGTH; i++) |
84 | 83 | { |
85 | 84 | char buf[3]; |
86 | 85 | sprintf(buf, "%02X", digest[i]); |
87 | | - md5 += buf; |
| 86 | + sha256 += buf; |
88 | 87 | } |
89 | 88 | } |
90 | 89 |
|
@@ -142,20 +141,20 @@ static void Scan( |
142 | 141 | { |
143 | 142 | dirs.push_back(path); |
144 | 143 |
|
145 | | - string md5 = "00000000000000000000000000000000"; |
146 | | - files.insert(Pair(path, md5)); |
| 144 | + string sha256 = "0000000000000000000000000000000000000000000000000000000000000000"; |
| 145 | + files.insert(Pair(path, sha256)); |
147 | 146 | } |
148 | 147 | else |
149 | 148 | { |
150 | | - string md5; |
| 149 | + string sha256; |
151 | 150 |
|
152 | | - if (!FindMD5(path.c_str(), md5)) |
| 151 | + if (!FindSHA(path.c_str(), sha256)) |
153 | 152 | { |
154 | | - fprintf(stderr, "%s: failed to find MD5: %s\n", |
| 153 | + fprintf(stderr, "%s: failed to find SHA256: %s\n", |
155 | 154 | arg0, path.c_str()); |
156 | 155 | } |
157 | 156 |
|
158 | | - files.insert(Pair(path, md5)); |
| 157 | + files.insert(Pair(path, sha256)); |
159 | 158 | } |
160 | 159 | } |
161 | 160 |
|
@@ -198,9 +197,9 @@ static bool WriteChangesFile( |
198 | 197 | while (p != end) |
199 | 198 | { |
200 | 199 | string path = (*p).first; |
201 | | - string md5 = (*p).second; |
| 200 | + string sha256 = (*p).second; |
202 | 201 |
|
203 | | - fprintf(os, "%s:%s\n", md5.c_str(), path.c_str()); |
| 202 | + fprintf(os, "%s:%s\n", sha256.c_str(), path.c_str()); |
204 | 203 | p++; |
205 | 204 | } |
206 | 205 |
|
@@ -234,15 +233,15 @@ static bool LoadChangesFile( |
234 | 233 | return false; |
235 | 234 | } |
236 | 235 |
|
237 | | - string md5 = string(buf, colon - buf); |
| 236 | + string sha256 = string(buf, colon - buf); |
238 | 237 | string path = string(colon + 1); |
239 | 238 |
|
240 | 239 | #if 0 |
241 | | - printf("md5{%s}\n", md5.c_str()); |
| 240 | + printf("sha256{%s}\n", sha256.c_str()); |
242 | 241 | printf("path{%s}\n", path.c_str()); |
243 | 242 | #endif |
244 | 243 |
|
245 | | - files.insert(Pair(path, md5)); |
| 244 | + files.insert(Pair(path, sha256)); |
246 | 245 | } |
247 | 246 |
|
248 | 247 | fclose(is); |
@@ -288,10 +287,10 @@ void DiffChanges( |
288 | 287 | } |
289 | 288 | else |
290 | 289 | { |
291 | | - string md5a = (*p).second; |
292 | | - string md5b = (*pos).second; |
| 290 | + string sha256a = (*p).second; |
| 291 | + string sha256b = (*pos).second; |
293 | 292 |
|
294 | | - if (md5a != md5b) |
| 293 | + if (sha256a != sha256b) |
295 | 294 | { |
296 | 295 | Change tmp; |
297 | 296 | tmp.type = 'M'; |
|
0 commit comments