linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Vineet Joglekar" <vintya@excite.com>
To: linux-kernel@vger.kernel.org, linux-c-programming@vger.kernel.org
Subject: Problem in encryption in kernel
Date: Mon, 21 Mar 2005 17:16:48 -0500 (EST)	[thread overview]
Message-ID: <20050321221648.169188AECF@xprdmailfe2.nwk.excite.com> (raw)


Hi all,



I am trying to use some encryption routines inside the kernel (2.4.28). I have done the following things, please let me know where I am going wrong, or anything additional needs to be done.



1: defined struct crypto_tfm * tfm and allocated to des using crypto_alloc_tfm()

2: called crypto_cipher_setkey() to set the DES key.

3: defined the ecryption function as follows:



int encrypt(char *buffer, size_t buffer_length)

{

    struct scatterlist sg;

    int ret = 0,i = 0;



    printk("addr sent = %x\n",buffer);

    sg.page = virt_to_page(buffer);

    printk("addr frm virt_to_page = %x\n",sg.page);

// these 2 address are coming out to be different.



    sg.length = 8;

    for(i=0; i < buffer_length; i+=8)

    {

        sg.offset = i;



        ret = crypto_cipher_encrypt(tfm,&sg,&sg,8);

        if(ret) printk("error");

    }

    return ret;

}



Now if I define a character array temp[16], pass it to encrypt as encrypt(temp,16) and on the next line, if I see the the array using printk again, it doesnt show it as encrypted. whats going wrong? (it didnt give any memory fault that this point, maybe it encrypted something else - as the address I saw were different)



I tried to see the address in pointer "buffer" and address returned by "virt_to_page", they are different.



Since the addresses were different, I tried to do following variations, but it always gave some memory fault:

1: instead of using sg.page, i tried to use sg.address as

sg.address = buffer; sg.offset = i;

2 : I tried to assign sg.page = buffer (w/o using virt_to_page) and sg.offset = i;

3: I tried

        sg.page = virt_to_page(buffer);

        sg.offset = ((unsigned long)buffer + ~PAGE_MASK) + i;



So I am stuck and out of ideas now. Please help me with it. All I want is that array getting encrypted after I pass it to the encrypt function (the size should remain the same)



Thanks in advance and regards,



Vineet

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!

                 reply	other threads:[~2005-03-21 22:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050321221648.169188AECF@xprdmailfe2.nwk.excite.com \
    --to=vintya@excite.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).