Commit 9f1cc0e2 authored by Mike Hamburg's avatar Mike Hamburg

some more ct tests; serializeInto -> serialize_into. still need more ct...

some more ct tests; serializeInto -> serialize_into.  still need more ct tests, unification of snake vs camel case
parent 3d0c6a6c
......@@ -277,17 +277,17 @@ doc: Doxyfile $(BUILD_OBJ)/timestamp $(HEADERS)
TODO_TYPES ?= HACK TODO FIXME BUG XXX PERF FUTURE REMOVE MAGIC UNIFY
TODO_LOCATIONS ?= src test Makefile Doxyfile
todo::
@(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep --color=auto -w \
@(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep --color=auto -w \
`echo $(TODO_TYPES) | tr ' ' '|'`
@echo '============================='
@(for i in $(TODO_TYPES); do \
(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i > /dev/null || continue; \
(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep -w $$i > /dev/null || continue; \
/bin/echo -n $$i' ' | head -c 10; \
(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i| wc -l; \
(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep -w $$i| wc -l; \
done)
@echo '============================='
@echo -n 'Total '
@(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w \
@(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep -w \
`echo $(TODO_TYPES) | tr ' ' '|'` | wc -l
bench: $(BUILD_IBIN)/bench
......
......@@ -63,7 +63,7 @@ public:
inline explicit PublicKey(const NOINIT&) NOEXCEPT { }
/** Serialize into a buffer. */
inline void serializeInto(unsigned char *x) const NOEXCEPT {
inline void serialize_into(unsigned char *x) const NOEXCEPT {
memcpy(x,wrapped,sizeof(wrapped));
}
......@@ -133,7 +133,7 @@ public:
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
/** Serialize into a buffer. */
inline void serializeInto(unsigned char *x) const NOEXCEPT {
inline void serialize_into(unsigned char *x) const NOEXCEPT {
memcpy(x,wrapped,sizeof(wrapped));
}
......
......@@ -105,7 +105,7 @@ public:
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
/** Serializable instance */
inline void serializeInto(unsigned char *buffer) const NOEXCEPT {
inline void serialize_into(unsigned char *buffer) const NOEXCEPT {
%(c_ns)s_scalar_encode(buffer, s);
}
......@@ -163,7 +163,8 @@ public:
/** Negate */
inline Scalar operator- () const NOEXCEPT { Scalar r((NOINIT())); %(c_ns)s_scalar_sub(r.s,%(c_ns)s_scalar_zero,s); return r; }
/** Invert with Fermat's Little Theorem (slow!). If *this == 0, return 0. */
/** Invert with Fermat's Little Theorem (slow!). If *this == 0,
* throw CryptoException. */
inline Scalar inverse() const throw(CryptoException) {
Scalar r;
if (DECAF_SUCCESS != %(c_ns)s_scalar_invert(r.s,s)) {
......@@ -172,6 +173,13 @@ public:
return r;
}
/** Invert with Fermat's Little Theorem (slow!). If *this == 0, set r=0
* and return DECAF_FAILURE. */
inline decaf_error_t __attribute__((warn_unused_result))
inverse_noexcept(Scalar &r) const NOEXCEPT {
return %(c_ns)s_scalar_invert(r.s,s);
}
/** Divide by inverting q. If q == 0, return 0. */
inline Scalar operator/ (const Scalar &q) const throw(CryptoException) { return *this * q.inverse(); }
......@@ -319,7 +327,7 @@ public:
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
/** Serializable instance */
inline void serializeInto(unsigned char *buffer) const NOEXCEPT {
inline void serialize_into(unsigned char *buffer) const NOEXCEPT {
%(c_ns)s_point_encode(buffer, p);
}
......
......@@ -88,14 +88,14 @@ public:
inline size_t serSize() const NOEXCEPT { return static_cast<const Base*>(this)->serSize(); }
/** @brief Serialize this object into a buffer */
inline void serializeInto(unsigned char *buf) const NOEXCEPT {
static_cast<const Base*>(this)->serializeInto(buf);
inline void serialize_into(unsigned char *buf) const NOEXCEPT {
static_cast<const Base*>(this)->serialize_into(buf);
}
/** @brief Serialize this object into a SecureBuffer and return it */
inline SecureBuffer serialize() const throw(std::bad_alloc) {
SecureBuffer out(serSize());
serializeInto(out.data());
serialize_into(out.data());
return out;
}
......
......@@ -18,7 +18,7 @@
using namespace decaf;
static const long NTESTS = 1;
static const long NTESTS = 10;
const char *undef_str = "Valgrind thinks this string is undefined.";
const Block undef_block(undef_str);
......@@ -44,10 +44,10 @@ static void test_arithmetic() {
(void)(x+y);
(void)(x-y);
(void)(x*y);
//(void)(x/y); // TODO: Fails due to zero check, but needs to be tested anyway.
ignore(x.inverse_noexcept(y));
(void)(x==y);
(void)(z=y);
x.serializeInto(ser);
x.serialize_into(ser);
x = y;
}
}
......@@ -73,7 +73,7 @@ static void test_ec() {
Scalar y(rng),z(rng);
Point p(rng),q(rng),r;
p.serializeInto(ser);
p.serialize_into(ser);
ignore(Group::Point::decode(p,FixedBlock<Group::Point::SER_BYTES>(ser)));
(void)(p*y);
(void)(p+q);
......@@ -91,10 +91,20 @@ static void test_ec() {
}
static void test_crypto() {
/* TODO */
SpongeRng rng(Block("test_crypto"));
rng.stir(undef_block);
for (int i=0; i<NTESTS; i++) {
PrivateKey<Group> sk1(rng);
PrivateKey<Group> sk2(rng);
SecureBuffer sig = sk1.sign(undef_block);
//sk.pub().verify(undef_block,sig); would fail. FUTURE: ct version of this?
/* TODO: shared_secret nothrow? have to test shared_secret... */
}
}
}; // template<GroupId GROUP>
}; /* template<GroupId GROUP> */
int main(int argc, char **argv) {
(void) argc; (void) argv;
......
......@@ -51,7 +51,7 @@ typedef typename Group::Precomputed Precomputed;
static void print(const char *name, const Scalar &x) {
unsigned char buffer[Scalar::SER_BYTES];
x.serializeInto(buffer);
x.serialize_into(buffer);
printf(" %s = 0x", name);
for (int i=sizeof(buffer)-1; i>=0; i--) {
printf("%02x", buffer[i]);
......@@ -69,7 +69,7 @@ static void hexprint(const char *name, const SecureBuffer &buffer) {
static void print(const char *name, const Point &x) {
unsigned char buffer[Point::SER_BYTES];
x.serializeInto(buffer);
x.serialize_into(buffer);
printf(" %s = 0x", name);
for (int i=Point::SER_BYTES-1; i>=0; i--) {
printf("%02x", buffer[i]);
......@@ -347,7 +347,7 @@ static void test_crypto() {
}
}
}; // template<GroupId GROUP>
}; /* template<GroupId GROUP> */
int main(int argc, char **argv) {
(void) argc; (void) argv;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment