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