impl

package
v0.0.0-...-7685c8a Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

p256/impl

This package contains low-level P-256 field arithmetic and point operations.

Documentation

Overview

Package impl contains low-level P-256 field arithmetic and point operations.

See README.md for details.

Code generated by Fiat Cryptography. DO NOT EDIT.

Autogenerated: '/usr/local/bin/fiat-crypto' word-by-word-montgomery --lang Go --no-wide-int --relax-primitive-carry-to-bitwidth 32,64 --cmovznz-by-mul --internal-static --package-case flatcase --public-function-case camelCase --private-function-case camelCase --public-type-case camelCase --private-type-case camelCase --doc-newline-in-typedef-bounds --doc-prepend-header 'Code generated by Fiat Cryptography. DO NOT EDIT.' --doc-text-before-function-name ” --doc-text-before-type-name ” --package-name impl Fp 64 '2^256 - 2^224 + 2^192 + 2^96 - 1'

curve description: Fp

machine_wordsize = 64 (from "64")

requested operations: (all)

m = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff (from "2^256 - 2^224 + 2^192 + 2^96 - 1")

NOTE: In addition to the bounds specified above each function, all

functions synthesized for this Montgomery arithmetic require the

input to be strictly less than the prime modulus (m), and also

require the input to be in the unique saturated representation.

All functions also ensure that these two properties are true of

return values.

Computed values:

eval z = z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192)

bytes_eval z = z[0] + (z[1] << 8) + (z[2] << 16) + (z[3] << 24) + (z[4] << 32) + (z[5] << 40) + (z[6] << 48) + (z[7] << 56) + (z[8] << 64) + (z[9] << 72) + (z[10] << 80) + (z[11] << 88) + (z[12] << 96) + (z[13] << 104) + (z[14] << 112) + (z[15] << 120) + (z[16] << 128) + (z[17] << 136) + (z[18] << 144) + (z[19] << 152) + (z[20] << 160) + (z[21] << 168) + (z[22] << 176) + (z[23] << 184) + (z[24] << 192) + (z[25] << 200) + (z[26] << 208) + (z[27] << 216) + (z[28] << 224) + (z[29] << 232) + (z[30] << 240) + (z[31] << 248)

twos_complement_eval z = let x1 := z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192) in

                         if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256

Code generated by Fiat Cryptography. DO NOT EDIT.

Autogenerated: '/usr/local/bin/fiat-crypto' word-by-word-montgomery --lang Go --no-wide-int --relax-primitive-carry-to-bitwidth 32,64 --cmovznz-by-mul --internal-static --package-case flatcase --public-function-case camelCase --private-function-case camelCase --public-type-case camelCase --private-type-case camelCase --doc-newline-in-typedef-bounds --doc-prepend-header 'Code generated by Fiat Cryptography. DO NOT EDIT.' --doc-text-before-function-name ” --doc-text-before-type-name ” --package-name impl Fq 64 '2^256 - 2^224 + 2^192 - 89188191075325690597107910205041859247'

curve description: Fq

machine_wordsize = 64 (from "64")

requested operations: (all)

m = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 (from "2^256 - 2^224 + 2^192 - 89188191075325690597107910205041859247")

NOTE: In addition to the bounds specified above each function, all

functions synthesized for this Montgomery arithmetic require the

input to be strictly less than the prime modulus (m), and also

require the input to be in the unique saturated representation.

All functions also ensure that these two properties are true of

return values.

Computed values:

eval z = z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192)

bytes_eval z = z[0] + (z[1] << 8) + (z[2] << 16) + (z[3] << 24) + (z[4] << 32) + (z[5] << 40) + (z[6] << 48) + (z[7] << 56) + (z[8] << 64) + (z[9] << 72) + (z[10] << 80) + (z[11] << 88) + (z[12] << 96) + (z[13] << 104) + (z[14] << 112) + (z[15] << 120) + (z[16] << 128) + (z[17] << 136) + (z[18] << 144) + (z[19] << 152) + (z[20] << 160) + (z[21] << 168) + (z[22] << 176) + (z[23] << 184) + (z[24] << 192) + (z[25] << 200) + (z[26] << 208) + (z[27] << 216) + (z[28] << 224) + (z[29] << 232) + (z[30] << 240) + (z[31] << 248)

twos_complement_eval z = let x1 := z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192) in

                         if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256

Index

Constants

View Source
const (
	FpLimbs     = 4
	FpSatLimbs  = FpLimbs + 1
	FpBits      = 256
	FpBytes     = 8 * (((FpBits - 1) / 64) + 1)
	FpWideBytes = 2 * FpBytes
	FpDivSteps  = ((49 * FpBits) + 57) / 17
	FpE         = 1
)
View Source
const (
	FqLimbs     = 4
	FqSatLimbs  = FqLimbs + 1
	FqBits      = 256
	FqBytes     = 8 * (((FqBits - 1) / 64) + 1)
	FqWideBytes = 2 * FqBytes
	FqDivSteps  = ((49 * FqBits) + 57) / 17
	FqE         = 4
)

Variables

View Source
var (
	FpProgenitorExp = [...]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x3f}
	FpModulus       = [...]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff}
	FpRootOfUnity   Fp
)
View Source
var (
	FqProgenitorExp = [...]byte{0x2a, 0x19, 0xe3, 0x17, 0x56, 0xce, 0x9d, 0x27, 0xf4, 0xbc, 0x38, 0x6d, 0xd5, 0x37, 0xe7, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x07}
	FqModulus       = [...]byte{0x51, 0x25, 0x63, 0xfc, 0xc2, 0xca, 0xb9, 0xf3, 0x84, 0x9e, 0x17, 0xa7, 0xad, 0xfa, 0xe6, 0xbc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff}
	FqRootOfUnity   Fq
)

Functions

This section is empty.

Types

type CurveHasherParams

type CurveHasherParams struct{}

CurveHasherParams defines hash-to-curve parameters.

func (CurveHasherParams) L

L returns the hash-to-field length in bytes.

func (CurveHasherParams) MessageExpander

func (CurveHasherParams) MessageExpander() h2c.MessageExpander

MessageExpander returns the RFC 9380 message expander.

type Fp

type Fp struct {
	// contains filtered or unexported fields
}

func (*Fp) Add

func (f *Fp) Add(lhs, rhs *Fp)

func (*Fp) Bytes

func (f *Fp) Bytes() []byte

func (*Fp) ComponentsBytes

func (f *Fp) ComponentsBytes() [][]byte

func (*Fp) Degree

func (f *Fp) Degree() uint64

func (*Fp) Div

func (f *Fp) Div(lhs, rhs *Fp) (ok ct.Bool)

func (*Fp) Double

func (f *Fp) Double(x *Fp)

func (*Fp) Equal

func (f *Fp) Equal(v *Fp) ct.Bool

func (*Fp) GoString

func (f *Fp) GoString() string

func (*Fp) Hex

func (f *Fp) Hex() string

func (*Fp) Inv

func (f *Fp) Inv(a *Fp) (ok ct.Bool)

func (*Fp) IsNonZero

func (f *Fp) IsNonZero() ct.Bool

func (*Fp) IsOne

func (f *Fp) IsOne() ct.Bool

func (*Fp) IsZero

func (f *Fp) IsZero() ct.Bool

func (*Fp) Limbs

func (f *Fp) Limbs() []uint64

func (*Fp) Mul

func (f *Fp) Mul(lhs, rhs *Fp)

func (*Fp) MustSetHex

func (f *Fp) MustSetHex(v string)

func (*Fp) Neg

func (f *Fp) Neg(v *Fp)

func (*Fp) Select

func (f *Fp) Select(choice ct.Choice, z, nz *Fp)

func (*Fp) Set

func (f *Fp) Set(v *Fp)

func (*Fp) SetBytes

func (f *Fp) SetBytes(data []byte) (ok ct.Bool)

func (*Fp) SetBytesWide

func (f *Fp) SetBytesWide(data []byte) (ok ct.Bool)

func (*Fp) SetLimbs

func (f *Fp) SetLimbs(data []uint64) (ok ct.Bool)

func (*Fp) SetOne

func (f *Fp) SetOne()

func (*Fp) SetRandom

func (f *Fp) SetRandom(prng io.Reader) (ok ct.Bool)

func (*Fp) SetUint64

func (f *Fp) SetUint64(v uint64)

func (*Fp) SetUniformBytes

func (f *Fp) SetUniformBytes(componentsData ...[]byte) (ok ct.Bool)

func (*Fp) SetZero

func (f *Fp) SetZero()

func (*Fp) Sqrt

func (f *Fp) Sqrt(x *Fp) (ok ct.Bool)

func (*Fp) Square

func (f *Fp) Square(v *Fp)

func (*Fp) String

func (f *Fp) String() string

func (*Fp) Sub

func (f *Fp) Sub(lhs, rhs *Fp)

type Fq

type Fq struct {
	// contains filtered or unexported fields
}

func (*Fq) Add

func (f *Fq) Add(lhs, rhs *Fq)

func (*Fq) Bytes

func (f *Fq) Bytes() []byte

func (*Fq) ComponentsBytes

func (f *Fq) ComponentsBytes() [][]byte

func (*Fq) Degree

func (f *Fq) Degree() uint64

func (*Fq) Div

func (f *Fq) Div(lhs, rhs *Fq) (ok ct.Bool)

func (*Fq) Double

func (f *Fq) Double(x *Fq)

func (*Fq) Equal

func (f *Fq) Equal(v *Fq) ct.Bool

func (*Fq) GoString

func (f *Fq) GoString() string

func (*Fq) Hex

func (f *Fq) Hex() string

func (*Fq) Inv

func (f *Fq) Inv(a *Fq) (ok ct.Bool)

func (*Fq) IsNonZero

func (f *Fq) IsNonZero() ct.Bool

func (*Fq) IsOne

func (f *Fq) IsOne() ct.Bool

func (*Fq) IsZero

func (f *Fq) IsZero() ct.Bool

func (*Fq) Limbs

func (f *Fq) Limbs() []uint64

func (*Fq) Mul

func (f *Fq) Mul(lhs, rhs *Fq)

func (*Fq) MustSetHex

func (f *Fq) MustSetHex(v string)

func (*Fq) Neg

func (f *Fq) Neg(v *Fq)

func (*Fq) Select

func (f *Fq) Select(choice ct.Choice, z, nz *Fq)

func (*Fq) Set

func (f *Fq) Set(v *Fq)

func (*Fq) SetBytes

func (f *Fq) SetBytes(data []byte) (ok ct.Bool)

func (*Fq) SetBytesWide

func (f *Fq) SetBytesWide(data []byte) (ok ct.Bool)

func (*Fq) SetLimbs

func (f *Fq) SetLimbs(data []uint64) (ok ct.Bool)

func (*Fq) SetOne

func (f *Fq) SetOne()

func (*Fq) SetRandom

func (f *Fq) SetRandom(prng io.Reader) (ok ct.Bool)

func (*Fq) SetUint64

func (f *Fq) SetUint64(v uint64)

func (*Fq) SetUniformBytes

func (f *Fq) SetUniformBytes(componentsData ...[]byte) (ok ct.Bool)

func (*Fq) SetZero

func (f *Fq) SetZero()

func (*Fq) Sqrt

func (f *Fq) Sqrt(x *Fq) (ok ct.Bool)

func (*Fq) Square

func (f *Fq) Square(v *Fq)

func (*Fq) String

func (f *Fq) String() string

func (*Fq) Sub

func (f *Fq) Sub(lhs, rhs *Fq)

type Point

type Point = pointsImpl.ShortWeierstrassPointImpl[*Fp, curveParams, CurveHasherParams, curveMapper, Fp]

Point represents a curve point.

Jump to

Keyboard shortcuts

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