fix dsa pre padding
This commit is contained in:
parent
2368d49678
commit
9e4e08d7a7
@ -356,6 +356,7 @@ int wc_DsaSign(const byte* digest, byte* out, DsaKey* key, WC_RNG* rng)
|
|||||||
mp_int k, kInv, r, s, H;
|
mp_int k, kInv, r, s, H;
|
||||||
int ret, sz;
|
int ret, sz;
|
||||||
byte buffer[DSA_HALF_SIZE];
|
byte buffer[DSA_HALF_SIZE];
|
||||||
|
byte* tmp = out; /* initial output pointer */
|
||||||
|
|
||||||
sz = min((int)sizeof(buffer), mp_unsigned_bin_size(&key->q));
|
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 rSz = mp_unsigned_bin_size(&r);
|
||||||
int sSz = mp_unsigned_bin_size(&s);
|
int sSz = mp_unsigned_bin_size(&s);
|
||||||
|
|
||||||
if (rSz == DSA_HALF_SIZE - 1) {
|
while (rSz++ < DSA_HALF_SIZE) {
|
||||||
out[0] = 0;
|
*out++ = 0x00; /* pad front with zeros */
|
||||||
out++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mp_to_unsigned_bin(&r, out) != MP_OKAY)
|
if (mp_to_unsigned_bin(&r, out) != MP_OKAY)
|
||||||
ret = MP_TO_E;
|
ret = MP_TO_E;
|
||||||
else {
|
else {
|
||||||
if (sSz == DSA_HALF_SIZE - 1) {
|
out = tmp + DSA_HALF_SIZE; /* advance to s in output */
|
||||||
out[rSz] = 0;
|
while (sSz++ < DSA_HALF_SIZE) {
|
||||||
out++;
|
*out++ = 0x00; /* pad front with zeros */
|
||||||
}
|
}
|
||||||
ret = mp_to_unsigned_bin(&s, out + rSz);
|
ret = mp_to_unsigned_bin(&s, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user