44#define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
61class twofish_thread :
public ethread
64 twofish_thread(test_twofish &parent) :
ethread(), _parent(parent) {}
70 test_twofish &_parent;
88 friend class twofish_thread;
91int test_twofish::execute()
95 LOG(
"starting twofish test...");
102 _threads.add_thread(
new twofish_thread(*
this),
true,
NULL_POINTER);
106 LOG(
"started all threads...");
109 while (_threads.threads()) {
111 LOG(
"periodic debris cleaning.");
113 _threads.clean_debris();
118 LOG(
a_sprintf(
"duration for %d keys and encrypt/decrypt=%d ms,",
120 LOG(
a_sprintf(
"that comes to %d ms per cycle.",
int(
double(duration
123 return final_report();
128#undef UNIT_BASE_THIS_OBJECT
129#define UNIT_BASE_THIS_OBJECT (*dynamic_cast<unit_base *>(application_shell::single_instance()))
131void twofish_thread::perform_activity(
void *)
152 int string_start = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
153 int string_end = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
165 ASSERT_TRUE(worked,
"phase 1 should not fail to encrypt the string");
169 worked = tc.
decrypt(target, recovered);
171 ASSERT_TRUE(worked,
"phase 1 should not fail to decrypt the string");
173 astring jammer_piece =
a_sprintf(
"--\noriginal has %d chars, recovered has %d chars",
183 if (teddro != ranstring) {
184 LOG(
a_sprintf(
"error!\toriginal has %d chars, recovered has %d chars",
190 ASSERT_EQUAL(teddro, ranstring,
"should not fail to regenerate the original string");
193 LOG(
a_sprintf(
"%s\nencrypt %d ms, decrypt %d ms, data %d bytes",
194 jammer_piece.
s(), enc_durat, dec_durat, string_end - string_start + 1));
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
a_sprintf is a specialization of astring that provides printf style support.
const contents * observe() const
Returns a pointer to the underlying C array of data.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
int length() const
Returns the current length of the string.
A very common template for a dynamic array of bytes.
bool encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts the "source" array into the "target" array.
bool decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts the "target" array from the encrypted "source" array.
const basis::byte_array & get_key() const
returns our current key.
static int static_maximum_key_size_in_bits()
static int static_minimum_key_size_in_bits()
Provides a platform-independent object for adding threads to a program.
virtual void perform_activity(void *thread_data)=0
< invoked just after after start(), when the OS thread is created.
Manages a collection of threads.
static void text_dump(basis::astring &output, const basis::abyte *location, basis::un_int length, basis::un_int label=0, const char *eol="\n")
prints out a block of memory in a human readable form.
Provides various functions for massaging strings.
static void sleep_ms(basis::un_int msec)
a system independent name for a forced snooze measured in milliseconds.
Represents a point in time relative to the operating system startup time.
void reset()
sets the stamp time back to now.
time_representation value() const
returns the time_stamp in terms of the lower level type.
#define NULL_POINTER
The value representing a pointer to nothing.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
void flip_increasing(type &a, type &b)
Makes sure that two values are in increasing order (a < b).
const int KILOBYTE
Number of bytes in a kilobyte.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
const int TEST_RUNS_PER_KEY
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)