Results 1 to 6 of 6

Thread: link problem using MS Visual c++6.0 when useing Cryptlib

Hybrid View

  1. #1
    chengyou
    Guest

    Question link problem using MS Visual c++6.0 when useing Cryptlib

    Hi,

    I am a newbie. I try to use Cryptlib low level interface to run a demo using DES algorithm.

    When I use MS Visual c++ 6.0 under Windows 2000 Pro to build this test.c file. This error occur:
    cryptlib.h : fatal error LNK1136: invalid or corrupt file

    Does any expert give me hint, thank you very very much in advance.


    This is the test.c source code

    #define INC_CHILD

    #include <stdio.h>
    #include <string.h>
    #include <conio.h>
    #include <string.h>

    #include "crypt\des.h"
    #include "cryptlib.h"


    int main()

    {
    #define CRYPTLEN 128
    #define BUFFERLENGTH (CRYPTLEN+64)
    char CryptBuffer[BUFFERLENGTH];

    int status;
    int mode;
    int ok1;
    int i=0;

    CRYPT_CONTEXT cryptContext;

    // input crypt context buffer
    printf("\nBitte eine Zeichenfolge eingeben:\nbis zu 32 Zeichen (256 Bit)\n\n>");

    ok1=1;
    while (((mode=getch()) != 13) && ok1==1)
    {
    putch(mode);
    if (i < CRYPTLEN-1){
    CryptBuffer[i++] = mode;
    }
    else{
    printf("\nBuffer filled!");
    ok1 = 0;
    }
    }

    //last element to 0 for String with ending 0
    CryptBuffer[i++] = 0;

    printf("\n%s\n",CryptBuffer);
    printf("\nEs werden %i Bytes verschluesselt\n", strlen(CryptBuffer));

    /* Cryptlib Initialisierung */
    status = cryptInit();
    if( cryptStatusError( status ) )
    {
    printf( "cryptInit() failed with error code %d.\n", status );
    return( -1 );
    }

    /* Load the key, encrypt the buffer, and destroy the encryption context */

    cryptCreateContext( &cryptContext, CRYPT_UNUSED, CRYPT_ALGO_DES );

    cryptGenerateKey( cryptContext );

    printf( "\ntext: %s; textlen: %d", CryptBuffer, strlen(CryptBuffer));

    /* Write the encrypted data to the screen */

    printf( "\nContents of buffer after encryption: \n\n%.32s\n", CryptBuffer );


    /* Load the key, decrypt the buffer, and destroy the encryption context */


    cryptDecrypt( cryptContext, CryptBuffer, BUFFERLENGTH );


    /* Write the decrypted data to the screen */

    printf( "\nContents of buffer after decryption: \n\n%.32s\n\n", CryptBuffer );
    printf( "\ntext: %s; textlen: %d", CryptBuffer, strlen(CryptBuffer));

    cryptDestroyContext( cryptContext );

    cryptEnd(); /* Cryptlib schliessen */

    return 0;

    }
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  2. #2
    Naides is Nobody
    Join Date
    Jan 2002
    Location
    Planet Earth
    Posts
    1,647
    You may have better luck for inteligent answers in a different (Visual C) Board, but, at quick view:

    The code looks consistent, and compiles OK. This is a Linker error Code.

    Often, the Library cryptlib.lib included by cryptlib.h is in Borland format, and does not link in a MS environ. You may need to recreate the library and or.check if there is a MS compatible version

  3. #3
    chengyou
    Guest
    Great hints! Naides, Thanks a lot!
    Now I can turn the right way.

    I have try several different c++ compiler, all the problem are due to the cryptlib.h file.


    I promise that I have read the FAQ and tried to use the Search to answer my question.

  4. #4
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    Also, the best place for cryptlib advice is the cryptlib mailing list. It's very responsive.

  5. #5
    chengyou
    Guest

    can not decrypt using one algorithm

    Hi, Sir

    I use MS Visual C++ 6.0 under Windows 2000 to test one algorithm.

    This program seem encrypt correctly, because the error alert not occur,
    But the decrypt seemed not correct.

    Does anybody give some hints? thanks a slot.





    this is the running result
    --------------------------------------------------------------------
    show the buffter:
    hello
    initialisation of cryptlib sucess.
    successfully load cryptCreateContext. using algoriothm DES
    Generating keys...

    text: ↓≥≡ P√T╕4╨Γ b╙s φπ╖π⌡≥d{ G;Ls╪/╪╤▒εI"#╖τΘ2↕╟→₧↑>_9►╪atP└4M%
    ♣s╥╟∩{}y ┼≡e&fB/ →=▐"l╝←jaR9Φ╟bA☼♀$♥↨∩Z<; textlen: 125

    Contents of buffer after encryption:

    ↓≥≡ P√T╕4╨Γ b╙s φπ╖π⌡≥d{ G;Ls╪

    Contents of buffer after decryption:

    τGI∞]D

    current cryptBuffer length: 10
    the first cryptlib running finish.
    Press any key to continue




    This is the test source code
    //****************************************************************************


    #ifdef _MSC_VER
    #include "../cryptlib.h"
    #include "../test/test.h"
    #else
    #include "cryptlib.h"
    #include "test/test.h"
    #endif

    //****************************************************************************

    void main( int argc, char **argv )
    {

    CRYPT_CONTEXT cryptContext;

    #define CRYPTLEN 128

    int InitStatus;
    int ContextStatus;
    int EncryptStatus;

    // assign stored data

    unsigned char TransData[] = "hello";

    int len = strlen(TransData);
    char *CryptBuffer = (char *)malloc(sizeof(char)*(len+1));

    memcpy(CryptBuffer,TransData, (len+1) );

    printf(" show the buffter: \n%s\n",CryptBuffer);



    /* Initialise cryptlib */

    InitStatus = cryptInit();
    if( cryptStatusError( InitStatus ) )
    {
    printf( "cryptInit() failed with error code %d.\n", InitStatus);
    exit( EXIT_FAILURE );
    }
    else
    printf( "initialisation of cryptlib sucess. \n");

    cryptAddRandom( NULL, CRYPT_RANDOM_SLOWPOLL );


    /* Load the key, encrypt the buffer */

    ContextStatus = cryptCreateContext( &cryptContext, CRYPT_UNUSED, CRYPT_ALGO_DES );

    if( cryptStatusError( ContextStatus ) )
    {
    printf( "cryptCreateContext() failed \n");
    exit( EXIT_FAILURE );
    }
    else
    printf( "successfully load cryptCreateContext. using algoriothm DES \n");


    /* Create key*/

    cryptGenerateKey( cryptContext );
    printf ("Generating keys...\n");


    /* Write the encrypted data to the screen */


    EncryptStatus = cryptEncrypt( cryptContext, CryptBuffer, CRYPTLEN);

    if( cryptStatusError( EncryptStatus ) )

    {
    printf( "Couldn't encrypt data, status = %d.\n", EncryptStatus );
    }

    else
    printf( "\ntext: %s; textlen: %d\n", CryptBuffer, strlen(CryptBuffer));

    printf( "\nContents of buffer after encryption: \n\n%.32s\n", CryptBuffer );

    /****************************************************************************
    /* Load the key, decrypt the buffer, and destroy the encryption context */

    cryptDecrypt( cryptContext, CryptBuffer, CRYPTLEN );

    /* Write the decrypted data to the screen */

    printf( "\nContents of buffer after decryption: \n\n%.32s\n\n", CryptBuffer );
    printf( "current cryptBuffer length: %d \n", strlen(CryptBuffer));

    cryptDestroyContext( cryptContext );

    printf("the first cryptlib running finish. \n");

    free (CryptBuffer);

    cryptEnd();

    }
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  6. #6
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    Well, if you're going to put crypto in your own code, don't bother with the low level encrytion calls. Use the enveloping API.

    One bug in your program is you're telling cryptlib that the buffer size is CRYPTLEN when you only allocate 5 or 6 bytes.

Similar Threads

  1. Replies: 0
    Last Post: January 3rd, 2008, 07:09
  2. Cryptlib - setting IV's
    By BassPlayer in forum RCE Cryptographics
    Replies: 5
    Last Post: December 2nd, 2003, 18:56
  3. Diffie Hellman Key Agreement - Cryptlib???
    By Clandestiny in forum RCE Cryptographics
    Replies: 4
    Last Post: October 29th, 2003, 00:32
  4. only a link
    By Mustapha in forum Advanced Reversing and Programming
    Replies: 2
    Last Post: March 14th, 2001, 20:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •