1
0
mirror of https://github.com/henrydcase/nobs.git synced 2024-11-26 00:51:22 +00:00
This commit is contained in:
Henry Case 2019-02-19 14:43:36 +00:00
parent 2f234154e4
commit fc84db2c0f
5 changed files with 40 additions and 25 deletions

View File

@ -13,7 +13,7 @@ V ?= 0
GOCACHE ?= off
GOARCH ?=
ETC_DIR = $(PRJ_DIR)/etc
BENCH_NAME = .
BENCH_NAME = BenchmarkXMul
DBG = 1
OPTS_ENV =
ifeq ($(NOASM),1)
@ -21,7 +21,7 @@ ifeq ($(NOASM),1)
endif
ifeq ($(DBG),1)
DBG_FLAGS+= -m -m # escape analysis
DBG_FLAGS+= #-m # escape analysis
DBG_FLAGS+= -l # no inline
DBG_FLAGS+= -N # debug symbols
#OPTS+=-gcflags=all="$(DBG_FLAGS)"
@ -68,3 +68,15 @@ vendor-sidh-for-tls: clean
bench: clean $(addprefix prep-,$(TARGETS))
cd $(GOPATH_LOCAL); $(OPTS_ENV) GOCACHE=$(GOCACHE) GOPATH=$(GOPATH_LOCAL) GOMAXPROCS=1 $(GO) test \
$(BENCH_OPTS) ./...
bench_csidh: clean make_dirs $(addprefix prep-,$(TARGETS))
cd $(GOPATH_LOCAL); $(OPTS_ENV) GOCACHE=$(GOCACHE) GOPATH=$(GOPATH_LOCAL) GOMAXPROCS=1 $(GO) test \
$(OPTS) -run="^_" -bench=$(BENCH_NAME) -memprofile mem.prof -benchmem github.com/henrydcase/nobs/dh/csidh
test_drbg: clean make_dirs $(addprefix prep-,$(TARGETS))
cd $(GOPATH_LOCAL); $(OPTS_ENV) GOCACHE=$(GOCACHE) GOPATH=$(GOPATH_LOCAL) GOMAXPROCS=1 $(GO) test \
$(OPTS) -c -run=. github.com/henrydcase/nobs/drbg
bench_drbg: clean make_dirs $(addprefix prep-,$(TARGETS))
cd $(GOPATH_LOCAL); $(OPTS_ENV) GOCACHE=$(GOCACHE) GOPATH=$(GOPATH_LOCAL) GOMAXPROCS=1 $(GO) test \
$(OPTS) -run="XXX" -bench=. -benchmem -memprofile=drbg_prof github.com/henrydcase/nobs/drbg

View File

@ -10,6 +10,10 @@ type PublicKey struct {
// Defines operations on private key
type PrivateKey struct {
e [37]int8
// Temporary buffer used during key generation. Placed
// here to avoid heap memory allocation
tmp [64]byte
}
// PrivateKey

View File

@ -3,12 +3,15 @@ package csidh
import "io"
import "crypto/rand"
// OZAPTF
var buf [8 * limbByteSize]byte
// TODO: this is weird. How do I know loop will end?
func randFp(fp *Fp) {
// var buf [len(fp) * limbByteSize]byte
mask := uint64(1<<(pbits%limbBitSize)) - 1
for {
*fp = Fp{}
var buf [len(fp) * limbByteSize]byte
if _, err := io.ReadFull(rand.Reader, buf[:]); err != nil {
// OZAPTF: to be re-done (AES_CTR)
panic("Can't read random number")
@ -60,15 +63,14 @@ func (c *PrivateKey) Generate(rand io.Reader) error {
}
for i := 0; i < len(primes); {
var buf [64]byte
_, err := io.ReadFull(rand, buf[:])
_, err := io.ReadFull(rand, c.tmp[:])
if err != nil {
return err
}
for j, _ := range buf {
if int8(buf[j]) <= expMax && int8(buf[j]) >= -expMax {
c.e[i>>1] |= int8((buf[j] & 0xf) << uint((i%2)*4))
for j, _ := range c.tmp {
if int8(c.tmp[j]) <= expMax && int8(c.tmp[j]) >= -expMax {
c.e[i>>1] |= int8((c.tmp[j] & 0xf) << uint((i%2)*4))
i = i + 1
if i == len(primes) {
break

View File

@ -272,31 +272,31 @@ func testProcessTestVectors(t *testing.T) {
func TestProcessTestVectors(t *testing.T) { testProcessTestVectors(t) }
var prv1, prv2 PrivateKey
// Private key generation
func BenchmarkGeneratePrivate(b *testing.B) {
for n := 0; n < b.N; n++ {
var prv PrivateKey
prv.Generate(rng)
prv1.Generate(rng)
}
}
// Public key generation from private (group action on empty key)
func BenchmarkGeneratePublic(b *testing.B) {
for n := 0; n < b.N; n++ {
var prv PrivateKey
var pub PublicKey
prv.Generate(rng)
pub.Generate(&prv)
prv1.Generate(rng)
pub.Generate(&prv1)
}
}
// Benchmark validation on same key multiple times
func BenchmarkValidate(b *testing.B) {
var pub PublicKey
var prv PrivateKey
prvBytes := []byte{0xaa, 0x54, 0xe4, 0xd4, 0xd0, 0xbd, 0xee, 0xcb, 0xf4, 0xd0, 0xc2, 0xbc, 0x52, 0x44, 0x11, 0xee, 0xe1, 0x14, 0xd2, 0x24, 0xe5, 0x0, 0xcc, 0xf5, 0xc0, 0xe1, 0x1e, 0xb3, 0x43, 0x52, 0x45, 0xbe, 0xfb, 0x54, 0xc0, 0x55, 0xb2}
prv1.Import(prvBytes)
prv.Generate(rng)
pub.Generate(&prv)
var pub PublicKey
pub.Generate(&prv1)
for n := 0; n < b.N; n++ {
pub.Validate()
@ -320,18 +320,15 @@ func BenchmarkValidateRandom(b *testing.B) {
// Benchmark validation on different keys
func BenchmarkValidateGenerated(b *testing.B) {
var pub PublicKey
var prv PrivateKey
for n := 0; n < b.N; n++ {
prv.Generate(rng)
pub.Generate(&prv)
prv1.Generate(rng)
pub.Generate(&prv1)
pub.Validate()
}
}
func BenchmarkDeriveGenerated(b *testing.B) {
var ss [64]uint8
var prv1, prv2 PrivateKey
var pub1, pub2 PublicKey
for n := 0; n < b.N; n++ {
prv1.Generate(rng)
@ -346,7 +343,6 @@ func BenchmarkDeriveGenerated(b *testing.B) {
func BenchmarkDerive(b *testing.B) {
var ss [64]uint8
var prv1, prv2 PrivateKey
var pub1, pub2 PublicKey
prv1.Generate(rng)

View File

@ -79,6 +79,7 @@ func cswapPoint(P1, P2 *Point, choice uint8) {
// see this: https://eprint.iacr.org/2017/264.pdf
func xMul512(kP, P *Point, co *Coeff, k *Fp) {
var A24 Coeff
R := *P
// P = P-Q
PdQ := *P