Export reverse byte order function (#10040)

* Reverse byte order

* Update BUILD.bazel

* Go imports

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terence tsao
2022-01-11 10:42:03 -08:00
committed by GitHub
parent 3d02addfe4
commit 88b94eae18
4 changed files with 26 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ go_library(
"//container/trie:go_default_library",
"//crypto/bls:go_default_library",
"//crypto/hash:go_default_library",
"//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//time:go_default_library",
"@com_github_pkg_errors//:go_default_library",

View File

@@ -5,6 +5,8 @@ import (
"math/big"
"sync"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/async"
"github.com/prysmaticlabs/prysm/crypto/bls"
@@ -51,7 +53,7 @@ func deterministicallyGenerateKeys(startIndex, numKeys uint64) ([]bls.SecretKey,
binary.LittleEndian.PutUint32(enc, uint32(i))
hash := hash.Hash(enc)
// Reverse byte order to big endian for use with big ints.
b := reverseByteOrder(hash[:])
b := bytesutil.ReverseByteOrder(hash[:])
num := new(big.Int)
num = num.SetBytes(b)
order := new(big.Int)
@@ -76,12 +78,3 @@ func deterministicallyGenerateKeys(startIndex, numKeys uint64) ([]bls.SecretKey,
}
return privKeys, pubKeys, nil
}
// Switch the endianness of a byte slice by reversing its order.
func reverseByteOrder(input []byte) []byte {
b := input
for i := 0; i < len(b)/2; i++ {
b[i], b[len(b)-i-1] = b[len(b)-i-1], b[i]
}
return b
}