@@ -408,6 +408,7 @@ static int RSA_verify_signature(const struct public_key *key,
/* Variables as per RFC3447 sec 8.2.2 */
const u8 *H = sig->digest;
u8 *EM = NULL;
+ u8 *EM_tmp = NULL;
MPI m = NULL;
size_t k;
@@ -442,19 +443,28 @@ static int RSA_verify_signature(const struct public_key *key,
/* (2c) Convert the message representative (m) to an encoded message
* (EM) of length k octets.
*
- * NOTE! The leading zero byte is suppressed by MPI, so we pass a
- * pointer to the _preceding_ byte to RSA_verify()!
+ * NOTE! The leading zero byte is suppressed by MPI, so we add it
+ * back to EM before input to RSA_verify()!
*/
- ret = RSA_I2OSP(m, k, &EM);
+ ret = RSA_I2OSP(m, k, &EM_tmp);
if (ret < 0)
goto error;
- ret = RSA_verify(H, EM - 1, k, sig->digest_size,
+ EM = kmalloc(k, GFP_KERNEL);
+ if (!EM) {
+ ret = -ENOMEM;
+ goto error;
+ }
+ memset(EM, 0, 1);
+ memcpy(EM + 1, EM_tmp, k-1);
+
+ ret = RSA_verify(H, EM, k, sig->digest_size,
RSA_ASN1_templates[sig->pkey_hash_algo].data,
RSA_ASN1_templates[sig->pkey_hash_algo].size);
-error:
kfree(EM);
+error:
+ kfree(EM_tmp);
mpi_free(m);
kleave(" = %d", ret);
return ret;