Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:46

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("MD5");
0013 
0014   EVP_DigestInit_ex(mdctx, md, NULL);
0015   EVP_DigestUpdate(mdctx, "foo-bar-bla", 11);
0016   EVP_DigestFinal_ex(mdctx, hash, &md_len);
0017   EVP_MD_CTX_free(mdctx);
0018 
0019   char tmp[EVP_MAX_MD_SIZE * 2 + 1];
0020   // re-write bytes in hex
0021   for (unsigned int i = 0; i < md_len; i++) {
0022     ::sprintf(&tmp[i * 2], "%02x", hash[i]);
0023   }
0024   tmp[md_len * 2] = 0;
0025   string sha = tmp;
0026   string sha_result = "ad42a5e51344e880010799a7b7c612fc";
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 }