fix dsa pre padding

This commit is contained in:
toddouska 2016-09-21 18:51:11 -07:00
parent 2368d49678
commit 9e4e08d7a7

View File

@ -356,6 +356,7 @@ int wc_DsaSign(const byte* digest, byte* out, DsaKey* key, WC_RNG* rng)
mp_int k, kInv, r, s, H;
int ret, sz;
byte buffer[DSA_HALF_SIZE];
byte* tmp = out; /* initial output pointer */
sz = min((int)sizeof(buffer), mp_unsigned_bin_size(&key->q));
@ -405,19 +406,18 @@ int wc_DsaSign(const byte* digest, byte* out, DsaKey* key, WC_RNG* rng)
int rSz = mp_unsigned_bin_size(&r);
int sSz = mp_unsigned_bin_size(&s);
if (rSz == DSA_HALF_SIZE - 1) {
out[0] = 0;
out++;
while (rSz++ < DSA_HALF_SIZE) {
*out++ = 0x00; /* pad front with zeros */
}
if (mp_to_unsigned_bin(&r, out) != MP_OKAY)
ret = MP_TO_E;
else {
if (sSz == DSA_HALF_SIZE - 1) {
out[rSz] = 0;
out++;
}
ret = mp_to_unsigned_bin(&s, out + rSz);
out = tmp + DSA_HALF_SIZE; /* advance to s in output */
while (sSz++ < DSA_HALF_SIZE) {
*out++ = 0x00; /* pad front with zeros */
}
ret = mp_to_unsigned_bin(&s, out);
}
}