How to generate a md5 hash?

Discussion in 'C Programming' started by dutche, Jul 20, 2005.

  1. dutche

    dutche Guest

    Hi, this is my first post here and I'm very very new in 'C'
    programming.
    And I began to 'translate' my PHP program, that beyond a lot of things
    generates a md5 hash, and I must generate a md5 hash in 'C' , but I
    cant found it anywhere.
    I've readed the crypt.h man page, I read twice the post in
    http://groups.google.com.br/group/c...8?q=md5 hash&rnum=3&hl=pt-BR#bd4b37481e4d0b48

    But I still dont know how to generate a md5 hash from my string
    'testing' for example.

    Plz, if anyone can help me I'd be glad

    Thanks
    dutche, Jul 20, 2005
    #1
    1. Advertising

  2. dutche

    Eric Sosman Guest

    dutche wrote:
    > Hi, this is my first post here and I'm very very new in 'C'
    > programming.
    > And I began to 'translate' my PHP program, that beyond a lot of things
    > generates a md5 hash, and I must generate a md5 hash in 'C' , but I
    > cant found it anywhere.
    > I've readed the crypt.h man page, I read twice the post in
    > http://groups.google.com.br/group/c...8?q=md5 hash&rnum=3&hl=pt-BR#bd4b37481e4d0b48
    >
    > But I still dont know how to generate a md5 hash from my string
    > 'testing' for example.


    The RFC that defines MD5 contains a sample C
    implementation.

    --
    Eric Sosman, Jul 20, 2005
    #2
    1. Advertising

  3. dutche

    osmium Guest

    "dutche" writes:

    > Hi, this is my first post here and I'm very very new in 'C'
    > programming.
    > And I began to 'translate' my PHP program, that beyond a lot of things
    > generates a md5 hash, and I must generate a md5 hash in 'C' , but I
    > cant found it anywhere.
    > I've readed the crypt.h man page, I read twice the post in
    > http://groups.google.com.br/group/c...8?q=md5 hash&rnum=3&hl=pt-BR#bd4b37481e4d0b48
    >
    > But I still dont know how to generate a md5 hash from my string
    > 'testing' for example.
    >
    > Plz, if anyone can help me I'd be glad


    Did you look at this?

    http://www.faqs.org/rfcs/rfc1321.html
    osmium, Jul 20, 2005
    #3
  4. dutche

    dutche Guest

    Yes, I've readed the entire RFC, but as I said...I'm very new in 'C'
    and I copied the files that is in Appendix.

    At this point, everything's fine...but when I try to compile
    it...like...I donno how to compile those files togheter.

    I tried 'gcc mddriver.c -o mddriver' , and a lot of errors appears to
    me :/

    I'm posting here cause I tried everything that I can with no results.

    Thanks
    dutche, Jul 20, 2005
    #4
  5. dutche

    Guest

    dutche wrote:
    > Yes, I've readed the entire RFC, but as I said...I'm very new in 'C'
    > and I copied the files that is in Appendix.
    >
    > At this point, everything's fine...but when I try to compile
    > it...like...I donno how to compile those files togheter.
    >
    > I tried 'gcc mddriver.c -o mddriver' , and a lot of errors appears to
    > me :/
    >
    > I'm posting here cause I tried everything that I can with no results.
    >
    > Thanks


    Please, learn how to ask an intelligent, useful question. Then someone
    may help you without wasting posts asking for this and that.

    With that said, here is the minimal amount of information needed to
    help you:

    1) Are you using separate source files? Do you have the MD5
    implementation in a separate file or did you copy/paste it into
    mddriver.c?
    2) What are the errors you get from gcc (please copy/paste, don't
    summarize)?
    3) What are the relevant source files involved in your project?

    At this point, I'd suggest, for simplicity's sake, to simply copy/paste
    the MD5 code to the TOP of your mddriver.c source file and place your
    int main() function at the bottom of the source file.
    , Jul 20, 2005
    #5
  6. dutche

    Default User Guest

    dutche wrote:

    > Yes, I've readed the entire RFC, but as I said...I'm very new in 'C'
    > and I copied the files that is in Appendix.



    Please quote a relevant portion of the previous message for context.
    Check CB Falconer messages for instructions.

    > At this point, everything's fine...but when I try to compile
    > it...like...I donno how to compile those files togheter.
    >
    > I tried 'gcc mddriver.c -o mddriver' , and a lot of errors appears to
    > me :/
    >
    > I'm posting here cause I tried everything that I can with no results.



    And what are we supposed to do, psychically divine what code you are
    trying?




    Brian
    Default User, Jul 20, 2005
    #6
  7. dutche

    dutche Guest

    First, I created these files:

    global.h
    md5.h
    md5c.c
    mddriver.c

    Ok, I made it exactly as described but when I try to compile I dont got
    any results, I think that I'm doing something wrong when compiling.

    I've copied the source of the programs directly from the RFC site, and
    the command that I used is: 'gcc mddriver.c -o mddriver'

    And the errors I got was...

    mddriver.c: In function `MDString':
    mddriver.c:106: error: `MD_CTX' undeclared (first use in this function)
    mddriver.c:106: error: (Each undeclared identifier is reported only
    once
    mddriver.c:106: error: for each function it appears in.)
    mddriver.c:106: error: parse error before "context"
    mddriver.c:110: error: `context' undeclared (first use in this
    function)
    mddriver.c:114: error: `MD5' undeclared (first use in this function)
    mddriver.c: In function `MDTimeTrial':
    mddriver.c:124: error: `MD_CTX' undeclared (first use in this function)
    mddriver.c:124: error: parse error before "context"
    mddriver.c:130: error: `MD5' undeclared (first use in this function)
    mddriver.c:141: error: `context' undeclared (first use in this
    function)
    mddriver.c: In function `MDTestSuite':
    mddriver.c:162: error: `MD5' undeclared (first use in this function)
    mddriver.c: In function `MDFile':
    mddriver.c:183: error: `MD_CTX' undeclared (first use in this function)
    mddriver.c:183: error: parse error before "context"
    mddriver.c:191: error: `context' undeclared (first use in this
    function)
    mddriver.c:198: error: `MD5' undeclared (first use in this function)
    mddriver.c: In function `MDFilter':
    mddriver.c:208: error: `MD_CTX' undeclared (first use in this function)
    mddriver.c:208: error: parse error before "context"
    mddriver.c:212: error: `context' undeclared (first use in this
    function)



    I'm using a Slackware Linux 10.1 with gcc-3.3.4-i486-1.

    Sorry for the few arguments in the last post.
    dutche, Jul 20, 2005
    #7
  8. dutche wrote:
    > First, I created these files:
    >
    > global.h
    > md5.h
    > md5c.c
    > mddriver.c
    >
    > Ok, I made it exactly as described but when I try to compile I dont got
    > any results, I think that I'm doing something wrong when compiling.
    >
    > I've copied the source of the programs directly from the RFC site, and
    > the command that I used is: 'gcc mddriver.c -o mddriver'
    >
    > And the errors I got was...
    >
    > mddriver.c: In function `MDString':
    > mddriver.c:106: error: `MD_CTX' undeclared (first use in this function)
    > mddriver.c:106: error: (Each undeclared identifier is reported only
    > once
    > mddriver.c:106: error: for each function it appears in.)
    > mddriver.c:106: error: parse error before "context"
    > mddriver.c:110: error: `context' undeclared (first use in this
    > function)
    > mddriver.c:114: error: `MD5' undeclared (first use in this function)
    > mddriver.c: In function `MDTimeTrial':
    > mddriver.c:124: error: `MD_CTX' undeclared (first use in this function)
    > mddriver.c:124: error: parse error before "context"
    > mddriver.c:130: error: `MD5' undeclared (first use in this function)
    > mddriver.c:141: error: `context' undeclared (first use in this
    > function)
    > mddriver.c: In function `MDTestSuite':
    > mddriver.c:162: error: `MD5' undeclared (first use in this function)
    > mddriver.c: In function `MDFile':
    > mddriver.c:183: error: `MD_CTX' undeclared (first use in this function)
    > mddriver.c:183: error: parse error before "context"
    > mddriver.c:191: error: `context' undeclared (first use in this
    > function)
    > mddriver.c:198: error: `MD5' undeclared (first use in this function)
    > mddriver.c: In function `MDFilter':
    > mddriver.c:208: error: `MD_CTX' undeclared (first use in this function)
    > mddriver.c:208: error: parse error before "context"
    > mddriver.c:212: error: `context' undeclared (first use in this
    > function)
    >
    >
    >
    > I'm using a Slackware Linux 10.1 with gcc-3.3.4-i486-1.
    >
    > Sorry for the few arguments in the last post.


    This newsgroup isn't really for helping you learn to compile C code.
    Nonetheless, notice you have multiple source files, but only used one
    of them in your compile statement. Try something more like:

    gcc -c -v -Wall -I. -omd5.o md5.c
    gcc -c -v -Wall -I. -omddriver.o mddriver.c
    gcc -omddriver mddriver.o md5.o
    Chris Hulbert, Jul 20, 2005
    #8
  9. dutche

    Mark Guest

    "dutche" <> wrote in message
    news:...
    > Yes, I've readed the entire RFC, but as I said...I'm very new in 'C'
    > and I copied the files that is in Appendix.
    >
    > At this point, everything's fine...but when I try to compile
    > it...like...I donno how to compile those files togheter.
    >
    > I tried 'gcc mddriver.c -o mddriver' , and a lot of errors appears to
    > me :/
    >
    > I'm posting here cause I tried everything that I can with no results.


    That's because the code provided with the RFC has a bug :)
    At approximately line 20 or mddriver.c replace the following line:

    #define MD MD5
    with
    #define MD 5

    That's should do the trick.

    Regards,
    Mark
    Mark, Jul 20, 2005
    #9
  10. dutche

    dutche Guest

    In the first compile I got errors:
    The command:
    gcc -c -v -Wall -I. -omd5.o md5c.c

    The errors:

    GGC heuristics: --param ggc-min-expand=46 --param
    ggc-min-heapsize=31005
    ignoring nonexistent directory "/usr/i486-slackware-linux/include"
    #include "..." search starts here:
    #include <...> search starts here:
    .
    /usr/local/include
    /usr/lib/gcc-lib/i486-slackware-linux/3.3.4/include
    /usr/include
    End of search list.
    md5c.c:81: error: parse error before '+=' token
    md5c.c:81:13: warning: backslash and newline separated by space
    md5c.c: In function `MD5Transform':
    md5c.c:340: error: parse error at end of input
    md5c.c:50: warning: `Encode' declared `static' but never defined
    md5c.c:52: warning: `Decode' declared `static' but never defined
    md5c.c:54: warning: `MD5_memcpy' declared `static' but never defined
    md5c.c:55: warning: `MD5_memset' declared `static' but never defined


    Thanks for help
    dutche, Jul 20, 2005
    #10
  11. dutche

    Mark Guest

    "Mark" <> wrote in message
    news:VhyDe.2629$...
    >
    > "dutche" <> wrote in message
    > news:...
    >> Yes, I've readed the entire RFC, but as I said...I'm very new in 'C'
    >> and I copied the files that is in Appendix.
    >>
    >> At this point, everything's fine...but when I try to compile
    >> it...like...I donno how to compile those files togheter.
    >>
    >> I tried 'gcc mddriver.c -o mddriver' , and a lot of errors appears to
    >> me :/
    >>
    >> I'm posting here cause I tried everything that I can with no results.

    >
    > That's because the code provided with the RFC has a bug :)
    > At approximately line 20 or mddriver.c replace the following line:
    >
    > #define MD MD5
    > with
    > #define MD 5
    >
    > That's should do the trick.
    >
    > Regards,
    > Mark


    Worth mentioning: You'll also need to compile md5.c
    $ gcc md5.c mddriver.c -o [whatever]

    Mark
    Mark, Jul 20, 2005
    #11
  12. dutche

    Mark Guest

    "dutche" <> wrote in message
    news:...
    > First, I created these files:
    >
    > global.h
    > md5.h
    > md5c.c
    > mddriver.c
    >
    > Ok, I made it exactly as described but when I try to compile I dont got
    > any results, I think that I'm doing something wrong when compiling.
    >
    > I've copied the source of the programs directly from the RFC site, and
    > the command that I used is: 'gcc mddriver.c -o mddriver'

    gcc md5.c mddriver.c -o mddriver


    > And the errors I got was...

    caused by an bug in the code.
    line 20 mddriver.c
    #define MD MD5
    should be
    #define MD 5
    Mark, Jul 20, 2005
    #12
  13. dutche

    Old Wolf Guest

    dutche wrote:
    > First, I created these files:
    >
    > global.h
    > md5.h
    > md5c.c
    > mddriver.c
    >
    > Ok, I made it exactly as described but when I try to compile I dont got
    > any results, I think that I'm doing something wrong when compiling.
    >
    > I've copied the source of the programs directly from the RFC site, and
    > the command that I used is: 'gcc mddriver.c -o mddriver'
    >
    > And the errors I got was...
    >
    > mddriver.c: In function `MDString':
    > mddriver.c:106: error: `MD_CTX' undeclared (first use in this function)
    > mddriver.c:106: error: (Each undeclared identifier is reported only
    > once
    > mddriver.c:106: error: for each function it appears in.)
    > mddriver.c:106: error: parse error before "context"
    > mddriver.c:110: error: `context' undeclared (first use in this
    > function)


    There are some errors in that source code at
    http://www.faqs.org/rfcs/rfc1321.html :

    md5c.c line 82 (the blank line) should be deleted
    mddriver.c line 21 should read:
    #define MD 5
    instead of
    #define MD MD5

    Note that md5c.c contains the functions for performing an MD5
    operation (suitable for embedding in another project), and
    mddriver.c is a commandline program that you can use to
    call these functions.
    If all you want to do is add these functions to another project
    of yours, then you only need md5c.c .

    Note that you have to tell GCC about all the source files you
    want to compile:

    gcc -o mddriver mddriver.c md5c.c

    It's also a good idea to enable warnings:

    gcc -o mddriver mddriver.c md5c.c -Wextra -Wall -ansi -pedantic

    mddriver.c has a couple of warnings when compiled with these
    switches, but they are ones you can safely ignore.

    Finally, the source code in that RFC is a little archaic,
    if you do a 'locate md5.c' on your system you will probably turn
    up a lot of other implementations of it. For example, the PHP
    source code contains it.
    Old Wolf, Jul 20, 2005
    #13
  14. dutche

    dutche Guest

    Is that point that I need to reach, I found that md5.c is the functions
    to generate a hash right?
    But (as I said I'm new in 'C') I cant realize which function is the
    "hash maker".

    Sorry, I'm still reading the K&R book but not too familiarized yet.
    dutche, Jul 20, 2005
    #14
  15. dutche

    Red Guest

    In article <>,
    says...
    >
    > Please, learn how to ask an intelligent, useful question.


    Please, learn how NOT to be a rude asswipe.
    Red, Jul 22, 2005
    #15
  16. Red wrote:
    > In article <>,
    > says...
    >
    >>Please, learn how to ask an intelligent, useful question.

    >
    >
    > Please, learn how NOT to be a rude asswipe.


    While it is occasionally enjoyable to see a self-referential post, yours
    is not at all amusing.
    Martin Ambuhl, Jul 22, 2005
    #16
  17. dutche

    CBFalconer Guest

    Martin Ambuhl wrote:
    > Red wrote:
    >> says...
    >>
    >>> Please, learn how to ask an intelligent, useful question.

    >>
    >> Please, learn how NOT to be a rude asswipe.

    >
    > While it is occasionally enjoyable to see a self-referential post,
    > yours is not at all amusing.


    No, but it does an admirable job of inciting PLONKs up and down the
    seacoast.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
    CBFalconer, Jul 22, 2005
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Afonin

    How to generate an MD5 data from the string

    Peter Afonin, Aug 20, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    476
  2. Replies:
    9
    Views:
    17,066
    John Salerno
    May 8, 2006
  3. Generate MD5

    , Dec 8, 2008, in forum: Java
    Replies:
    7
    Views:
    1,210
    Roedy Green
    Dec 11, 2008
  4. rp
    Replies:
    1
    Views:
    499
    red floyd
    Nov 10, 2011
  5. Peter Woodsky

    create a md5 / md5 passwd with a salt

    Peter Woodsky, Nov 20, 2008, in forum: Ruby
    Replies:
    6
    Views:
    198
    Brian Candler
    Nov 21, 2008
Loading...

Share This Page