From 4da2b5dafd07b960c874d476c5e19993c943e5e0 Mon Sep 17 00:00:00 2001
From: Luiz Eduardo Gava <leg@terra.com.br>
Date: Mon, 11 Aug 2003 22:42:09 +0200
Subject: [PATCH] (rsa_encrypt): Bugfix contributed by leg@terra.com.br.

Rev: src/nettle/rsa-encrypt.c:1.6
---
 rsa-encrypt.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/rsa-encrypt.c b/rsa-encrypt.c
index 8dbf04bc..2e746fea 100644
--- a/rsa-encrypt.c
+++ b/rsa-encrypt.c
@@ -56,11 +56,11 @@ rsa_encrypt(const struct rsa_public_key *key,
    * where padding should be at least 8 pseudorandomly generated
    * *non-zero* octets. */
      
-  if (length + 11 < key->size)
+  if (length + 11 > key->size)
     /* Message too long for this key. */
     return 0;
 
-  /* At least 8 bits of random padding */
+  /* At least 8 octets of random padding */
   padding = key->size - length - 3;
   assert(padding >= 8);
   
@@ -73,8 +73,9 @@ rsa_encrypt(const struct rsa_public_key *key,
   for (i = 0; i<padding; i++)
     if (!em[i+1])
       em[i+1] = 1;
-  
-  memcpy(em + 1 + padding, message, length);
+
+  em[padding+1] = 0;  
+  memcpy(em + 2 + padding, message, length);
 
   nettle_mpz_set_str_256_u(gibbberish, key->size - 1, em);
   mpz_powm(gibbberish, gibbberish, key->e, key->n);
-- 
GitLab