mirror of
https://github.com/arnaucube/go-iden3-crypto.git
synced 2026-02-07 11:36:41 +01:00
Compare commits
4 Commits
v0.0.3
...
feature/tr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bffc894c62 | ||
|
|
3d81ae3d8b | ||
|
|
eb41fe0757 | ||
|
|
e10db811aa |
17
.travis.yml
17
.travis.yml
@@ -4,5 +4,22 @@ language: go
|
||||
go:
|
||||
- "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:
|
||||
- GO111MODULE=on
|
||||
|
||||
before_install:
|
||||
- export GOARCH=$XGOARCH
|
||||
|
||||
script:
|
||||
- go test -v ./...
|
||||
|
||||
@@ -513,15 +513,33 @@ func (z *Element) String() string {
|
||||
|
||||
// ToBigInt returns z as a big.Int in Montgomery form
|
||||
func (z *Element) ToBigInt(res *big.Int) *big.Int {
|
||||
if bits.UintSize == 64 {
|
||||
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
|
||||
func (z Element) ToBigIntRegular(res *big.Int) *big.Int {
|
||||
z.FromMont()
|
||||
if bits.UintSize == 64 {
|
||||
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
|
||||
@@ -548,9 +566,19 @@ func (z *Element) SetBigInt(v *big.Int) *Element {
|
||||
}
|
||||
// v should
|
||||
vBits := vv.Bits()
|
||||
if bits.UintSize == 64 {
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
11
utils/showarchbits_test.go
Normal file
11
utils/showarchbits_test.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user