34 using namespace basis;
48 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), to_print)
64 class rsa_thread :
public ethread
67 rsa_thread(test_rsa &parent) :
ethread(), _parent(parent) {}
69 void perform_activity(
void *ptr);
83 virtual ~test_rsa() {}
86 const astring &fodder()
const {
return _fodder; }
94 friend class rsa_thread;
97 int test_rsa::execute()
102 _threads.add_thread(
new rsa_thread(*
this),
true,
NULL_POINTER);
105 while (_threads.threads()) {
106 #ifdef DEBUG_RSA_CRYPTO
109 _threads.clean_debris();
110 #ifdef DEBUG_RSA_CRYPTO
113 time_control::sleep_ms(1000);
116 #ifdef DEBUG_RSA_CRYPTO
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
124 return final_report();
129 #undef UNIT_BASE_THIS_OBJECT
130 #define UNIT_BASE_THIS_OBJECT (*dynamic_cast<unit_base *>(application_shell::single_instance()))
132 void rsa_thread::perform_activity(
void *)
150 int string_start = _parent.randomizer().inclusive(0,
MAX_STRING);
151 int string_end = _parent.randomizer().inclusive(0,
MAX_STRING);
162 (
abyte*)ranstring.
s()), target);
164 ASSERT_TRUE(worked,
"phase 1 shouldn't fail to encrypt the string");
171 ASSERT_TRUE(worked,
"phase 1 should not fail to decrypt the string");
175 ASSERT_EQUAL(teddro, ranstring,
"should not fail to get back the data");
182 (
abyte*)ranstring.
s()), target);
184 ASSERT_TRUE(worked,
"phase 2 should not fail to encrypt the string");
189 ASSERT_TRUE(worked,
"phase 2 should not fail to decrypt the string");
191 teddro = (
char *)recovered.
observe();
193 ASSERT_EQUAL(teddro, ranstring,
"should not fail to get back the data here either");
195 #ifdef DEBUG_RSA_CRYPTO
196 LOG(
a_sprintf(
"key generation: %d ms, public encrypt: %d ms, private "
197 "decrypt: %d ms", key_durat, pub_enc_durat, priv_dec_durat));
198 LOG(
a_sprintf(
"data size: %d bytes, private encrypt: %d ms, public "
200 string_end - string_start + 1, priv_enc_durat, pub_dec_durat));
203 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.
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.
Supports public key encryption and decryption.
bool public_encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts "source" using our public key and stores it in "target".
bool private_key(basis::byte_array &privkey) const
makes a copy of the private key held here.
bool private_decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts "source" using our private key and stores it in "target".
bool public_decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts "source" using our public key and stores it in "target".
bool private_encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts "source" using our private key and stores it in "target".
bool public_key(basis::byte_array &pubkey) const
makes a copy of the public key held here.
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.
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)