Thread: Crypto API

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    7

    Crypto API

    Hi there,
    I am working on a homework that has to do with encryption. I want to be able to encrypt a string of characters. I have been reading about the Crypto API over the last few days, and I managed to get some code, but It doesn't work properly. This is just a test, once I know its working I will added it to the rest of my code. Here I am setting a password, encrypting a string, decrypting and then I expect to see the same string, but It doesn't work out.

    Code:
            char me[5] = "nice";    // set the password
    	struct crypto_tfm *tfm;    // crypto pointer
    	struct scatterlist src, dst, dst2;
    	char str1[5] = "whic";
    	char str2[5];
    	char str3[5];
    	
    	src.page = virt_to_page(str1);
    	src.offset = offset_in_page(str1);
    	src.length = 5;
    	
    	dst.page = virt_to_page(str2);
    	dst.offset = offset_in_page(str2);
    	dst.length = 5;
    	
    	dst2.page = virt_to_page(str3);
    	dst2.offset = offset_in_page(str3);
    	dst2.length = 5;
    	
    	tfm = crypto_alloc_tfm("blowfish", CRYPTO_TFM_MODE_ECB);   // initialize with blowfish
    	crypto_cipher_setkey(tfm, me, 4);    // set the key
    	crypto_cipher_encrypt(tfm, &dst, &src, 1); // (tfm, dest, source)
    	crypto_cipher_decrypt(tfm, &dst2, &dst, 1); // (tfm, dest, source)
    	crypto_free_tfm(tfm);
    	
    	*(str1+4) = '\0';
     	*(str2+4) = '\0';
     	*(str3+4) = '\0';
     	printk("%s\n",str1);
     	printk("%s\n",str2);
     	printk("%s\n",str3);
    Any suggestions on what I might be doing wrong?

    Thank you,

    -George

  2. #2
    Registered User
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    14
    tfm = crypto_alloc_tfm("blowfish", CRYPTO_TFM_MODE_ECB); // initialize with blowfish


    Havenīt tested this or nothing just throwing a couple of thoughts in the air.

    Is tfm really initialized with blowfish, maybe a check would be good?

    Isnīt the ECB automatically be used with blowfish, how about :
    tfm=crypto_alloc_tfm("blowfish,0");

    Also is crypto_cipher_setkey(tfm, me, 4); returning succesfully value.?

    I know that you are testing things at this point, but ainīt it important to check is something being successfully initialized to see is everything going as planned.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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
  2. Want to learn Windows API for Game Programming
    By George M. in forum Windows Programming
    Replies: 15
    Last Post: 09-28-2008, 10:26 AM
  3. platform specific API or C standard API
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 01:32 AM
  4. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 07:46 PM
  5. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM