X-Git-Url: https://www.bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=src%2Fint%2Fi31_mulacc.c;h=024d095665a6b5c6f0e46eb4479386cc8dd03e18;hp=04a42c7adbe1161f09ca82464e3a42f20e2a433c;hb=431629d869126b4fd605e371039cb341b3f811f7;hpb=3210f38e0491b39aec1ef419cb4114e9483089fb diff --git a/src/int/i31_mulacc.c b/src/int/i31_mulacc.c index 04a42c7..024d095 100644 --- a/src/int/i31_mulacc.c +++ b/src/int/i31_mulacc.c @@ -29,10 +29,19 @@ void br_i31_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b) { size_t alen, blen, u; + uint32_t dl, dh; alen = (a[0] + 31) >> 5; blen = (b[0] + 31) >> 5; - d[0] = a[0] + b[0]; + + /* + * We want to add the two bit lengths, but these are encoded, + * which requires some extra care. + */ + dl = (a[0] & 31) + (b[0] & 31); + dh = (a[0] >> 5) + (b[0] >> 5); + d[0] = (dh << 5) + dl + (~(uint32_t)(dl - 31) >> 31); + for (u = 0; u < blen; u ++) { uint32_t f; size_t v;