package fiat
import (
"crypto/subtle"
"errors"
)
type P224Element struct {
x p224MontgomeryDomainFieldElement
}
const p224ElementLen = 28
type p224UntypedFieldElement = [4 ]uint64
func (e *P224Element ) One () *P224Element {
p224SetOne (&e .x )
return e
}
func (e *P224Element ) Equal (t *P224Element ) int {
eBytes := e .Bytes ()
tBytes := t .Bytes ()
return subtle .ConstantTimeCompare (eBytes , tBytes )
}
func (e *P224Element ) IsZero () int {
zero := make ([]byte , p224ElementLen )
eBytes := e .Bytes ()
return subtle .ConstantTimeCompare (eBytes , zero )
}
func (e *P224Element ) Set (t *P224Element ) *P224Element {
e .x = t .x
return e
}
func (e *P224Element ) Bytes () []byte {
var out [p224ElementLen ]byte
return e .bytes (&out )
}
func (e *P224Element ) bytes (out *[p224ElementLen ]byte ) []byte {
var tmp p224NonMontgomeryDomainFieldElement
p224FromMontgomery (&tmp , &e .x )
p224ToBytes (out , (*p224UntypedFieldElement )(&tmp ))
p224InvertEndianness (out [:])
return out [:]
}
func (e *P224Element ) SetBytes (v []byte ) (*P224Element , error ) {
if len (v ) != p224ElementLen {
return nil , errors .New ("invalid P224Element encoding" )
}
var minusOneEncoding = new (P224Element ).Sub (
new (P224Element ), new (P224Element ).One ()).Bytes ()
for i := range v {
if v [i ] < minusOneEncoding [i ] {
break
}
if v [i ] > minusOneEncoding [i ] {
return nil , errors .New ("invalid P224Element encoding" )
}
}
var in [p224ElementLen ]byte
copy (in [:], v )
p224InvertEndianness (in [:])
var tmp p224NonMontgomeryDomainFieldElement
p224FromBytes ((*p224UntypedFieldElement )(&tmp ), &in )
p224ToMontgomery (&e .x , &tmp )
return e , nil
}
func (e *P224Element ) Add (t1 , t2 *P224Element ) *P224Element {
p224Add (&e .x , &t1 .x , &t2 .x )
return e
}
func (e *P224Element ) Sub (t1 , t2 *P224Element ) *P224Element {
p224Sub (&e .x , &t1 .x , &t2 .x )
return e
}
func (e *P224Element ) Mul (t1 , t2 *P224Element ) *P224Element {
p224Mul (&e .x , &t1 .x , &t2 .x )
return e
}
func (e *P224Element ) Square (t *P224Element ) *P224Element {
p224Square (&e .x , &t .x )
return e
}
func (v *P224Element ) Select (a , b *P224Element , cond int ) *P224Element {
p224Selectznz ((*p224UntypedFieldElement )(&v .x ), p224Uint1 (cond ),
(*p224UntypedFieldElement )(&b .x ), (*p224UntypedFieldElement )(&a .x ))
return v
}
func p224InvertEndianness (v []byte ) {
for i := 0 ; i < len (v )/2 ; i ++ {
v [i ], v [len (v )-1 -i ] = v [len (v )-1 -i ], v [i ]
}
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .