4

I am using Libgcrypt with Elgamal to encrypt a block of bytes, and I am having 2 problems:

  1. When I do not use padding and my block of bytes starts which an zero byte, I lose the first byte during decryption;

  2. If I use padding the encryption works well, but when I decrypt the padding is not removed. And apparently the first zero byte still there.

With RSA I am having the same problem :(

My test code is there: www.tiago.eti.br/storage/post.c And it do not use padding.

To use padding you need to change:

#define PADDING "raw"

to

#define PADDING "pkcs1"

And to change the encryption algorithm change:

#define ALG "elg"

to

#define ALG "rsa"

To compile you need to use:

gcc -Wall -g post.c -lgcrypt -o post

What can I do to solve it?

Jay
  • 9,585
  • 6
  • 49
  • 72
Tiago Queiroz
  • 151
  • 1
  • 11
  • 1
    I'm not sure I would expect the padding to be removed when the block is decrypted. – argentage Jul 18 '12 at 15:34
  • 2
    In documentation you can find this: "Function: gcry_error_t gcry_pk_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t data, gcry_sexp_t skey) (...)This function does not remove padding from the data by default. To let Libgcrypt remove padding, give a hint in `flags' telling which padding method was used when encrypting: (flags padding-method)" And I did it. But it did not work.... – Tiago Queiroz Jul 18 '12 at 17:51

1 Answers1

2

I posted the same question in Libgcrypt mailing list and I had an answer.

Libgcrypt until 1.5.0 does not remove the padding: it recognizes the flags but does nothing with the padding.

So the solution is update Libgcrypt to 1.5.0.

Jay
  • 9,585
  • 6
  • 49
  • 72
Tiago Queiroz
  • 151
  • 1
  • 11