mirror of
https://github.com/pseXperiments/icicle.git
synced 2026-01-09 23:48:10 -05:00
This PR introduces major updates for ICICLE Core, Rust and Golang bindings --------- Co-authored-by: Yuval Shekel <yshekel@gmail.com> Co-authored-by: DmytroTym <dmytrotym1@gmail.com> Co-authored-by: Otsar <122266060+Otsar-Raikou@users.noreply.github.com> Co-authored-by: VitaliiH <vhnatyk@gmail.com> Co-authored-by: release-bot <release-bot@ingonyama.com> Co-authored-by: Stas <spolonsky@icloud.com> Co-authored-by: Jeremy Felder <jeremy.felder1@gmail.com> Co-authored-by: ImmanuelSegol <3ditds@gmail.com> Co-authored-by: JimmyHongjichuan <45908291+JimmyHongjichuan@users.noreply.github.com> Co-authored-by: pierre <pierreuu@gmail.com> Co-authored-by: Leon Hibnik <107353745+LeonHibnik@users.noreply.github.com> Co-authored-by: nonam3e <timur@ingonyama.com> Co-authored-by: Vlad <88586482+vladfdp@users.noreply.github.com> Co-authored-by: LeonHibnik <leon@ingonyama.com> Co-authored-by: nonam3e <71525212+nonam3e@users.noreply.github.com> Co-authored-by: vladfdp <vlad.heintz@gmail.com>
85 lines
1.5 KiB
Go
85 lines
1.5 KiB
Go
package internal
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
MOCKBASE_LIMBS int = 4
|
|
)
|
|
|
|
type MockBaseField struct {
|
|
limbs [MOCKBASE_LIMBS]uint32
|
|
}
|
|
|
|
func (f MockBaseField) Len() int {
|
|
return int(MOCKBASE_LIMBS)
|
|
}
|
|
|
|
func (f MockBaseField) Size() int {
|
|
return int(MOCKBASE_LIMBS * 4)
|
|
}
|
|
|
|
func (f MockBaseField) GetLimbs() []uint32 {
|
|
return f.limbs[:]
|
|
}
|
|
|
|
func (f MockBaseField) AsPointer() *uint32 {
|
|
return &f.limbs[0]
|
|
}
|
|
|
|
func (f *MockBaseField) FromUint32(v uint32) MockBaseField {
|
|
f.limbs[0] = v
|
|
return *f
|
|
}
|
|
|
|
func (f *MockBaseField) FromLimbs(limbs []uint32) MockBaseField {
|
|
if len(limbs) != f.Len() {
|
|
panic("Called FromLimbs with limbs of different length than field")
|
|
}
|
|
for i := range f.limbs {
|
|
f.limbs[i] = limbs[i]
|
|
}
|
|
|
|
return *f
|
|
}
|
|
|
|
func (f *MockBaseField) Zero() MockBaseField {
|
|
for i := range f.limbs {
|
|
f.limbs[i] = 0
|
|
}
|
|
|
|
return *f
|
|
}
|
|
|
|
func (f *MockBaseField) One() MockBaseField {
|
|
for i := range f.limbs {
|
|
f.limbs[i] = 0
|
|
}
|
|
f.limbs[0] = 1
|
|
|
|
return *f
|
|
}
|
|
|
|
func (f *MockBaseField) FromBytesLittleEndian(bytes []byte) MockBaseField {
|
|
if len(bytes)/4 != f.Len() {
|
|
panic(fmt.Sprintf("Called FromBytesLittleEndian with incorrect bytes length; expected %d - got %d", f.Len()*4, len(bytes)))
|
|
}
|
|
|
|
for i := range f.limbs {
|
|
f.limbs[i] = binary.LittleEndian.Uint32(bytes[i*4 : i*4+4])
|
|
}
|
|
|
|
return *f
|
|
}
|
|
|
|
func (f MockBaseField) ToBytesLittleEndian() []byte {
|
|
bytes := make([]byte, f.Len()*4)
|
|
for i, v := range f.limbs {
|
|
binary.LittleEndian.PutUint32(bytes[i*4:], v)
|
|
}
|
|
|
|
return bytes
|
|
}
|