Skip to content

Commit

Permalink
lib/digsig: pkcs_1_v1_5_decode_emsa cleanup
Browse files Browse the repository at this point in the history
Removed useless 'is_valid' variable in pkcs_1_v1_5_decode_emsa(),
which was inhereted from original code. Client now uses return value
to check for an error.

Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
Reviewed-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jmorris@namei.org>
  • Loading branch information
Dmitry Kasatkin authored and James Morris committed Feb 1, 2012
1 parent f58a081 commit b35e286
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions lib/digsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ static int pkcs_1_v1_5_decode_emsa(const unsigned char *msg,
unsigned long msglen,
unsigned long modulus_bitlen,
unsigned char *out,
unsigned long *outlen,
int *is_valid)
unsigned long *outlen)
{
unsigned long modulus_len, ps_len, i;
int result;

/* default to invalid packet */
*is_valid = 0;

modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);

Expand All @@ -50,39 +45,30 @@ static int pkcs_1_v1_5_decode_emsa(const unsigned char *msg,
return -EINVAL;

/* separate encoded message */
if ((msg[0] != 0x00) || (msg[1] != (unsigned char)1)) {
result = -EINVAL;
goto bail;
}
if ((msg[0] != 0x00) || (msg[1] != (unsigned char)1))
return -EINVAL;

for (i = 2; i < modulus_len - 1; i++)
if (msg[i] != 0xFF)
break;

/* separator check */
if (msg[i] != 0) {
if (msg[i] != 0)
/* There was no octet with hexadecimal value 0x00
to separate ps from m. */
result = -EINVAL;
goto bail;
}
return -EINVAL;

ps_len = i - 2;

if (*outlen < (msglen - (2 + ps_len + 1))) {
*outlen = msglen - (2 + ps_len + 1);
result = -EOVERFLOW;
goto bail;
return -EOVERFLOW;
}

*outlen = (msglen - (2 + ps_len + 1));
memcpy(out, &msg[2 + ps_len + 1], *outlen);

/* valid packet */
*is_valid = 1;
result = 0;
bail:
return result;
return 0;
}

/*
Expand All @@ -96,7 +82,7 @@ static int digsig_verify_rsa(struct key *key,
unsigned long len;
unsigned long mlen, mblen;
unsigned nret, l;
int valid, head, i;
int head, i;
unsigned char *out1 = NULL, *out2 = NULL;
MPI in = NULL, res = NULL, pkey[2];
uint8_t *p, *datap, *endp;
Expand Down Expand Up @@ -172,10 +158,9 @@ static int digsig_verify_rsa(struct key *key,
memset(out1, 0, head);
memcpy(out1 + head, p, l);

err = -EINVAL;
pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len, &valid);
err = pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len);

if (valid && len == hlen)
if (!err && len == hlen)
err = memcmp(out2, h, hlen);

err:
Expand Down

0 comments on commit b35e286

Please sign in to comment.