// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Code generated by generate.go. DO NOT EDIT.

package fiat

import (
	
	
)

// P256Element is an integer modulo 2^256 - 2^224 + 2^192 + 2^96 - 1.
//
// The zero value is a valid zero element.
type P256Element struct {
	// Values are represented internally always in the Montgomery domain, and
	// converted in Bytes and SetBytes.
	x p256MontgomeryDomainFieldElement
}

const p256ElementLen = 32

type p256UntypedFieldElement = [4]uint64

// One sets e = 1, and returns e.
func ( *P256Element) () *P256Element {
	p256SetOne(&.x)
	return 
}

// Equal returns 1 if e == t, and zero otherwise.
func ( *P256Element) ( *P256Element) int {
	 := .Bytes()
	 := .Bytes()
	return subtle.ConstantTimeCompare(, )
}

// IsZero returns 1 if e == 0, and zero otherwise.
func ( *P256Element) () int {
	 := make([]byte, p256ElementLen)
	 := .Bytes()
	return subtle.ConstantTimeCompare(, )
}

// Set sets e = t, and returns e.
func ( *P256Element) ( *P256Element) *P256Element {
	.x = .x
	return 
}

// Bytes returns the 32-byte big-endian encoding of e.
func ( *P256Element) () []byte {
	// This function is outlined to make the allocations inline in the caller
	// rather than happen on the heap.
	var  [p256ElementLen]byte
	return .bytes(&)
}

func ( *P256Element) ( *[p256ElementLen]byte) []byte {
	var  p256NonMontgomeryDomainFieldElement
	p256FromMontgomery(&, &.x)
	p256ToBytes(, (*p256UntypedFieldElement)(&))
	p256InvertEndianness([:])
	return [:]
}

// SetBytes sets e = v, where v is a big-endian 32-byte encoding, and returns e.
// If v is not 32 bytes or it encodes a value higher than 2^256 - 2^224 + 2^192 + 2^96 - 1,
// SetBytes returns nil and an error, and e is unchanged.
func ( *P256Element) ( []byte) (*P256Element, error) {
	if len() != p256ElementLen {
		return nil, errors.New("invalid P256Element encoding")
	}

	// Check for non-canonical encodings (p + k, 2p + k, etc.) by comparing to
	// the encoding of -1 mod p, so p - 1, the highest canonical encoding.
	var  = new(P256Element).Sub(
		new(P256Element), new(P256Element).One()).Bytes()
	for  := range  {
		if [] < [] {
			break
		}
		if [] > [] {
			return nil, errors.New("invalid P256Element encoding")
		}
	}

	var  [p256ElementLen]byte
	copy([:], )
	p256InvertEndianness([:])
	var  p256NonMontgomeryDomainFieldElement
	p256FromBytes((*p256UntypedFieldElement)(&), &)
	p256ToMontgomery(&.x, &)
	return , nil
}

// Add sets e = t1 + t2, and returns e.
func ( *P256Element) (,  *P256Element) *P256Element {
	p256Add(&.x, &.x, &.x)
	return 
}

// Sub sets e = t1 - t2, and returns e.
func ( *P256Element) (,  *P256Element) *P256Element {
	p256Sub(&.x, &.x, &.x)
	return 
}

// Mul sets e = t1 * t2, and returns e.
func ( *P256Element) (,  *P256Element) *P256Element {
	p256Mul(&.x, &.x, &.x)
	return 
}

// Square sets e = t * t, and returns e.
func ( *P256Element) ( *P256Element) *P256Element {
	p256Square(&.x, &.x)
	return 
}

// Select sets v to a if cond == 1, and to b if cond == 0.
func ( *P256Element) (,  *P256Element,  int) *P256Element {
	p256Selectznz((*p256UntypedFieldElement)(&.x), p256Uint1(),
		(*p256UntypedFieldElement)(&.x), (*p256UntypedFieldElement)(&.x))
	return 
}

func p256InvertEndianness( []byte) {
	for  := 0;  < len()/2; ++ {
		[], [len()-1-] = [len()-1-], []
	}
}