Avoid division by zero in hybrid point encoding
authorTheo Buehler <tb@openbsd.org>
Sat, 1 May 2021 10:25:50 +0000 (12:25 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 17 May 2021 08:41:27 +0000 (10:41 +0200)
commitc054a6d45dab1bbe38e1c89518e40ba9a9660baa
treeb3e972447287b9bd855b6d5df825fc72889a64f0
parentb743b16113ca0e30c383191c804de37dbfc4f12e
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: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15112)
crypto/ec/ec2_oct.c