33 using namespace basis;
44 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), 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()
102 _threads.add_thread(
new blowfish_thread(*
this),
true,
NULL_POINTER);
105 #ifdef DEBUG_BLOWFISH
109 while (_threads.threads()) {
110 #ifdef DEBUG_BLOWFISH
113 _threads.clean_debris();
114 time_control::sleep_ms(1000);
117 #ifdef DEBUG_BLOWFISH
119 LOG(
a_sprintf(
"duration for %d keys and encrypt/decrypt=%d ms,",
121 LOG(
a_sprintf(
"that comes to %d ms per cycle.\n",
int(
double(duration
125 return final_report();
130 #undef UNIT_BASE_THIS_OBJECT
131 #define UNIT_BASE_THIS_OBJECT (*dynamic_cast<unit_base *>(application_shell::single_instance()))
133 void blowfish_thread::perform_activity(
void *)
140 (blowfish_crypto::minimum_key_size(),
141 blowfish_crypto::maximum_key_size()));
142 #ifdef DEBUG_BLOWFISH
149 #ifdef DEBUG_BLOWFISH
157 int string_start = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
158 int string_end = _parent.randomizer().inclusive(0,
MAX_STRING - 1);
168 (
abyte*)ranstring.
s()), target);
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");
183 #ifdef DEBUG_BLOWFISH
184 if (teddro != ranstring) {
185 LOG(
a_sprintf(
"error!\toriginal has %d chars, recovered has %d chars\n",
191 ASSERT_EQUAL(teddro, ranstring,
"should not fail to regenerate the original string");
193 #ifdef DEBUG_BLOWFISH
194 LOG(
a_sprintf(
" encrypt %d ms, decrypt %d ms, data %d bytes\n",
195 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.
const basis::byte_array & get_key() const
returns our current key.
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)