Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "Utilities/OpenSSL/interface/openssl_init.h"
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <sstream>
0005 
0006 using namespace std;
0007 int main() {
0008   unsigned char hash[EVP_MAX_MD_SIZE];
0009   unsigned int md_len = 0;
0010   cms::openssl_init();
0011   EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
0012   const EVP_MD *md = EVP_get_digestbyname("SHA1");
0013 
0014   EVP_DigestInit_ex(mdctx, md, NULL);
0015   EVP_DigestUpdate(mdctx, "foo", 3);
0016   EVP_DigestUpdate(mdctx, "bar", 3);
0017   EVP_DigestFinal_ex(mdctx, hash, &md_len);
0018   EVP_MD_CTX_free(mdctx);
0019 
0020   stringstream ss;
0021   for (unsigned int i = 0; i < md_len; i++) {
0022     ss << hex << setw(2) << setfill('0') << (int)hash[i];
0023   }
0024   hash[md_len] = 0;
0025   string sha_result = "8843d7f92416211de9ebb963ff4ce28125932878";
0026   string sha = ss.str();
0027   if (sha != sha_result) {
0028     cout << "Failed: SHA1 Mismatch:" << sha << " vs " << sha_result << endl;
0029     return 1;
0030   }
0031   cout << "Passed: SHA1 match:" << sha << " vs " << sha_result << endl;
0032   return 0;
0033 }