Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:30:21+00:00 2026-06-12T22:30:21+00:00

i am pretty new to c. I am trying to compare two files with

  • 0

i am pretty new to c. I am trying to compare two files with md5.
I wrote a function which should return the hash values. But when comparing the values of different files or buffers, it says that they have the same hash.

unsigned char* getMD5(void *buffer, size_t bsize) {
    EVP_MD_CTX *mdctx;
    const EVP_MD *md;
    unsigned char hashwert[EVP_MAX_MD_SIZE];
    int hashwert_laenge;
    OpenSSL_add_all_digests();
    md = EVP_get_digestbyname("MD5");
    mdctx = EVP_MD_CTX_create();
    EVP_DigestInit_ex(mdctx, md, NULL);
    EVP_DigestUpdate(mdctx, buffer, bsize);
    EVP_DigestFinal_ex(mdctx, hashwert, &hashwert_laenge);
    EVP_MD_CTX_destroy(mdctx);
    return hashwert;
}

//in main...
char mess[] = "abc";
cahr mess2[] = "bcd";
if(strcmp(getMD5(mess, strlen(mess)),getMD5(mess2, strlen(mess2))==0) {
   printf("euqal\n");
}else {
   printf("not equal \n"); 
}

I always get that the buffers are equal, even if they are not.
Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:30:23+00:00Added an answer on June 12, 2026 at 10:30 pm

    You should compile with all warnings enabled and debugging info, e.g. with gcc -Wall -g on Linux.

    It will have warned you: function returns address of local variable.

    Newbies and expert C programmers usually should improve their code till no warnings are given. If your code triggers a warning that you really cannot avoid you should at least comment very carefully why.

    You cannot meaningfully return the address of some local array.

    You could return strdup(hashwert); and have the convention that the calling function (the caller) should free the result.

    Or you could have a different API, for example having hashwert be a parameter of your function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to the jquery validation plugin. Trying to compare date values in
I'm pretty new to XQuery and I'm trying to write an example function that
I'm pretty new to MYSQL. I'm trying to write a query which will search
Pretty new to C# but not new in programming in generally. I'm still trying
I am pretty new to jQuery but I am trying to get a code
I'm pretty new to c# and I'm trying to make a function that checks
I'm pretty new to this - I'm trying to compare a NSString stringWithFormat with
I'm pretty new to WinDbg and I'm trying to find a bug which has
I am pretty new to c++ but I am trying to set up a
Pretty new to Prolog. I'm trying to give two lists and have the difference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.