33 using namespace basis;
44 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
46 #define DEBUG_BLOWFISH
61 class blowfish_thread :
public ethread
64 blowfish_thread(test_blowfish &parent) :
ethread(), _parent(parent) {}
66 void perform_activity(
void *ptr);
70 test_blowfish &_parent;
88 friend class blowfish_thread;
91 int test_blowfish::execute()
95 LOG(
"starting blowfish test...");
102 _threads.add_thread(
new blowfish_thread(*
this),
true,
NULL_POINTER);
105 #ifdef DEBUG_BLOWFISH
106 LOG(
"started all threads...");
109 while (_threads.threads()) {
110 #ifdef DEBUG_BLOWFISH
111 LOG(
"cleaning debris.");
113 _threads.clean_debris();
114 time_control::sleep_ms(1000);
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()))
131 void blowfish_thread::perform_activity(
void *)
138 (blowfish_crypto::minimum_key_size(),
139 blowfish_crypto::maximum_key_size()));
140 #ifdef DEBUG_BLOWFISH
146 #ifdef DEBUG_BLOWFISH
153 int string_start = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
154 int string_end = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
157 #ifdef DEBUG_BLOWFISH
166 ASSERT_TRUE(worked,
"phase 1 should not fail to encrypt the string");
170 worked = bc.
decrypt(target, recovered);
172 ASSERT_TRUE(worked,
"phase 1 should not fail to decrypt the string");
173 #ifdef DEBUG_BLOWFISH
174 astring jammer_piece =
a_sprintf(
"--\noriginal has %d chars, recovered has %d chars",
179 #ifdef DEBUG_BLOWFISH
183 #ifdef DEBUG_BLOWFISH
184 if (teddro != ranstring) {
185 LOG(
a_sprintf(
"error!\toriginal has %d chars, recovered has %d chars",
191 ASSERT_EQUAL(teddro, ranstring,
"should not fail to regenerate the original string");
193 #ifdef DEBUG_BLOWFISH
194 LOG(
a_sprintf(
"%s\nencrypt %d ms, decrypt %d ms, data %d bytes",
195 jammer_piece.
s(), enc_durat, dec_durat, string_end - string_start + 1));
197 time_control::sleep_ms(0);
199 time_control::sleep_ms(0);
The application_shell is a base object for console programs.
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.
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.
Provides a platform-independent object for adding threads to a program.
Manages a collection of threads.
Provides various functions for massaging strings.
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)