Compare commits

...

4 Commits

Author SHA1 Message Date
Eduard S
bffc894c62 Fix Travis to really test 32 bits
To make sure 32 bits arch is being tested, try the following test which should
fail in 32 bits mode:
```go
package utils

import (
	"math/bits"
	"testing"
)

func TestBreak(t *testing.T) {
	if bits.UintSize != 64 {
		panic("bits.UintSize != 64")
	}
}
```
2020-04-09 16:59:02 +02:00
Eduard S
3d81ae3d8b Test break in 386 2020-04-09 16:38:21 +02:00
arnau
eb41fe0757 Merge pull request #18 from iden3/feature/fix32bits
Fix compat with 32 bit arch
2020-03-18 11:55:56 +01:00
Eduard S
e10db811aa Fix compat with 32 bit arch 2020-03-17 17:17:45 +01:00
3 changed files with 62 additions and 6 deletions

View File

@@ -4,5 +4,22 @@ language: go
go: go:
- "1.12" - "1.12"
# Travis overrides the GOARCH env var probably in its `travis_setup_go`
# function, so we need a work around...
jobs:
include:
- name: "Unit Tests 64 bit arch"
env:
- XGOARCH="amd64"
- name: "Unit Test 32 bit arch"
env:
- XGOARCH="386"
env: env:
- GO111MODULE=on - GO111MODULE=on
before_install:
- export GOARCH=$XGOARCH
script:
- go test -v ./...

View File

@@ -513,15 +513,33 @@ func (z *Element) String() string {
// ToBigInt returns z as a big.Int in Montgomery form // ToBigInt returns z as a big.Int in Montgomery form
func (z *Element) ToBigInt(res *big.Int) *big.Int { func (z *Element) ToBigInt(res *big.Int) *big.Int {
bits := (*[4]big.Word)(unsafe.Pointer(z)) if bits.UintSize == 64 {
return res.SetBits(bits[:]) bits := (*[4]big.Word)(unsafe.Pointer(z))
return res.SetBits(bits[:])
} else {
var bits [8]big.Word
for i := 0; i < len(z); i++ {
bits[i*2] = big.Word(z[i])
bits[i*2+1] = big.Word(z[i] >> 32)
}
return res.SetBits(bits[:])
}
} }
// ToBigIntRegular returns z as a big.Int in regular form // ToBigIntRegular returns z as a big.Int in regular form
func (z Element) ToBigIntRegular(res *big.Int) *big.Int { func (z Element) ToBigIntRegular(res *big.Int) *big.Int {
z.FromMont() z.FromMont()
bits := (*[4]big.Word)(unsafe.Pointer(&z)) if bits.UintSize == 64 {
return res.SetBits(bits[:]) bits := (*[4]big.Word)(unsafe.Pointer(&z))
return res.SetBits(bits[:])
} else {
var bits [8]big.Word
for i := 0; i < len(z); i++ {
bits[i*2] = big.Word(z[i])
bits[i*2+1] = big.Word(z[i] >> 32)
}
return res.SetBits(bits[:])
}
} }
// SetBigInt sets z to v (regular form) and returns z in Montgomery form // SetBigInt sets z to v (regular form) and returns z in Montgomery form
@@ -548,8 +566,18 @@ func (z *Element) SetBigInt(v *big.Int) *Element {
} }
// v should // v should
vBits := vv.Bits() vBits := vv.Bits()
for i := 0; i < len(vBits); i++ { if bits.UintSize == 64 {
z[i] = uint64(vBits[i]) for i := 0; i < len(vBits); i++ {
z[i] = uint64(vBits[i])
}
} else {
for i := 0; i < len(vBits); i++ {
if i%2 == 0 {
z[i/2] = uint64(vBits[i])
} else {
z[i/2] |= uint64(vBits[i]) << 32
}
}
} }
return z.ToMont() return z.ToMont()
} }

View File

@@ -0,0 +1,11 @@
package utils
import (
"fmt"
"math/bits"
"testing"
)
func TestShowArchBits(t *testing.T) {
fmt.Printf("Architecture is %v bits\n", bits.UintSize)
}