Thread: Problem with a Crypto Library

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Problem with a Crypto Library

    Hi...
    I'm new in this forum, but I like it a lot...

    I've a problem with my new project, I need to do "hmac-sha1" of a part of a file and put the first 16 values of that hash in a new file...

    I've found a libray on "koders" (i don't know if I can post here the link, if I can, I will post it in the next post).

    But if I try to compile it, I will receive this error:
    Code:
    [mpre@mpre-probook e-sec_min]$ gcc e-sec_min.c -o esec
    /tmp/ccn86muF.o: In function `rehash_sec':
    e-sec_min.c:(.text+0x234): undefined reference to `hmac_sha1'
    collect2: ld returned 1 exit status
    In attachment I will put my directory where there are all the file needed by the program.

    Can any of you help me to make working that function?
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    That error message is from the linker, not the compiler. It is not finding the symbol (presumably corresponding to a function) named hmac_sha1

    Try adding the name of the library to the gcc command line. Functions in third-party libraries (like the one you found on "koders") are not found by magic. Possibly read the documentation for the library for specific information on how to link against the library.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Thank you for the info... I never used external library befor now...
    I've tried this command:
    Code:
    gcc e-sec_min.c hmac-sha1.c hmac.h hmac-md5.c sha1.c sha1.h md5.h md5.c memxor.h memxor.c unlocked-io.h -o esec
    and something is changed... now there are an error on memxor.h:
    Code:
    memxor.h:29:30: error: expected ‘;’, ‘,’ or ‘)’ before ‘dest’
    This is memxor.h:

    Code:
    #ifndef MEMXOR_H# define MEMXOR_H
    
    
    #include <stddef.h>
    
    
    /* Compute binary exclusive OR of memory areas DEST and SRC, putting
       the result in DEST, of length N bytes.  Returns a pointer to
       DEST. */
    void *memxor (void *restrict dest, const void *restrict src, size_t n);
    
    
    #endif /* MEMXOR_H */
    It generate me the file "esec" but if I try to launch it i will receive:
    Code:
    [root@mpre-probook e-sec_min]# ./esecbash: ./esec: cannot execute binary file
    What I'm doing wrong?

    Thank you very mutch

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    restrict is a keyword first introduced by the 1999 C standard. It was not supported by older versions of C, and is also not supported in C++.

    The option to get gcc to support the 1999 C standard (rather than 1989 standard plus a few later corrections) is -std=c99. Bear in mind that the support in gcc for 1999 standard C is incomplete.

    By the way, it is not necessary to list header files (.h extension) on the gcc command line. They are files that are #include'd by other files.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Thank you all for the help, now i have compiled my program.

    But, now I need another little help:

    I need to convert a string to hex values... Let me explane.

    I've
    Code:
    char a[16]="123456789abcdef0"
    and I need
    Code:
    char a[8]={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}
    How I can do this?
    Last edited by mpre; 02-07-2012 at 06:08 PM.

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    It wouldn't be an array of char pointers, it would just be an array of chars, OR a char pointer:
    Code:
    char *a;
    /* or */
    char a[16];

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Yes, I copyed wrong, i used
    Code:
    char a[16]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Crypto API
    By inferno_gogo in forum C Programming
    Replies: 1
    Last Post: 02-21-2009, 02:04 PM
  2. Crypto API - Import Private Key (DER or PEM)
    By magic.mike in forum Windows Programming
    Replies: 0
    Last Post: 01-14-2009, 08:48 AM
  3. crypto questions
    By talz13 in forum Windows Programming
    Replies: 1
    Last Post: 07-13-2004, 12:20 PM
  4. Binary Tree Crypto
    By Elint in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2004, 06:43 AM