Thread: dsa signing and verifying

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    27

    dsa signing and verifying

    Im writing a program that is supposed to sign a file and then verify a file. Basically your supposed to put in three command prompts,one to indicate whether you want to sign or verify,another for the file to be signed or verified and for another file to be written to, meaning if you sign text.txt it will go to text.bin.Its sort of like if it was encrypting text.txt,the encrypted version would be written to encrypt.txt. My main problem is i dont know if im using the write arguments to write data to a file.

    If anyone can help,id appreciate it.

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<openssl/evp.h>
    #include<openssl/dsa.h>
    
    int main (int argc , char ** argv )
    
    {
    EVP_MD_CTX ctx;
    DSA *dsa ;
    char choice;
    unsigned char *sig;
    int len , siglen,size ;
    char *buf;
    unsigned char md[ EVP_MAX_MD_SIZE ];
    FILE *file;
    
    /* Compute the SHA1 digest of str */
    
    EVP_DigestInit (& ctx , EVP_sha1 ());
    EVP_DigestUpdate (& ctx , file , strlen (file ));
    EVP_DigestFinal (& ctx , md , &len );
    
    file=fopen(argv[2],"r");
    fseek(file,0,SEEK_END);
    size=ftell(file);
    buf=(char *)malloc(size);
    fread(buf,1,size,file);
    fclose(file);
    
    
    /* Generate DSA parameters */
    
    dsa = DSA_generate_parameters (1024 , NULL , NULL , NULL , NULL ,NULL , NULL );
    
    /* Generate DSA keys */
    
    DSA_generate_key (dsa );
    
    /* Allocate buffer space for signature */
    
    sig = ( unsigned char *) malloc ( DSA_size (dsa ));
    
    if(choice=="sign")
    { 
    DSA_sign (file , md , len , sig , &siglen , dsa );
    write_data(argv[3],buf,size);
    }
    else if(choice=="verify")
    { 
    if ( DSA_verify (file , md , len , sig , siglen , dsa) == 1)
    printf (" Signature is verified !\n");
    else
    printf (" Signature verification failed ...\ n");
    write_data(argv[3],buf,size);
    }
    /* Destroy the DSA object */
    DSA_free (dsa );
    
    return 0;
    }
    Last edited by kakashi316; 05-03-2012 at 12:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Signing off.
    By abachler in forum General Discussions
    Replies: 10
    Last Post: 03-16-2010, 07:32 PM
  2. verifying image compression
    By elninio in forum C++ Programming
    Replies: 2
    Last Post: 06-17-2008, 07:36 PM
  3. Signing an ActiveX cab?
    By Mastadex in forum Windows Programming
    Replies: 0
    Last Post: 05-28-2007, 02:46 PM
  4. Verifying int with while(!(cin >> num))
    By motarded in forum C++ Programming
    Replies: 3
    Last Post: 02-26-2006, 10:37 PM
  5. signing 'if statements' to 'arrays'
    By Machewy in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2003, 05:18 PM