Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Stephan Mueller <smueller@chronox.de>
To: Gadre Nayan <gadrenayan@gmail.com>
Cc: linux-crypto@vger.kernel.org
Subject: Re: Crypto hash function decryption
Date: Sun, 01 May 2016 15:24:18 +0200	[thread overview]
Message-ID: <7386652.LF5ZBdauM9@positron.chronox.de> (raw)
In-Reply-To: <CAKJ7aR4t_7fhRuFDX0xMPRSCxEAvL4Wn0mjXRy_4-WA9T5xRDA@mail.gmail.com>

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

  reply	other threads:[~2016-05-01 13:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-01 13:05 Crypto hash function decryption Gadre Nayan
2016-05-01 13:24 ` Stephan Mueller [this message]
     [not found]   ` <CAKJ7aR4bf_5dSUgAm8mXvfdV=HjVNVF-q6Zt3kDf0DzzATnwrw@mail.gmail.com>
2016-05-01 15:54     ` Stephan Mueller

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=7386652.LF5ZBdauM9@positron.chronox.de \
    --to=smueller@chronox.de \
    --cc=gadrenayan@gmail.com \
    --cc=linux-crypto@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