Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-15 00:38:10

0001 #include <openssl/sha.h>
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <sstream>
0005 
0006 using namespace std;
0007 int main() {
0008   SHA_CTX ctx;
0009   SHA1_Init(&ctx);
0010   SHA1_Update(&ctx, "foo", 3);
0011   SHA1_Update(&ctx, "bar", 3);
0012   unsigned char hash[SHA_DIGEST_LENGTH];
0013   SHA1_Final(hash, &ctx);
0014 
0015   stringstream ss;
0016   for (unsigned int i = 0; i < SHA_DIGEST_LENGTH; i++) {
0017     ss << hex << setw(2) << setfill('0') << (int)hash[i];
0018   }
0019   string sha_result = "8843d7f92416211de9ebb963ff4ce28125932878";
0020   string sha = ss.str();
0021   if (sha != sha_result) {
0022     cout << "Failed: SHA1 Mismatch:" << sha << " vs " << sha_result << endl;
0023     return 1;
0024   }
0025   cout << "Passed: SHA1 match:" << sha << " vs " << sha_result << endl;
0026   return 0;
0027 }