Lost of data when encrypt and decrypt using libgcrypt and Elgamal
===

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][1]
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"

What can I do to solve it?

  [1]: http://www.tiago.eti.br/storage/post.c "post.c"