In the Linux kernel, the following vulnerability has been resolved:
crypto: ecdsa - Harden against integer overflows in DIVROUNDUP()
Herbert notes that DIVROUNDUP() may overflow unnecessarily if an ecdsa implementation's ->key_size() callback returns an unusually large value. Herbert instead suggests (for a division by 8):
X / 8 + !!(X & 7)
Based on this formula, introduce a generic DIVROUNDUPPOW2() macro and use it in lieu of DIVROUNDUP() for ->keysize() return values.
Additionally, use the macro in eccdigitsfrombytes(), whose "nbytes" parameter is a ->keysize() return value in some instances, or a user-specified ASN.1 length in the case of ecdsagetsignature_rs().