@@ -35,7 +35,7 @@ INCFLAGS = -Isrc/include -Iinclude -Isrc/$(FIELD) -Isrc/$(FIELD)/$(ARCH) | |||||
LANGFLAGS = -std=c99 -fno-strict-aliasing | LANGFLAGS = -std=c99 -fno-strict-aliasing | ||||
LANGXXFLAGS = -fno-strict-aliasing | LANGXXFLAGS = -fno-strict-aliasing | ||||
GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC | GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC | ||||
OFLAGS = -O3 | |||||
OFLAGS ?= -O3 | |||||
TODAY = $(shell date "+%Y-%m-%d") | TODAY = $(shell date "+%Y-%m-%d") | ||||
@@ -173,10 +173,10 @@ public: | |||||
} | } | ||||
/** Read data to a buffer. */ | /** Read data to a buffer. */ | ||||
inline void read(Buffer &buffer) { spongerng_next(sp,buffer.data(),buffer.size()); } | |||||
inline void read(Buffer &buffer) NOEXCEPT { spongerng_next(sp,buffer.data(),buffer.size()); } | |||||
/** Read data to a buffer. */ | /** Read data to a buffer. */ | ||||
inline void read(TmpBuffer buffer) { read((Buffer &)buffer); } | |||||
inline void read(TmpBuffer buffer) NOEXCEPT { read((Buffer &)buffer); } | |||||
/** Read data to a C++ string | /** Read data to a C++ string | ||||
* @warning TODO Future versions of this function may throw RngException if a | * @warning TODO Future versions of this function may throw RngException if a | ||||
@@ -192,19 +192,14 @@ private: | |||||
}; | }; | ||||
/**@cond internal*/ | /**@cond internal*/ | ||||
/* FIXME: multiple sizes */ | |||||
EcGroup<448>::Scalar::Scalar(SpongeRng &rng) { | |||||
*this = rng.read(SER_BYTES); | |||||
template<GroupId g> EcGroup<g>::Scalar::Scalar(SpongeRng &rng) NOEXCEPT { | |||||
*this = rng.read(EcGroup<g>::Scalar::SER_BYTES); | |||||
} | } | ||||
EcGroup<448>::Point::Point(SpongeRng &rng, bool uniform) { | |||||
template<GroupId g> EcGroup<g>::Point::Point(SpongeRng &rng, bool uniform) NOEXCEPT { | |||||
SecureBuffer buffer((uniform ? 2 : 1) * HASH_BYTES); | SecureBuffer buffer((uniform ? 2 : 1) * HASH_BYTES); | ||||
rng.read(buffer); | rng.read(buffer); | ||||
if (uniform) { | |||||
decaf_448_point_from_hash_uniform(p,buffer); | |||||
} else { | |||||
decaf_448_point_from_hash_nonuniform(p,buffer); | |||||
} | |||||
set_to_hash(buffer); | |||||
} | } | ||||
/**@endcond*/ | /**@endcond*/ | ||||
@@ -47,7 +47,7 @@ typedef typename decaf::EcGroup<GROUP>::Point Point; | |||||
typedef typename decaf::EcGroup<GROUP>::Precomputed Precomputed; | typedef typename decaf::EcGroup<GROUP>::Precomputed Precomputed; | ||||
static void print(const char *name, const Scalar &x) { | static void print(const char *name, const Scalar &x) { | ||||
unsigned char buffer[DECAF_448_SCALAR_BYTES]; | |||||
unsigned char buffer[Scalar::SER_BYTES]; | |||||
x.encode(buffer); | x.encode(buffer); | ||||
printf(" %s = 0x", name); | printf(" %s = 0x", name); | ||||
for (int i=sizeof(buffer)-1; i>=0; i--) { | for (int i=sizeof(buffer)-1; i>=0; i--) { | ||||
@@ -57,7 +57,7 @@ static void print(const char *name, const Scalar &x) { | |||||
} | } | ||||
static void print(const char *name, const Point &x) { | static void print(const char *name, const Point &x) { | ||||
unsigned char buffer[DECAF_448_SER_BYTES]; | |||||
unsigned char buffer[Point::SER_BYTES]; | |||||
x.encode(buffer); | x.encode(buffer); | ||||
printf(" %s = 0x", name); | printf(" %s = 0x", name); | ||||
for (int i=sizeof(buffer)-1; i>=0; i--) { | for (int i=sizeof(buffer)-1; i>=0; i--) { | ||||
@@ -175,6 +175,7 @@ static void test_ec() { | |||||
point_check(test,p,q,r,0,0,p,Point((decaf::SecureBuffer)p),"round-trip"); | point_check(test,p,q,r,0,0,p,Point((decaf::SecureBuffer)p),"round-trip"); | ||||
point_check(test,p,q,r,0,0,p+q,q+p,"commute add"); | point_check(test,p,q,r,0,0,p+q,q+p,"commute add"); | ||||
point_check(test,p,q,r,0,0,p+(q+r),(p+q)+r,"assoc add"); | point_check(test,p,q,r,0,0,p+(q+r),(p+q)+r,"assoc add"); | ||||
point_check(test,p,q,r,0,0,p.times_two(),p+p,"dbl add"); | |||||
if (i%10) continue; | if (i%10) continue; | ||||
point_check(test,p,q,r,x,0,x*(p+q),x*p+x*q,"distr mul"); | point_check(test,p,q,r,x,0,x*(p+q),x*p+x*q,"distr mul"); | ||||