// 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 (
	
	
)

// P384Element is an integer modulo 2^384 - 2^128 - 2^96 + 2^32 - 1.
//
// The zero value is a valid zero element.
type P384Element struct {
	// Values are represented internally always in the Montgomery domain, and
	// converted in Bytes and SetBytes.
	x p384MontgomeryDomainFieldElement
}

const p384ElementLen = 48

type p384UntypedFieldElement = [6]uint64

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

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

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

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

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

func ( *P384Element) ( *[p384ElementLen]byte) []byte {
	var  p384NonMontgomeryDomainFieldElement
	p384FromMontgomery(&, &.x)
	p384ToBytes(, (*p384UntypedFieldElement)(&))
	p384InvertEndianness([:])
	return [:]
}

// SetBytes sets e = v, where v is a big-endian 48-byte encoding, and returns e.
// If v is not 48 bytes or it encodes a value higher than 2^384 - 2^128 - 2^96 + 2^32 - 1,
// SetBytes returns nil and an error, and e is unchanged.
func ( *P384Element) ( []byte) (*P384Element, error) {
	if len() != p384ElementLen {
		return nil, errors.New("invalid P384Element 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(P384Element).Sub(
		new(P384Element), new(P384Element).One()).Bytes()
	for  := range  {
		if [] < [] {
			break
		}
		if [] > [] {
			return nil, errors.New("invalid P384Element encoding")
		}
	}

	var  [p384ElementLen]byte
	copy([:], )
	p384InvertEndianness([:])
	var  p384NonMontgomeryDomainFieldElement
	p384FromBytes((*p384UntypedFieldElement)(&), &)
	p384ToMontgomery(&.x, &)
	return , nil
}

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

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

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

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

// Select sets v to a if cond == 1, and to b if cond == 0.
func ( *P384Element) (,  *P384Element,  int) *P384Element {
	p384Selectznz((*p384UntypedFieldElement)(&.x), p384Uint1(),
		(*p384UntypedFieldElement)(&.x), (*p384UntypedFieldElement)(&.x))
	return 
}

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