Documentation
¶
Overview ¶
Package common provides shared utilities for post-quantum crypto implementations
Package common provides shared utilities for post-quantum crypto implementations
Index ¶
- Constants
- Variables
- func AllocateCombined(sizes ...int) []byte
- func Bytes2Hex(d []byte) string
- func ClearBytes(b []byte)
- func ConstantTimeSelect(v int, a, b []byte) []byte
- func CopyBytes(b []byte) (copiedBytes []byte)
- func CopyWithPadding(dst, src []byte, padValue byte)
- func CreateSignatureBuffer(size int) []byte
- func DeriveKey(seed []byte, label string, outputLen int) []byte
- func FillRandomBytes(rand io.Reader, buf []byte) error
- func FromHex(s string) []byte
- func GenerateDeterministicBytes(seed []byte, length int) []byte
- func GenerateRandomBytes(rand io.Reader, size int) ([]byte, error)
- func GetHasher(h HashFunc) hash.Hash
- func Hex2Bytes(str string) []byte
- func IsHexAddress(s string) bool
- func Max(a, b int) int
- func Min(a, b int) int
- func SafeCopy(dst, src []byte) error
- func SecureCompare(a, b []byte) bool
- func SplitBuffer(buffer []byte, sizes ...int) [][]byte
- func ValidateBufferSize(buf []byte, expectedSize int, name string) error
- func ValidateMode(mode int, min, max int) error
- func ValidateRandomSource(rand io.Reader) error
- func XOF(seed []byte, outputLen int) []byte
- type Address
- func (a Address) Big() *big.Int
- func (a Address) Bytes() []byte
- func (a Address) Cmp(b Address) int
- func (a Address) Format(s fmt.State, c rune)
- func (a Address) Hash() Hash
- func (a Address) Hex() string
- func (a Address) MarshalText() ([]byte, error)
- func (a *Address) Scan(src interface{}) error
- func (a *Address) SetBytes(b []byte)
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(input []byte) error
- func (a *Address) UnmarshalText(input []byte) error
- func (a Address) Value() (driver.Value, error)
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- func (h Hash) Format(s fmt.State, c rune)
- func (h Hash) Generate(rand *rand.Rand, size int) interface{}
- func (h Hash) Hex() string
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) Scan(src interface{}) error
- func (h *Hash) SetBytes(b []byte)
- func (h Hash) String() string
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (h *Hash) UnmarshalText(input []byte) error
- func (h Hash) Value() (driver.Value, error)
- type HashFunc
Constants ¶
const ( // HashLength is the expected length of the hash HashLength = 32 // AddressLength is the expected length of the address AddressLength = 20 )
Variables ¶
var ( Big0 = big.NewInt(0) Big1 = big.NewInt(1) Big2 = big.NewInt(2) Big3 = big.NewInt(3) Big256 = big.NewInt(256) Big257 = big.NewInt(257) )
Common big integers often used
Functions ¶
func AllocateCombined ¶ added in v1.2.10
AllocateCombined allocates a single buffer for multiple data segments
func ClearBytes ¶ added in v1.2.10
func ClearBytes(b []byte)
ClearBytes securely clears sensitive data
func ConstantTimeSelect ¶ added in v1.2.10
ConstantTimeSelect returns a if v == 1, b if v == 0
func CopyWithPadding ¶ added in v1.2.10
CopyWithPadding copies source to destination with padding if needed
func CreateSignatureBuffer ¶ added in v1.2.10
CreateSignatureBuffer creates a signature buffer with proper initialization
func FillRandomBytes ¶ added in v1.2.10
FillRandomBytes fills existing buffer with random bytes
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func GenerateDeterministicBytes ¶ added in v1.2.10
GenerateDeterministicBytes generates deterministic bytes from seed
func GenerateRandomBytes ¶ added in v1.2.10
GenerateRandomBytes generates random bytes with validation
func IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.
func SecureCompare ¶ added in v1.2.10
SecureCompare performs constant-time comparison
func SplitBuffer ¶ added in v1.2.10
SplitBuffer splits a buffer into segments of specified sizes
func ValidateBufferSize ¶ added in v1.2.10
ValidateBufferSize checks if buffer has expected size
func ValidateMode ¶ added in v1.2.10
ValidateMode checks if a mode value is within valid range
func ValidateRandomSource ¶ added in v1.2.10
ValidateRandomSource checks if random source is not nil
Types ¶
type Address ¶
type Address [AddressLength]byte
Address represents the 20 byte address of an Ethereum account.
func BigToAddress ¶
BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.
func BytesToAddress ¶
BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.
func HexToAddress ¶
HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.
func (Address) MarshalText ¶
MarshalText returns the hex representation of a.
func (*Address) SetBytes ¶
SetBytes sets the address to the value of b. If b is larger than len(a), b will be cropped from the left.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Address) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type Hash ¶
type Hash [HashLength]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BigToHash ¶
BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func (Hash) MarshalText ¶
MarshalText returns the hex representation of h.
func (*Hash) SetBytes ¶
SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.
func (Hash) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.