Commit f1df5e47 authored by Michael Hamburg's avatar Michael Hamburg

lowerCamelCase -> snake_case. Put decaf_ in front of all (most?) identifiers,...

lowerCamelCase -> snake_case.  Put decaf_ in front of all (most?) identifiers, except for SHAKE which is being removed before 1.0 release (for future refactoring)
parent 85fafd2d
......@@ -62,7 +62,7 @@ public:
}
/** Serialization size. */
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
inline size_t ser_size() const NOEXCEPT { return SER_BYTES; }
/** Verify a message */
inline void verify(
......@@ -132,7 +132,7 @@ public:
}
/** Serialization size. */
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
inline size_t ser_size() const NOEXCEPT { return SER_BYTES; }
/** Serialize into a buffer. */
inline void serialize_into(unsigned char *x) const NOEXCEPT {
......@@ -152,7 +152,7 @@ public:
}
/** Derive a shared secret */
inline SecureBuffer sharedSecret(
inline SecureBuffer shared_secret(
const PublicKey<$(cxx_ns)> &pub,
size_t bytes,
bool me_first
......@@ -166,7 +166,7 @@ public:
/** Derive a shared secret */
inline decaf_error_t __attribute__((warn_unused_result))
sharedSecretNoexcept(
shared_secret_noexcept(
Buffer ret,
const PublicKey<$(cxx_ns)> &pub,
bool me_first
......
......@@ -1364,11 +1364,11 @@ struct smvt_control {
};
static int recode_wnaf (
struct smvt_control *control, /* [nbits/(tableBits+1) + 3] */
struct smvt_control *control, /* [nbits/(table_bits+1) + 3] */
const scalar_t scalar,
unsigned int tableBits
unsigned int table_bits
) {
unsigned int table_size = SCALAR_BITS/(tableBits+1) + 3;
unsigned int table_size = SCALAR_BITS/(table_bits+1) + 3;
int position = table_size - 1; /* at the end */
/* place the end marker */
......@@ -1382,7 +1382,7 @@ static int recode_wnaf (
*/
uint64_t current = scalar->limb[0] & 0xFFFF;
uint32_t mask = (1<<(tableBits+1))-1;
uint32_t mask = (1<<(table_bits+1))-1;
unsigned int w;
const unsigned int B_OVER_16 = sizeof(scalar->limb[0]) / 2;
......@@ -1396,7 +1396,7 @@ static int recode_wnaf (
assert(position >= 0);
uint32_t pos = __builtin_ctz((uint32_t)current), odd = (uint32_t)current >> pos;
int32_t delta = odd & mask;
if (odd & 1<<(tableBits+1)) delta -= (1<<(tableBits+1));
if (odd & 1<<(table_bits+1)) delta -= (1<<(table_bits+1));
current -= delta << pos;
control[position].power = pos + 16*(w-1);
control[position].addend = delta;
......
......@@ -538,12 +538,12 @@ void $(c_ns)_scalar_cond_sel (
/**
* @brief Test that a point is valid, for debugging purposes.
*
* @param [in] toTest The point to test.
* @param [in] to_test The point to test.
* @retval DECAF_TRUE The point is valid.
* @retval DECAF_FALSE The point is invalid.
*/
decaf_bool_t $(c_ns)_point_valid (
const $(c_ns)_point_t toTest
const $(c_ns)_point_t to_test
) API_VIS WARN_UNUSED NONNULL NOINLINE;
/**
......
......@@ -104,7 +104,7 @@ public:
inline Scalar(const Block &buffer) NOEXCEPT { *this = buffer; }
/** Serializable instance */
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
inline size_t ser_size() const NOEXCEPT { return SER_BYTES; }
/** Serializable instance */
inline void serialize_into(unsigned char *buffer) const NOEXCEPT {
......@@ -378,7 +378,7 @@ public:
}
/** Serializable instance */
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
inline size_t ser_size() const NOEXCEPT { return SER_BYTES; }
/** Serializable instance */
inline void serialize_into(unsigned char *buffer) const NOEXCEPT {
......@@ -559,7 +559,7 @@ public:
* initializer for points which makes this equal to the identity.
*/
inline Precomputed (
const Precomputed_U &yours = *defaultValue()
const Precomputed_U &yours = *default_value()
) NOEXCEPT : OwnedOrUnowned<Precomputed,Precomputed_U>(yours) {}
......@@ -617,7 +617,7 @@ public:
friend class OwnedOrUnowned<Precomputed,Precomputed_U>;
static inline size_t size() NOEXCEPT { return $(c_ns)_sizeof_precomputed_s; }
static inline size_t alignment() NOEXCEPT { return $(c_ns)_alignof_precomputed_s; }
static inline const Precomputed_U * defaultValue() NOEXCEPT { return $(c_ns)_precomputed_base; }
static inline const Precomputed_U * default_value() NOEXCEPT { return $(c_ns)_precomputed_base; }
/** @endcond */
};
......
......@@ -59,10 +59,10 @@ int main(int argc, char **argv) {
if (ret || !pre) return 1;
API_NS(precompute)(pre, real_point_base);
struct niels_s *preWnaf;
ret = posix_memalign((void**)&preWnaf, API_NS(alignof_precomputed_s), API_NS(sizeof_precomputed_wnafs));
if (ret || !preWnaf) return 1;
API_NS(precompute_wnafs)(preWnaf, real_point_base);
struct niels_s *pre_wnaf;
ret = posix_memalign((void**)&pre_wnaf, API_NS(alignof_precomputed_s), API_NS(sizeof_precomputed_wnafs));
if (ret || !pre_wnaf) return 1;
API_NS(precompute_wnafs)(pre_wnaf, real_point_base);
const gf_s *output;
unsigned i;
......@@ -91,7 +91,7 @@ int main(int argc, char **argv) {
}
printf("\n};\n");
output = (const gf_s *)preWnaf;
output = (const gf_s *)pre_wnaf;
printf("const gf API_NS(precomputed_wnaf_as_fe)[%d]\n",
(int)(API_NS(sizeof_precomputed_wnafs) / sizeof(gf)));
printf("__attribute__((aligned(%d),visibility(\"hidden\"))) = {\n ", (int)API_NS(alignof_precomputed_s));
......
......@@ -12,12 +12,12 @@
#define API_NAME "$(c_ns)"
#define API_NS(_id) $(c_ns)_##_id
#define hash_ctx_t $(eddsa_hash)_ctx_t
#define hash_init $(eddsa_hash)_init
#define hash_update $(eddsa_hash)_update
#define hash_final $(eddsa_hash)_final
#define hash_destroy $(eddsa_hash)_destroy
#define hash_hash $(eddsa_hash)_hash
#define hash_ctx_t decaf_$(eddsa_hash)_ctx_t
#define hash_init decaf_$(eddsa_hash)_init
#define hash_update decaf_$(eddsa_hash)_update
#define hash_final decaf_$(eddsa_hash)_final
#define hash_destroy decaf_$(eddsa_hash)_destroy
#define hash_hash decaf_$(eddsa_hash)_hash
#define SUPPORTS_CONTEXTS $(C_NS)_EDDSA_SUPPORTS_CONTEXTS
#define EDDSA_USE_SIGMA_ISOGENY $(eddsa_sigma_iso)
......@@ -47,9 +47,9 @@ static void hash_init_with_dom(
hash_init(hash);
#if SUPPORTS_CONTEXTS
const char *domS = "$(eddsa_dom)";
const char *dom_s = "$(eddsa_dom)";
const uint8_t dom[2] = {1+word_is_zero(prehashed), context_len};
hash_update(hash,(const unsigned char *)domS, strlen(domS));
hash_update(hash,(const unsigned char *)dom_s, strlen(dom_s));
hash_update(hash,dom,2);
hash_update(hash,context,context_len);
#else
......
......@@ -145,7 +145,7 @@ public:
}
/** Serialization size. */
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
inline size_t ser_size() const NOEXCEPT { return SER_BYTES; }
/** Serialize into a buffer. */
inline void serialize_into(unsigned char *x) const NOEXCEPT {
......@@ -258,7 +258,7 @@ public:
/** Serialization size. */
inline size_t serSize() const NOEXCEPT { return SER_BYTES; }
inline size_t ser_size() const NOEXCEPT { return SER_BYTES; }
/** Serialize into a buffer. */
inline void serialize_into(unsigned char *x) const NOEXCEPT {
......
......@@ -85,7 +85,7 @@ inline bool memeq(const std::vector<T,U> &a, const std::vector<V,W> &b) {
template<class Base> class Serializable {
public:
/** @brief Return the number of bytes needed to serialize this object */
inline size_t serSize() const NOEXCEPT { return static_cast<const Base*>(this)->serSize(); }
inline size_t ser_size() const NOEXCEPT { return static_cast<const Base*>(this)->ser_size(); }
/** @brief Serialize this object into a buffer */
inline void serialize_into(unsigned char *buf) const NOEXCEPT {
......@@ -94,7 +94,7 @@ public:
/** @brief Serialize this object into a SecureBuffer and return it */
inline SecureBuffer serialize() const throw(std::bad_alloc) {
SecureBuffer out(serSize());
SecureBuffer out(ser_size());
serialize_into(out.data());
return out;
}
......@@ -396,32 +396,32 @@ protected:
Wrapped *mine;
const Wrapped *yours;
} ours;
bool isMine;
bool is_mine;
inline void clear() NOEXCEPT {
if (isMine) {
if (is_mine) {
really_bzero(ours.mine, T::size());
free(ours.mine);
ours.yours = T::defaultValue();
isMine = false;
ours.yours = T::default_value();
is_mine = false;
}
}
inline void alloc() throw(std::bad_alloc) {
if (isMine) return;
if (is_mine) return;
int ret = posix_memalign((void**)&ours.mine, T::alignment(), T::size());
if (ret || !ours.mine) {
isMine = false;
is_mine = false;
throw std::bad_alloc();
}
isMine = true;
is_mine = true;
}
inline const Wrapped *get() const NOEXCEPT { return isMine ? ours.mine : ours.yours; }
inline const Wrapped *get() const NOEXCEPT { return is_mine ? ours.mine : ours.yours; }
inline OwnedOrUnowned(
const Wrapped &yours = *T::defaultValue()
const Wrapped &yours = *T::default_value()
) NOEXCEPT {
ours.yours = &yours;
isMine = false;
is_mine = false;
}
/**
......@@ -429,14 +429,14 @@ protected:
*/
inline T &operator=(const OwnedOrUnowned &it) throw(std::bad_alloc) {
if (this == &it) return *(T*)this;
if (it.isMine) {
if (it.is_mine) {
alloc();
memcpy(ours.mine,it.ours.mine,T::size());
} else {
clear();
ours.yours = it.ours.yours;
}
isMine = it.isMine;
is_mine = it.is_mine;
return *(T*)this;
}
......@@ -445,9 +445,9 @@ protected:
if (this == &it) return *(T*)this;
clear();
ours = it.ours;
isMine = it.isMine;
it.isMine = false;
it.ours.yours = T::defaultValue;
is_mine = it.is_mine;
it.is_mine = false;
it.ours.yours = T::default_value;
return *this;
}
#endif
......
......@@ -19,31 +19,31 @@ extern "C" {
#endif
typedef struct sha512_ctx_s {
typedef struct decaf_sha512_ctx_s {
uint64_t state[8];
uint8_t block[128];
uint64_t bytesProcessed;
} sha512_ctx_s, sha512_ctx_t[1];
uint64_t bytes_processed;
} decaf_sha512_ctx_s, decaf_sha512_ctx_t[1];
void sha512_init(sha512_ctx_t ctx) NONNULL API_VIS;
void sha512_update(sha512_ctx_t ctx, const uint8_t *message, size_t length) NONNULL API_VIS;
void sha512_final(sha512_ctx_t ctx, uint8_t *out, size_t length) NONNULL API_VIS;
void decaf_sha512_init(decaf_sha512_ctx_t ctx) NONNULL API_VIS;
void decaf_sha512_update(decaf_sha512_ctx_t ctx, const uint8_t *message, size_t length) NONNULL API_VIS;
void decaf_sha512_final(decaf_sha512_ctx_t ctx, uint8_t *out, size_t length) NONNULL API_VIS;
static inline void sha512_destroy(sha512_ctx_t ctx) {
static inline void decaf_sha512_destroy(decaf_sha512_ctx_t ctx) {
decaf_bzero(ctx,sizeof(*ctx));
}
static inline void sha512_hash(
static inline void decaf_sha512_hash(
uint8_t *output,
size_t output_len,
const uint8_t *message,
size_t message_len
) {
sha512_ctx_t ctx;
sha512_init(ctx);
sha512_update(ctx,message,message_len);
sha512_final(ctx,output,output_len);
sha512_destroy(ctx);
decaf_sha512_ctx_t ctx;
decaf_sha512_init(ctx);
decaf_sha512_update(ctx,message,message_len);
decaf_sha512_final(ctx,output,output_len);
decaf_sha512_destroy(ctx);
}
#ifdef __cplusplus
......
/**
* @file decaf/sha512.hxx
* @file decaf/decaf_sha512.hxx
* @copyright
* Based on public domain code by Dan Bernstein \n
* Copyright (c) 2015 Cryptography Research, Inc. \n
......@@ -30,7 +30,7 @@ class SHA512 {
protected:
/** @cond internal */
/** The C-wrapper sponge state */
sha512_ctx_t sha;
decaf_sha512_ctx_t sha;
public:
......@@ -44,10 +44,10 @@ public:
static const size_t DEFAULT_OUTPUT_BYTES = OUTPUT_BYTES;
/** Constructor */
inline SHA512() NOEXCEPT { sha512_init(sha); }
inline SHA512() NOEXCEPT { decaf_sha512_init(sha); }
/** Add more data to running hash */
inline void update(const uint8_t *__restrict__ in, size_t len) NOEXCEPT { sha512_update(sha,in,len); }
inline void update(const uint8_t *__restrict__ in, size_t len) NOEXCEPT { decaf_sha512_update(sha,in,len); }
/** Add more data to running hash, C++ version. */
inline void update(const Block &s) NOEXCEPT { update(s.data(),s.size()); }
......@@ -61,17 +61,17 @@ public:
/** @brief Output bytes from the SHA context, and resets it. */
inline void final(Buffer b) throw(LengthException) {
if (b.size() > OUTPUT_BYTES) throw LengthException();
sha512_final(sha,b.data(),b.size());
decaf_sha512_final(sha,b.data(),b.size());
}
/** Resets the SHA context */
inline void reset() NOEXCEPT { sha512_init(sha); }
inline void reset() NOEXCEPT { decaf_sha512_init(sha); }
/** @brief Output bytes from the sponge. */
inline SecureBuffer final(size_t len = OUTPUT_BYTES) throw(LengthException) {
if (len > OUTPUT_BYTES) throw LengthException();
SecureBuffer buffer(len);
sha512_final(sha,buffer.data(),len);
decaf_sha512_final(sha,buffer.data(),len);
return buffer;
}
......@@ -88,12 +88,12 @@ public:
) throw(LengthException, std::bad_alloc) {
if (outlen > OUTPUT_BYTES) throw LengthException();
SecureBuffer buffer(outlen);
sha512_hash(buffer.data(),outlen,message.data(),message.size());
decaf_sha512_hash(buffer.data(),outlen,message.data(),message.size());
return buffer;
}
/** Destructor zeroizes state */
inline ~SHA512() NOEXCEPT { sha512_destroy(sha); }
inline ~SHA512() NOEXCEPT { decaf_sha512_destroy(sha); }
};
} /* namespace decaf */
......
This diff is collapsed.
/**
* @file decaf/shake.hxx
* @file decaf/decaf_shake.hxx
* @copyright
* Based on CC0 code by David Leon Gil, 2015 \n
* Copyright (c) 2015 Cryptography Research, Inc. \n
......@@ -35,18 +35,18 @@ class KeccakHash {
protected:
/** @cond internal */
/** The C-wrapper sponge state */
keccak_sponge_t sp;
decaf_keccak_sponge_t sp;
/** Initialize from parameters */
inline KeccakHash(const kparams_s *params) NOEXCEPT { sponge_init(sp, params); }
inline KeccakHash(const decaf_kparams_s *params) NOEXCEPT { decaf_sponge_init(sp, params); }
/** @endcond */
public:
/** Add more data to running hash */
inline void update(const uint8_t *__restrict__ in, size_t len) NOEXCEPT { sha3_update(sp,in,len); }
inline void update(const uint8_t *__restrict__ in, size_t len) NOEXCEPT { decaf_sha3_update(sp,in,len); }
/** Add more data to running hash, C++ version. */
inline void update(const Block &s) NOEXCEPT { sha3_update(sp,s.data(),s.size()); }
inline void update(const Block &s) NOEXCEPT { decaf_sha3_update(sp,s.data(),s.size()); }
/** Add more data, stream version. */
inline KeccakHash &operator<<(const Block &s) NOEXCEPT { update(s); return *this; }
......@@ -58,7 +58,7 @@ public:
inline SecureBuffer output(size_t len) throw(std::bad_alloc, LengthException) {
if (len > max_output_size()) throw LengthException();
SecureBuffer buffer(len);
sha3_output(sp,buffer.data(),len);
decaf_sha3_output(sp,buffer.data(),len);
return buffer;
}
......@@ -66,7 +66,7 @@ public:
inline SecureBuffer final(size_t len) throw(std::bad_alloc, LengthException) {
if (len > max_output_size()) throw LengthException();
SecureBuffer buffer(len);
sha3_final(sp,buffer.data(),len);
decaf_sha3_final(sp,buffer.data(),len);
return buffer;
}
......@@ -75,22 +75,22 @@ public:
* @todo make this throw exceptions.
*/
inline void output(Buffer b) throw(LengthException) {
sha3_output(sp,b.data(),b.size());
decaf_sha3_output(sp,b.data(),b.size());
}
/** @brief Output bytes from the sponge and reinitialize it. */
inline void final(Buffer b) throw(LengthException) {
sha3_final(sp,b.data(),b.size());
decaf_sha3_final(sp,b.data(),b.size());
}
/** @brief Return the sponge's default output size. */
inline size_t default_output_size() const NOEXCEPT {
return sponge_default_output_bytes(sp);
return decaf_sponge_default_output_bytes(sp);
}
/** @brief Return the sponge's maximum output size. */
inline size_t max_output_size() const NOEXCEPT {
return sponge_max_output_bytes(sp);
return decaf_sponge_max_output_bytes(sp);
}
/** Output the default number of bytes. */
......@@ -104,17 +104,17 @@ public:
}
/** Reset the hash to the empty string */
inline void reset() NOEXCEPT { sha3_reset(sp); }
inline void reset() NOEXCEPT { decaf_sha3_reset(sp); }
/** Destructor zeroizes state */
inline ~KeccakHash() NOEXCEPT { sponge_destroy(sp); }
inline ~KeccakHash() NOEXCEPT { decaf_sponge_destroy(sp); }
};
/** Fixed-output-length SHA3 */
template<int bits> class SHA3 : public KeccakHash {
private:
/** Get the parameter template block for this hash */
static inline const struct kparams_s *get_params();
static inline const struct decaf_kparams_s *get_params();
public:
/** Number of bytes of output */
......@@ -142,7 +142,7 @@ template<int bits>
class SHAKE : public KeccakHash {
private:
/** Get the parameter template block for this hash */
static inline const struct kparams_s *get_params();
static inline const struct decaf_kparams_s *get_params();
public:
/** Number of bytes of output */
......@@ -165,12 +165,12 @@ public:
};
/** @cond internal */
template<> inline const struct kparams_s *SHAKE<128>::get_params() { return &SHAKE128_params_s; }
template<> inline const struct kparams_s *SHAKE<256>::get_params() { return &SHAKE256_params_s; }
template<> inline const struct kparams_s *SHA3<224>::get_params() { return &SHA3_224_params_s; }
template<> inline const struct kparams_s *SHA3<256>::get_params() { return &SHA3_256_params_s; }
template<> inline const struct kparams_s *SHA3<384>::get_params() { return &SHA3_384_params_s; }
template<> inline const struct kparams_s *SHA3<512>::get_params() { return &SHA3_512_params_s; }
template<> inline const struct decaf_kparams_s *SHAKE<128>::get_params() { return &DECAF_SHAKE128_params_s; }
template<> inline const struct decaf_kparams_s *SHAKE<256>::get_params() { return &DECAF_SHAKE256_params_s; }
template<> inline const struct decaf_kparams_s *SHA3<224>::get_params() { return &DECAF_SHA3_224_params_s; }
template<> inline const struct decaf_kparams_s *SHA3<256>::get_params() { return &DECAF_SHA3_256_params_s; }
template<> inline const struct decaf_kparams_s *SHA3<384>::get_params() { return &DECAF_SHA3_384_params_s; }
template<> inline const struct decaf_kparams_s *SHA3<512>::get_params() { return &DECAF_SHA3_512_params_s; }
/** @endcond */
} /* namespace decaf */
......
......@@ -20,15 +20,15 @@ extern "C" {
/** Keccak CSPRNG structure as struct. */
typedef struct {
keccak_sponge_t sponge; /**< Internal sponge object. */
} keccak_prng_s;
decaf_keccak_sponge_t sponge; /**< Internal sponge object. */
} decaf_keccak_prng_s;
/** Keccak CSPRNG structure as one-element array */
typedef keccak_prng_s keccak_prng_t[1];
typedef decaf_keccak_prng_s decaf_keccak_prng_t[1];
/** Initialize a sponge-based CSPRNG from a buffer. */
void spongerng_init_from_buffer (
keccak_prng_t prng, /**< [out] The PRNG object. */
void decaf_spongerng_init_from_buffer (
decaf_keccak_prng_t prng, /**< [out] The PRNG object. */
const uint8_t *__restrict__ in, /**< [in] The initialization data. */
size_t len, /**< [in] The length of the initialization data. */
int deterministic /**< [in] If zero, allow RNG to stir in nondeterministic data from RDRAND or RDTSC.*/
......@@ -40,8 +40,8 @@ void spongerng_init_from_buffer (
* @retval DECAF_FAILURE failure.
* @note On failure, errno can be used to determine the cause.
*/
decaf_error_t spongerng_init_from_file (
keccak_prng_t prng, /**< [out] The PRNG object. */
decaf_error_t decaf_spongerng_init_from_file (
decaf_keccak_prng_t prng, /**< [out] The PRNG object. */
const char *file, /**< [in] A name of a file containing initial data. */
size_t len, /**< [in] The length of the initial data. Must be positive. */
int deterministic /**< [in] If zero, allow RNG to stir in nondeterministic data from RDRAND or RDTSC. */
......@@ -53,36 +53,36 @@ decaf_error_t spongerng_init_from_file (
* @retval DECAF_FAILURE failure.
* @note On failure, errno can be used to determine the cause.
*/
decaf_error_t spongerng_init_from_dev_urandom (
keccak_prng_t prng /**< [out] sponge The sponge object. */
decaf_error_t decaf_spongerng_init_from_dev_urandom (
decaf_keccak_prng_t prng /**< [out] sponge The sponge object. */
) API_VIS WARN_UNUSED;
/** Output bytes from a sponge-based CSPRNG. */
void spongerng_next (
keccak_prng_t prng, /**< [inout] The PRNG object. */
void decaf_spongerng_next (
decaf_keccak_prng_t prng, /**< [inout] The PRNG object. */
uint8_t * __restrict__ out, /**< [out] Output buffer. */
size_t len /**< [in] Number of bytes to output. */
) API_VIS;
/** Stir entropy data into a sponge-based CSPRNG from a buffer. */
void spongerng_stir (
keccak_prng_t prng, /**< [out] The PRNG object. */
void decaf_spongerng_stir (
decaf_keccak_prng_t prng, /**< [out] The PRNG object. */
const uint8_t * __restrict__ in, /**< [in] The entropy data. */
size_t len /**< [in] The length of the initial data. */
) NONNULL API_VIS;
/** Securely destroy a sponge RNG object by overwriting it. */
static INLINE UNUSED void
spongerng_destroy (
keccak_prng_t doomed /**< [in] The object to destroy. */
decaf_spongerng_destroy (
decaf_keccak_prng_t doomed /**< [in] The object to destroy. */
);
/** @cond internal */
/***************************************/
/* Implementations of inline functions */
/***************************************/
void spongerng_destroy (keccak_prng_t doomed) {
sponge_destroy(doomed->sponge);
void decaf_spongerng_destroy (decaf_keccak_prng_t doomed) {
decaf_sponge_destroy(doomed->sponge);
}
/** @endcond */ /* internal */
......
......@@ -38,7 +38,7 @@ namespace decaf {
class SpongeRng : public Rng {
private:
/** C wrapped object */
keccak_prng_t sp;
decaf_keccak_prng_t sp;
public:
/** Deterministic flag.
......@@ -61,13 +61,13 @@ public:
/** Initialize, deterministically by default, from block */
inline SpongeRng( const Block &in, Deterministic det ) {
spongerng_init_from_buffer(sp,in.data(),in.size(),(int)det);
decaf_spongerng_init_from_buffer(sp,in.data(),in.size(),(int)det);
}
/** Initialize, non-deterministically by default, from C/C++ filename */
inline SpongeRng( const std::string &in = "/dev/urandom", size_t len = 32, Deterministic det = RANDOM )
throw(RngException) {
decaf_error_t ret = spongerng_init_from_file(sp,in.c_str(),len,det);
decaf_error_t ret = decaf_spongerng_init_from_file(sp,in.c_str(),len,det);
if (!decaf_successful(ret)) {
throw RngException(errno, "Couldn't load from file");
}
......@@ -75,11 +75,11 @@ public:
/** Stir in new data */
inline void stir( const Block &data ) NOEXCEPT {
spongerng_stir(sp,data.data(),data.size());
decaf_spongerng_stir(sp,data.data(),data.size());
}
/** Securely destroy by overwriting state. */
inline ~SpongeRng() NOEXCEPT { spongerng_destroy(sp); }
inline ~SpongeRng() NOEXCEPT { decaf_spongerng_destroy(sp); }
using Rng::read;
......@@ -88,7 +88,7 @@ public:
#if __cplusplus >= 201103L
final
#endif
{ spongerng_next(sp,buffer.data(),buffer.size()); }
{ decaf_spongerng_next(sp,buffer.data(),buffer.size()); }
private:
SpongeRng(const SpongeRng &) DELETE;
......
......@@ -19,29 +19,29 @@ extern "C" {
/** Keccak STROBE structure as struct. */
typedef struct {
keccak_sponge_t sponge; /**< Internal sponge object. */
decaf_keccak_sponge_t sponge; /**< Internal sponge object. */
} keccak_strobe_s;
/** Keccak STROBE structure as one-element array */
typedef keccak_strobe_s keccak_strobe_t[1];
/** STROBE parameters, 128-bit estimated security for hashing and encryption */
extern const struct kparams_s STROBE_128 API_VIS;
extern const struct decaf_kparams_s STROBE_128 API_VIS;
/** STROBE parameters, 256-bit estimated security for hashing and encryption */
extern const struct kparams_s STROBE_256 API_VIS;
extern const struct decaf_kparams_s STROBE_256 API_VIS;
/** STROBE parameters, 128-bit estimated security for encryption only (not hashing) */
extern const struct kparams_s STROBE_KEYED_128 API_VIS;
extern const struct decaf_kparams_s STROBE_KEYED_128 API_VIS;
/** STROBE parameters, 256-bit estimated security for encryption only (not hashing) */
extern const struct kparams_s STROBE_KEYED_256 API_VIS;
extern const struct decaf_kparams_s STROBE_KEYED_256 API_VIS;
/** Initialize Strobe protocol context. */
void strobe_init (
keccak_strobe_t strobe, /**< [out] The uninitialized strobe object. */
const struct kparams_s *params, /**< [in] Parameter set descriptor. */
const struct decaf_kparams_s *params, /**< [in] Parameter set descriptor. */
const char *proto, /**< [in] Unique identifier for the protocol. TODO: define namespaces for this */
uint8_t am_client /**< [in] Nonzero if this party. */
) NONNULL API_VIS;
......@@ -158,7 +158,7 @@ static inline void NONNULL strobe_prng (
/** Respecify Strobe protocol object's crypto. */
void strobe_respec (
keccak_strobe_t strobe, /**< [inout] The initialized strobe context. */
const struct kparams_s *params /**< [in] Strobe parameter descriptor. */
const struct decaf_kparams_s *params /**< [in] Strobe parameter descriptor. */
) NONNULL API_VIS;
/** Securely destroy a STROBE object by overwriting it. */
......@@ -329,7 +329,7 @@ void strobe_prng(keccak_strobe_t strobe, unsigned char *out, uint16_t len) {
}
void strobe_destroy (keccak_strobe_t doomed) {
sponge_destroy(doomed->sponge);
decaf_sponge_destroy(doomed->sponge);
}
/** @endcond */ /* internal */
......
......@@ -53,7 +53,7 @@ public:
inline Strobe (
const char *description, /**< Description of this protocol. */
client_or_server whoami, /**< Am I client or server? */
const kparams_s &params = STROBE_256 /**< Strength parameters */
const decaf_kparams_s &params = STROBE_256 /**< Strength parameters */
) NOEXCEPT {
strobe_init(wrapped, &params, description, whoami == CLIENT);
keyed = false;
......@@ -222,7 +222,7 @@ public:
/** Change specs, perhaps to a faster spec that takes advantage of being keyed.
* @warning Experimental.
*/
inline void respec(const kparams_s &params) throw(ProtocolException) {
inline void respec(const decaf_kparams_s &params) throw(ProtocolException) {
if (!keyed) throw(ProtocolException());