scalar

package
v0.0.0-...-33e5fd3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(d, a, b *[4]uint64, rf Reduce256)

Scalar addition; partial reduction function is provided (rf). The reduction function must ensure that the result fits on 255 bits.

func Decode

func Decode(d *[4]uint64, src []byte, r *[4]uint64) int

Decode a scalar value from bytes. Modulus r is provided. Returned value:

 1   decode successful, value is in range and non-zero
 0   decode successful, value is zero
-1   decode failed, value is out of range.

On error, output value (in d[]) is forced to zero.

func DecodeReduce

func DecodeReduce(d *[4]uint64, src []byte, rf Reduce384)

Decode a scalar from bytes; the bytes are interpreted with unsigned little-endian convention into a big integer, which is reduced modulo the curve subgroup order r. All bytes from the input slice are used. If the input slice is empty, then the obtained value is 0. The reduction is applied with the provided function (rf) for reduction 384->256.

func Encode

func Encode(b []byte, s *[4]uint64, rf Reduce256) []byte

Encode a scalar into exactly 32 bytes. The scalar is reduced by invoking the provided reduction function. The bytes are appended to the provided slice. The extension is done in place if the provided slice has enough capacity. The new slice is returned.

func Mul

func Mul(d, a, b *[4]uint64, rf Reduce384)

Scalar multiplication; partial reduction function (rf, for 384->256) is prodived.

func Mul128x128

func Mul128x128(d *[4]uint64, a, b *[2]uint64)

128x128->256 multiplication.

func Mul128x128trunc

func Mul128x128trunc(d, a, b *[2]uint64)

128x128->128 multiplication.

func Mul256x128

func Mul256x128(d *[6]uint64, a *[4]uint64, b *[2]uint64)

256x128->384 multiplication.

func Mul256x256

func Mul256x256(d *[8]uint64, a *[4]uint64, b *[4]uint64)

256x256->512 multiplication.

func Recode5

func Recode5(d *[52]byte, a *[4]uint64)

Recode a scalar with 5-bit Booth encoding. Output is a sequence of small integers in the -15..+16 range such that:

a = \sum_{i=0}^{51} d[i]*2^(5*i)

Top digit d[51] is nonnegative. If the input value is less than 2^255, then the top digit can only be 0 or 1. Each output digit is encoded in a byte as sign+mantissa: the low 5 bits of the byte are the absolute value of the digit (in the 0..16 range), and the high bit of the byte is set to 1 for a negative digit, 0 otherwise. When the digit is 0, the function may encode it as -0 (0x80) or +0 (0x00) (the top digit d[51] cannot be -0, only +0).

func Recode5Small

func Recode5Small(d *[26]byte, k *[2]uint64)

Recode a small _unsigned_ 128-bit integer with 5-bit Booth encoding. Output is 26 digits, the top digit is necessarily nonnegative (and cannot be -0).

func Recode5SmallSigned

func Recode5SmallSigned(d *[26]byte, k *[2]uint64) uint64

Recode a small _signed_ 128-bit integer with 5-bit Booth encoding. If the source value is negative, then what is recoded is its absolute value; the source sign is returned (1 for negative, 0 for zero or positive). Output is 26 digits, the top digit is necessarily nonnegative (and cannot be -0).

func Sub

func Sub(d, a, b *[4]uint64, rf Reduce256, r *[4]uint64)

Scalar subtraction; partial reduction function (rf) and order (r) are provided. The reductin function must ensure that the results is less than 2*r.

func ToBytes

func ToBytes(s *[4]uint64, rf Reduce256) [32]byte

Encode a scalar into exactly 32 bytes. The scalar is reduced by invoking the provided reduction function.

Types

type Reduce256

type Reduce256 func(*[4]uint64, *[4]uint64)

Type for a scalar reduction function: input is a 256-bit integer, output is normalized into the 0..r-1 range.

type Reduce384

type Reduce384 func(*[4]uint64, *[6]uint64)

Type for a scalar reduction function: input is a 384-bit integer, output fits on 256 bits (but is not necessarily normalized to 0..r-1).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL