[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcrypt-devel
Subject:    Re: Decrypt using BcryptDecrypt
From:       Mandar Apte via Gcrypt-devel <gcrypt-devel () gnupg ! org>
Date:       2020-06-15 7:14:23
Message-ID: CAGHdk0iPVJrBMHGjhGAvLshMaD402O__bau0sT_HzhHT66K6Ug () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Any help regarding request in below email ?

On Wed, 10 Jun 2020, 10:08 pm Mandar Apte, <mandar.apte409@gmail.com> wrote:

> Hello Team,
>
>           Are there any APIs in Libgcrypt using which I can get padded
> data along with my plain text data which I can encrypt using
> gcry_cipher_encrypt?
>
>
> Thanks in advance.
> Best Regards,
> Mandar
>
> On Fri, 5 Jun 2020, 7:16 pm Mandar Apte, <mandar.apte409@gmail.com> wrote:
>
>> Hello Werner,
>>
>>           Thank you very much for the response.
>>
>> The way you have shown in the email chain below, I had done same thing in
>> my code as well. Also, I am passing the data of block length size only to
>> gcry_cipher_encrypt and gcry_cipher_decrypt APIs.
>> Now, my goal is to check, if the AES256 encryption/decryption is same for
>> libgcrypt and Bcrypt library. Thats the reason I am trying to decrypt the
>> data, which was encrypted using Libgcrypt APIs, using Bcrypt APIs on
>> windows.
>>
>> I am pretty sure if I use windows version of Libgcrypt my problem wont be
>> there at all.
>>
>> I think I myself have to handle the padding while encrypting using
>> Libgcrypt library APIs.
>>
>> Since, I have to handle padding in my code, is there any APIs in
>> libgcrypt with which I ensure that I am padding the data in standard way?
>>
>
>
> Are there any APIs in Libgcrypt using which I can get padded data along
>> with my plain text data which I can encrypt using gcry_cipher_encrypt?
>>
>>
>> Thank you in advance.
>> Best Regards,
>> Mandar
>>
>>
>>
>> On Fri, 5 Jun 2020, 2:05 pm Werner Koch, <wk@gnupg.org> wrote:
>>
>>> On Tue,  2 Jun 2020 16:57, Mandar Apte said:
>>> > On windows I am using Bcrypt library which also supports AES 256 in CBC
>>> > mode.
>>>
>>> FWIW, Libgcrypt runs very well on Windows.
>>>
>>> > Hence, I wanted to check, if the Libgcrypt APIs are doing padding
>>> > internally since I am not passing any such instruction to the Libgcrypt
>>> > library explicitly?
>>>
>>> No, Libgcrypt does not do any padding and it expects complete blocks.
>>> gcry_cipher_get_algo_blklen() tells you the block length of the cipher
>>> algorithm.
>>>
>>> There is a flag to enable ciphertext stealing (GCRY_CIPHER_CBC_CTS) but
>>> in this case you need to pass the entire plaintext/ciphertext to the
>>> encrypt/decrypt function; there is no way to do this incremental.
>>>
>>> For the standard padding as used in CMS (S/MIME), you need to handle the
>>> padding in your code; here is a snippet
>>>
>>>  if (last_block_is_incomplete)
>>>    {
>>>       int i,
>>>       int npad = blklen - (buflen % blklen);
>>>
>>>       p = buffer;
>>>       for (n=buflen, i=0; n < bufsize && i < npad; n++, i++)
>>>         p[n] = npad;
>>>       gcry_cipher_encrypt (chd, buffer, n, buffer, n);
>>>     }
>>>
>>>
>>>
>>> Shalom-Salam,
>>>
>>>    Werner
>>>
>>>
>>> --
>>> Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.
>>>
>>

[Attachment #5 (text/html)]

<div dir="auto"><div>Any help regarding request in below email ?  <br><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 10 Jun 2020, 10:08 pm \
Mandar Apte, &lt;<a href="mailto:mandar.apte409@gmail.com">mandar.apte409@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Hello Team,  \
</div><div dir="auto"><br></div><div dir="auto">                <span \
style="font-family:sans-serif">Are there any APIs in Libgcrypt using which I can get \
padded data along with my plain text data which I can encrypt using \
gcry_cipher_encrypt?  </span></div><div dir="auto"><br></div><div \
dir="auto"><br></div><div dir="auto">Thanks in advance.  </div><div dir="auto">Best \
Regards,  </div><div dir="auto">Mandar<br><br><div class="gmail_quote" \
dir="auto"><div dir="ltr" class="gmail_attr">On Fri, 5 Jun 2020, 7:16 pm Mandar Apte, \
&lt;<a href="mailto:mandar.apte409@gmail.com" target="_blank" \
rel="noreferrer">mandar.apte409@gmail.com</a>&gt; wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="auto">Hello Werner,<div dir="auto"><br><div \
dir="auto">               Thank you very much for the response.  </div><div \
dir="auto"><br></div><div dir="auto">The way you have shown in the email chain below, \
I had done same thing in my code as well. Also, I am passing the data of block length \
size only to gcry_cipher_encrypt and gcry_cipher_decrypt APIs.  </div><div \
dir="auto">Now, my goal is to check, if the AES256 encryption/decryption is same for \
libgcrypt and Bcrypt library. Thats the reason I am trying to decrypt the data, which \
was encrypted using Libgcrypt APIs, using Bcrypt APIs on windows.</div><div \
dir="auto">  </div><div dir="auto">I am pretty sure if I use windows version of \
Libgcrypt my problem wont be there at all.  </div><div dir="auto"><br></div><div \
dir="auto">I think I myself have to handle the padding while encrypting using \
Libgcrypt library APIs.  </div><div dir="auto"><br></div><div dir="auto">Since, I \
have to handle padding in my code, is there any APIs in libgcrypt with which I ensure \
that I am padding the data in standard way? \
</div></div></div></blockquote></div></div><div dir="auto"><br></div><div \
dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="auto"><div dir="auto"><div dir="auto">Are there any \
APIs in Libgcrypt using which I can get padded data along with my plain text data \
which I can encrypt using gcry_cipher_encrypt?  </div><div dir="auto"><br></div><div \
dir="auto"><br></div><div dir="auto">Thank you in advance.  </div><div \
dir="auto">Best  Regards,  </div><div dir="auto">Mandar</div><div \
dir="auto"><br></div></div><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" \
class="gmail_attr">On Fri, 5 Jun 2020, 2:05 pm Werner Koch, &lt;<a \
href="mailto:wk@gnupg.org" rel="noreferrer noreferrer" \
target="_blank">wk@gnupg.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue,   2 Jun \
2020 16:57, Mandar Apte said:<br> &gt; On windows I am using Bcrypt library which \
also supports AES 256 in CBC<br> &gt; mode.<br>
<br>
FWIW, Libgcrypt runs very well on Windows.<br>
<br>
&gt; Hence, I wanted to check, if the Libgcrypt APIs are doing padding<br>
&gt; internally since I am not passing any such instruction to the Libgcrypt<br>
&gt; library explicitly?<br>
<br>
No, Libgcrypt does not do any padding and it expects complete blocks.<br>
gcry_cipher_get_algo_blklen() tells you the block length of the cipher<br>
algorithm.<br>
<br>
There is a flag to enable ciphertext stealing (GCRY_CIPHER_CBC_CTS) but<br>
in this case you need to pass the entire plaintext/ciphertext to the<br>
encrypt/decrypt function; there is no way to do this incremental.<br>
<br>
For the standard padding as used in CMS (S/MIME), you need to handle the<br>
padding in your code; here is a snippet<br>
<br>
  if (last_block_is_incomplete)<br>
     { <br>
         int i,<br>
         int npad = blklen - (buflen % blklen);<br>
<br>
         p = buffer;<br>
         for (n=buflen, i=0; n &lt; bufsize &amp;&amp; i &lt; npad; n++, i++)<br>
            p[n] = npad;<br>
         gcry_cipher_encrypt (chd, buffer, n, buffer, n);<br>
      }<br>
<br>
<br>
<br>
Shalom-Salam,<br>
<br>
     Werner<br>
<br>
<br>
--<br>
Die Gedanken sind frei.   Ausnahmen regelt ein Bundesgesetz.<br>
</blockquote></div></div>
</blockquote></div></div></div>
</blockquote></div></div></div>



_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic