44#define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
64class blowfish_thread :
public ethread
67 blowfish_thread(test_blowfish &parent) :
ethread(), _parent(parent) {}
73 test_blowfish &_parent;
91 friend class blowfish_thread;
94int test_blowfish::execute()
98 LOG(
"starting blowfish test...");
105 _threads.add_thread(
new blowfish_thread(*
this),
true,
NULL_POINTER);
109 LOG(
"started all threads...");
112 while (_threads.threads()) {
114 LOG(
"periodic debris cleaning.");
116 _threads.clean_debris();
121 LOG(
a_sprintf(
"duration for %d keys and encrypt/decrypt=%d ms,",
123 LOG(
a_sprintf(
"that comes to %d ms per cycle.",
int(
double(duration
126 return final_report();
131#undef UNIT_BASE_THIS_OBJECT
132#define UNIT_BASE_THIS_OBJECT (*dynamic_cast<unit_base *>(application_shell::single_instance()))
134void blowfish_thread::perform_activity(
void *)
157 int string_start = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
158 int string_end = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
170 ASSERT_TRUE(worked,
"phase 1 should not fail to encrypt the string");
174 worked = bc.
decrypt(target, recovered);
176 ASSERT_TRUE(worked,
"phase 1 should not fail to decrypt the string");
178 astring jammer_piece =
a_sprintf(
"--\noriginal has %d chars, recovered has %d chars",
188 if (teddro != ranstring) {
189 LOG(
a_sprintf(
"error!\toriginal has %d chars, recovered has %d chars",
195 ASSERT_EQUAL(teddro, ranstring,
"should not fail to regenerate the original string");
198 LOG(
a_sprintf(
"%s\nencrypt %d ms, decrypt %d ms, data %d bytes",
199 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.
Provides BlowFish encryption on byte_arrays using the OpenSSL package.
static int minimum_key_size()
returns the minimum key size (in bits) supported here.
bool decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts the "target" array from the encrypted "source" array.
bool encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts the "source" array into the "target" array.
static int maximum_key_size()
returns the maximum key size (in bits) supported here.
const basis::byte_array & get_key() const
returns our current key.
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).
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)