Skip to content

Commit

Permalink
curve25519: remove dependency on fmt
Browse files Browse the repository at this point in the history
For golang/go#48154

Change-Id: If7e99bd1159edc2e3deeb3a4e3d8fb048bc591ab
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/348069
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
  • Loading branch information
aaqaishtyaq authored and Maisem Ali committed Nov 15, 2022
1 parent 04a15b9 commit 51fd58e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions curve25519/curve25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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] {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions curve25519/curve25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package curve25519
import (
"bytes"
"crypto/rand"
"fmt"
"encoding/hex"
"testing"
)

Expand All @@ -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)
}
Expand Down

0 comments on commit 51fd58e

Please sign in to comment.