Documentation ¶
Index ¶
- Constants
- Variables
- func BinaryMul(c uint8, input []byte) []byte
- func BitsToBytes(input []uint8) ([]byte, error)
- func Bytes32(x *big.Int) []byte
- func BytesToBits(data []byte) []uint8
- func EnsureFieldOrder(fieldOrder *big.Int) error
- func EnsureRank(rank uint32, threshold uint32) error
- func EnsureThreshold(threshold uint32, n uint32) error
- func EulerFunction(primeFactor []*big.Int) (*big.Int, error)
- func ExtendHashOutput(salt, message []byte, outputByteLength int) []byte
- func FastMod3(number *big.Int) int
- func Gcd(a *big.Int, b *big.Int) *big.Int
- func GenRandomBytes(size int) ([]byte, error)
- func GetAnyMsg(bs ...[]byte) []proto.Message
- func HashBytesToInt(salt []byte, bs ...[]byte) (*big.Int, error)
- func HashProtos(salt []byte, msgs ...proto.Message) ([]byte, error)
- func HashProtosRejectSampling(fieldOrder *big.Int, msgs ...proto.Message) (*big.Int, []byte, error)
- func HashProtosToInt(salt []byte, msgs ...proto.Message) (*big.Int, error)
- func InRange(checkValue *big.Int, floor *big.Int, ceil *big.Int) error
- func IsRelativePrime(a *big.Int, b *big.Int) bool
- func Lcm(a, b *big.Int) (*big.Int, error)
- func Pad(x []byte, n int) []byte
- func RandomAbsoluteRangeInt(n *big.Int) (*big.Int, error)
- func RandomAbsoluteRangeIntBySeed(salt []byte, message []byte, q *big.Int) *big.Int
- func RandomCoprimeInt(n *big.Int) (*big.Int, error)
- func RandomInt(n *big.Int) (*big.Int, error)
- func RandomPositiveInt(n *big.Int) (*big.Int, error)
- func RandomPrime(bits int) (*big.Int, error)
- func ReverseByte(s []byte) []byte
- func ScalarMul(bit uint8, input []uint8) []uint8
- func Xor(bigArray, smallArray []byte) []byte
- type Hash
- type SafePrime
Constants ¶
const (
// SaltSize is based on blake2b256
SaltSize = 32
)
Variables ¶
var ( // ErrLessOrEqualBig2 is returned if the field order is less than or equal to 2 ErrLessOrEqualBig2 = errors.New("less 2") //ErrExceedMaxRetry is returned if we retried over times ErrExceedMaxRetry = errors.New("exceed max retries") //ErrInvalidInput is returned if the input is invalid ErrInvalidInput = errors.New("invalid input") //ErrLargeRank is returned if the rank is too large ErrLargeRank = errors.New("large rank") //ErrLargeThreshold is returned if the threshold is too large ErrLargeThreshold = errors.New("large threshold") // ErrNotInRange is returned if the value is not in the given range. ErrNotInRange = errors.New("not in range") // ErrLargerFloor is returned if the floor is larger than ceil. ErrLargerFloor = errors.New("larger floor") // ErrEmptySlice is returned if the length of slice is zero. ErrEmptySlice = errors.New("empty slice") // ErrSmallThreshold is returned if the threshold < 2. ErrSmallThreshold = errors.New("threshold < 2") // ErrSmallSafePrime is returned if the safePrime < 2^10. ErrSmallSafePrime = errors.New("safe-prime size must be at least 10-bit") )
var File_github_com_getamis_alice_crypto_utils_message_proto protoreflect.FileDescriptor
Functions ¶
func BitsToBytes ¶ added in v1.0.2
func BytesToBits ¶ added in v1.0.2
func EnsureFieldOrder ¶
EnsureFieldOrder ensures the field order should be more than 2.
func EnsureRank ¶
EnsureRank ensures the rank+1 should be smaller than threshold.
func EnsureThreshold ¶
EnsureThreshold ensures the threshold should be smaller than or equal to n.
func EulerFunction ¶
EulerFunction :(Special case) Assume that N is square-free and primeFactor consists of prime integers. Formula: N = prod_i P_i, the output is prod_i (P_i -1). TODO: general case.
func ExtendHashOutput ¶ added in v1.0.2
The hash result is Hash(salt + "," + message +"," + "0") | Hash(salt + "," + message + "," + "1") | .... | Hash(salt + "," + message + "," + "n-1"). Here n := Ceil (outputByteLength/32)
func FastMod3 ¶ added in v1.0.2
This is a algorithm to get number % 3. The velocity of this function is faster than new(bigInt).mod(number, 3).
func GenRandomBytes ¶
GenRandomBytes generates a random byte array with indicating the legnth.
func HashBytesToInt ¶ added in v1.0.2
func HashProtos ¶
HashProtos hashes a slice of message.
func HashProtosRejectSampling ¶ added in v1.0.2
func HashProtosToInt ¶ added in v1.0.2
Waring: The follwing function only work in S256 and P256, because the output of blake2b is 32 byte. HashProtosToInt hashes a slice of message to an integer.
func IsRelativePrime ¶
IsRelativePrime returns if a and b are relative primes
func Lcm ¶
Lcm calculates find Least Common Multiple https://rosettacode.org/wiki/Least_common_multiple#Go
func RandomAbsoluteRangeInt ¶ added in v1.0.2
RandomInt generates a random number in [-n, n].
func RandomAbsoluteRangeIntBySeed ¶ added in v1.0.2
RandomAbsoluteRangeIntBySeed generates a random number in (-2^q.bit, 2^q.bit) with seed.
func RandomCoprimeInt ¶
RandomCoprimeInt generates a random relative prime number in [2, n)
func RandomPositiveInt ¶
RandomPositiveInt generates a random number in [1, n).
func RandomPrime ¶
RandomPrime generates a random prime number with bits size
func ReverseByte ¶ added in v1.0.2
Types ¶
type Hash ¶
type Hash struct { Msgs []*any.Any `protobuf:"bytes,1,rep,name=msgs,proto3" json:"msgs,omitempty"` // contains filtered or unexported fields }
func (*Hash) Descriptor
deprecated
func (*Hash) ProtoMessage ¶
func (*Hash) ProtoMessage()
func (*Hash) ProtoReflect ¶ added in v1.0.2
func (x *Hash) ProtoReflect() protoreflect.Message
type SafePrime ¶ added in v1.0.2
p, q are primes and p = 2*q+1
func GenerateRandomSafePrime ¶ added in v1.0.2
The algorithm appears in the paper Safe Prime Generation with a Combined Sieve https://eprint.iacr.org/2003/186.pdf safe prime: p = 2q+1, where p and q are both primes.