From 05595931fe9d3f8894ab063e1981d28e9873e2cb Mon Sep 17 00:00:00 2001 From: Aaqa Ishtyaq Date: Tue, 7 Sep 2021 23:22:23 +0530 Subject: [PATCH] curve25519: remove dependency on fmt For golang/go#48154 Change-Id: If7e99bd1159edc2e3deeb3a4e3d8fb048bc591ab Reviewed-on: https://go-review.googlesource.com/c/crypto/+/348069 Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot Run-TryBot: Dmitri Shuralyov Auto-Submit: Dmitri Shuralyov --- curve25519/curve25519.go | 9 +++++---- curve25519/curve25519_test.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/curve25519/curve25519.go b/curve25519/curve25519.go index cda3fdd..bc62161 100644 --- a/curve25519/curve25519.go +++ b/curve25519/curve25519.go @@ -9,7 +9,8 @@ package curve25519 // import "golang.org/x/crypto/curve25519" import ( "crypto/subtle" - "fmt" + "errors" + "strconv" "golang.org/x/crypto/curve25519/internal/field" ) @@ -124,10 +125,10 @@ func X25519(scalar, point []byte) ([]byte, error) { func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) { var in [32]byte if l := len(scalar); l != 32 { - return nil, fmt.Errorf("bad scalar length: %d, expected %d", l, 32) + return nil, errors.New("bad scalar length: " + strconv.Itoa(l) + ", expected 32") } if l := len(point); l != 32 { - return nil, fmt.Errorf("bad point length: %d, expected %d", l, 32) + return nil, errors.New("bad point length: " + strconv.Itoa(l) + ", expected 32") } copy(in[:], scalar) if &point[0] == &Basepoint[0] { @@ -138,7 +139,7 @@ func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) { copy(base[:], point) ScalarMult(dst, &in, &base) if subtle.ConstantTimeCompare(dst[:], zero[:]) == 1 { - return nil, fmt.Errorf("bad input point: low order point") + return nil, errors.New("bad input point: low order point") } } return dst[:], nil diff --git a/curve25519/curve25519_test.go b/curve25519/curve25519_test.go index 4246ddd..5a31541 100644 --- a/curve25519/curve25519_test.go +++ b/curve25519/curve25519_test.go @@ -7,7 +7,7 @@ package curve25519 import ( "bytes" "crypto/rand" - "fmt" + "encoding/hex" "testing" ) @@ -25,7 +25,7 @@ func TestX25519Basepoint(t *testing.T) { } } - result := fmt.Sprintf("%x", x) + result := hex.EncodeToString(x) if result != expectedHex { t.Errorf("incorrect result: got %s, want %s", result, expectedHex) }