Linux cryptographic layer development
 help / color / mirror / Atom feed
* Crypto hash function decryption
@ 2016-05-01 13:05 Gadre Nayan
  2016-05-01 13:24 ` Stephan Mueller
  0 siblings, 1 reply; 3+ messages in thread
From: Gadre Nayan @ 2016-05-01 13:05 UTC (permalink / raw)
  To: linux-crypto

Hi,

I wanted to implement a simple encryption decryption of data in kernel
space to start with the kernel crypto library.

I have the following:

int myFunction() {

        struct scatterlist sg;
        struct crypto_hash *tfm;
        struct hash_desc desc;
        unsigned char input[21];

        pr_err("Starting Crypto hash function\n");
        strcpy(input, "12345678901234567890");

        tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);

        desc.tfm = tfm;
        desc.flags = 0;

        sg_init_one(&sg, input, 21);
        crypto_hash_init(&desc);

        crypto_hash_update(&desc, &sg, 10);
        crypto_hash_final(&desc, dataptr);

        crypto_free_hash(tfm);
        pr_err("Encryption done\nip: %s\nop: %s\n", input, dataptr);


        return 0;
}

So I can get this function to encrypt the data. I wanted to know how I
can decrypt this data (dataptr) back to my original string "123....".

What api's should I use.

THanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Crypto hash function decryption
  2016-05-01 13:05 Crypto hash function decryption Gadre Nayan
@ 2016-05-01 13:24 ` Stephan Mueller
       [not found]   ` <CAKJ7aR4bf_5dSUgAm8mXvfdV=HjVNVF-q6Zt3kDf0DzzATnwrw@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Stephan Mueller @ 2016-05-01 13:24 UTC (permalink / raw)
  To: Gadre Nayan; +Cc: linux-crypto

Am Sonntag, 1. Mai 2016, 18:35:51 schrieb Gadre Nayan:

Hi Gadre,

> Hi,
> 
> I wanted to implement a simple encryption decryption of data in kernel
> space to start with the kernel crypto library.
> 
> I have the following:
> 
> int myFunction() {
> 
>         struct scatterlist sg;
>         struct crypto_hash *tfm;
>         struct hash_desc desc;
>         unsigned char input[21];
> 
>         pr_err("Starting Crypto hash function\n");
>         strcpy(input, "12345678901234567890");
> 
>         tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
> 
>         desc.tfm = tfm;
>         desc.flags = 0;
> 
>         sg_init_one(&sg, input, 21);
>         crypto_hash_init(&desc);
> 
>         crypto_hash_update(&desc, &sg, 10);
>         crypto_hash_final(&desc, dataptr);
> 
>         crypto_free_hash(tfm);
>         pr_err("Encryption done\nip: %s\nop: %s\n", input, dataptr);
> 
> 
>         return 0;
> }
> 
> So I can get this function to encrypt the data. I wanted to know how I
> can decrypt this data (dataptr) back to my original string "123....".
> 
> What api's should I use.

Maybe a peek into Handbook of Applied Cryptography may help here: a hash 
cannot be decrypted.

Besides the crypto_hash_* API is discouraged to be used.

Ciao
Stephan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Crypto hash function decryption
       [not found]   ` <CAKJ7aR4bf_5dSUgAm8mXvfdV=HjVNVF-q6Zt3kDf0DzzATnwrw@mail.gmail.com>
@ 2016-05-01 15:54     ` Stephan Mueller
  0 siblings, 0 replies; 3+ messages in thread
From: Stephan Mueller @ 2016-05-01 15:54 UTC (permalink / raw)
  To: Gadre Nayan; +Cc: linux-crypto

Am Sonntag, 1. Mai 2016, 19:05:12 schrieb Gadre Nayan:

Hi Gadre,

> Yes, i was reading about that till your reply came.
> 
> So then if not hash...then should I use asymmetric or symmetric key APIs.
> 
> My kernel version is 3.19, what APIs can I use which can compile with this
> kernel version.
> 
> The latest kernel 4.5 has skcipher fully implemented but I need to work
> with 3.19.

Please read the kernel crypto API documentation:

http://www.chronox.de/crypto-API/index.html
> 
> Thanks
> 
> On 1 May 2016 6:54 p.m., "Stephan Mueller" <smueller@chronox.de> wrote:
> > Am Sonntag, 1. Mai 2016, 18:35:51 schrieb Gadre Nayan:
> > 
> > Hi Gadre,
> > 
> > > Hi,
> > > 
> > > I wanted to implement a simple encryption decryption of data in kernel
> > > space to start with the kernel crypto library.
> > > 
> > > I have the following:
> > > 
> > > int myFunction() {
> > > 
> > >         struct scatterlist sg;
> > >         struct crypto_hash *tfm;
> > >         struct hash_desc desc;
> > >         unsigned char input[21];
> > >         
> > >         pr_err("Starting Crypto hash function\n");
> > >         strcpy(input, "12345678901234567890");
> > >         
> > >         tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
> > >         
> > >         desc.tfm = tfm;
> > >         desc.flags = 0;
> > >         
> > >         sg_init_one(&sg, input, 21);
> > >         crypto_hash_init(&desc);
> > >         
> > >         crypto_hash_update(&desc, &sg, 10);
> > >         crypto_hash_final(&desc, dataptr);
> > >         
> > >         crypto_free_hash(tfm);
> > >         pr_err("Encryption done\nip: %s\nop: %s\n", input, dataptr);
> > >         
> > >         
> > >         return 0;
> > > 
> > > }
> > > 
> > > So I can get this function to encrypt the data. I wanted to know how I
> > > can decrypt this data (dataptr) back to my original string "123....".
> > > 
> > > What api's should I use.
> > 
> > Maybe a peek into Handbook of Applied Cryptography may help here: a hash
> > cannot be decrypted.
> > 
> > Besides the crypto_hash_* API is discouraged to be used.
> > 
> > Ciao
> > Stephan


Ciao
Stephan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-01 15:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-01 13:05 Crypto hash function decryption Gadre Nayan
2016-05-01 13:24 ` Stephan Mueller
     [not found]   ` <CAKJ7aR4bf_5dSUgAm8mXvfdV=HjVNVF-q6Zt3kDf0DzzATnwrw@mail.gmail.com>
2016-05-01 15:54     ` Stephan Mueller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox