Browse Source

trying to templatize

master
Michael Hamburg 9 years ago
parent
commit
fc3be89e4c
4 changed files with 646 additions and 447 deletions
  1. +1
    -1
      Makefile
  2. +636
    -433
      include/decaf.hxx
  3. +6
    -11
      include/shake.hxx
  4. +3
    -2
      test/test_decaf.cxx

+ 1
- 1
Makefile View File

@@ -35,7 +35,7 @@ INCFLAGS = -Isrc/include -Iinclude -Isrc/$(FIELD) -Isrc/$(FIELD)/$(ARCH)
LANGFLAGS = -std=c99 -fno-strict-aliasing
LANGXXFLAGS = -fno-strict-aliasing
GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC
OFLAGS = -O3
OFLAGS ?= -O3

TODAY = $(shell date "+%Y-%m-%d")



+ 636
- 433
include/decaf.hxx
File diff suppressed because it is too large
View File


+ 6
- 11
include/shake.hxx View File

@@ -173,10 +173,10 @@ public:
}
/** 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. */
inline void read(TmpBuffer buffer) { read((Buffer &)buffer); }
inline void read(TmpBuffer buffer) NOEXCEPT { read((Buffer &)buffer); }
/** Read data to a C++ string
* @warning TODO Future versions of this function may throw RngException if a
@@ -192,19 +192,14 @@ private:
};

/**@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);
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*/



+ 3
- 2
test/test_decaf.cxx View File

@@ -47,7 +47,7 @@ typedef typename decaf::EcGroup<GROUP>::Point Point;
typedef typename decaf::EcGroup<GROUP>::Precomputed Precomputed;

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);
printf(" %s = 0x", name);
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) {
unsigned char buffer[DECAF_448_SER_BYTES];
unsigned char buffer[Point::SER_BYTES];
x.encode(buffer);
printf(" %s = 0x", name);
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+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.times_two(),p+p,"dbl add");
if (i%10) continue;
point_check(test,p,q,r,x,0,x*(p+q),x*p+x*q,"distr mul");


Loading…
Cancel
Save