Avoid division by zero in hybrid point encoding
authorTheo Buehler <tb@openbsd.org>
Sat, 1 May 2021 10:25:50 +0000 (12:25 +0200)
committerNicola Tuveri <nic.tuv@gmail.com>
Sun, 9 May 2021 11:52:53 +0000 (14:52 +0300)
commit56f0237938c7e99d04f004886d56cb76514c4d56
treee04940bbf0ab5b7412d806fb2552f78faa65310c
parent32b1da718d5d6f35fcef82f3794273807d6202e9
Avoid division by zero in hybrid point encoding

In hybrid and compressed point encodings, the form octet contains a bit
of information allowing to calculate y from x.  For a point on a binary
curve, this bit is zero if x is zero, otherwise it must match the
rightmost bit of of the field element y / x.  The existing code only
considers the second possibility. It could thus incorrecly fail with a
division by zero error as found by Guido Vranken's cryptofuzz.

This commit adds a few explanatory comments to oct2point. The only
actual code change is in the last hunk which adds a BN_is_zero(x)
check to avoid the division by zero.

Fixes #15021

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15108)
crypto/ec/ec2_oct.c