From fc6fce3bbf3f2b3ea30e1d154cd9511b1f833e3b Mon Sep 17 00:00:00 2001 From: Emman Date: Fri, 8 Apr 2022 10:50:11 +0800 Subject: [PATCH] Test Issue 52075 - generic impl panic when scalar has too many leading zeroes --- sm2/p256_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sm2/p256_test.go b/sm2/p256_test.go index 584c456c..1cde393d 100644 --- a/sm2/p256_test.go +++ b/sm2/p256_test.go @@ -277,3 +277,17 @@ func TestP256CombinedMult(t *testing.T) { t.Errorf("1×G + (-1)×G = (%d, %d), should be ∞", x, y) } } + +func TestIssue52075(t *testing.T) { + Gx, Gy := P256().Params().Gx, P256().Params().Gy + scalar := make([]byte, 33) + scalar[32] = 1 + x, y := P256().ScalarBaseMult(scalar) + if x.Cmp(Gx) != 0 || y.Cmp(Gy) != 0 { + t.Errorf("unexpected output (%v,%v)", x, y) + } + x, y = P256().ScalarMult(Gx, Gy, scalar) + if x.Cmp(Gx) != 0 || y.Cmp(Gy) != 0 { + t.Errorf("unexpected output (%v,%v)", x, y) + } +}