aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-04-09 14:03:13 +0000
committerlloyd <[email protected]>2010-04-09 14:03:13 +0000
commit143b5cb297a36b94c9d0e56e2d2145a7c55efde5 (patch)
tree000b11f87806678649e68e753aaad8ed6ef45803 /doc/examples
parenta1fc16d73b6e8fbb041c5163687bfd37c5705da4 (diff)
parentd7e2e9316a5540e93595b5386f67594135de736d (diff)
propagate from branch 'net.randombit.botan' (head 75d272c759511a9a99a371ddc74bd17b2c1453b6)
to branch 'net.randombit.botan.c++0x' (head 2ce9ba37cb9287a3d875921240d6682100625b9f)
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/factor.cpp2
-rw-r--r--doc/examples/new_engine.cpp (renamed from doc/examples/xor_ciph.cpp)58
2 files changed, 32 insertions, 28 deletions
diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp
index b0105426b..c4d37c92b 100644
--- a/doc/examples/factor.cpp
+++ b/doc/examples/factor.cpp
@@ -101,7 +101,7 @@ std::vector<BigInt> factorize(const BigInt& n_in,
while(n != 1)
{
- if(is_prime(n, rng))
+ if(check_prime(n, rng))
{
factors.push_back(n);
break;
diff --git a/doc/examples/xor_ciph.cpp b/doc/examples/new_engine.cpp
index 3174e103e..2f412a6b9 100644
--- a/doc/examples/xor_ciph.cpp
+++ b/doc/examples/new_engine.cpp
@@ -1,15 +1,13 @@
/*
+* Adding an application specific engine
* (C) 2004,2008 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-/*
- Adding a simple XOR cipher to the internal tables
-*/
-
#include <botan/stream_cipher.h>
-#include <botan/init.h>
+#include <botan/engine.h>
+
using namespace Botan;
class XOR_Cipher : public StreamCipher
@@ -25,43 +23,49 @@ class XOR_Cipher : public StreamCipher
XOR_Cipher() : StreamCipher(1, 32) { mask_pos = 0; }
private:
- void cipher(const byte[], byte[], u32bit);
- void key_schedule(const byte[], u32bit);
+ void cipher(const byte in[], byte out[], u32bit length)
+ {
+ for(u32bit j = 0; j != length; j++)
+ {
+ out[j] = in[j] ^ mask[mask_pos];
+ mask_pos = (mask_pos + 1) % mask.size();
+ }
+ }
+
+ void key_schedule(const byte key[], u32bit length)
+ {
+ mask.set(key, length);
+ }
SecureVector<byte> mask;
u32bit mask_pos;
};
-void XOR_Cipher::cipher(const byte in[], byte out[], u32bit length)
+class Application_Engine : public Engine
{
- for(u32bit j = 0; j != length; j++)
- {
- out[j] = in[j] ^ mask[mask_pos];
- mask_pos = (mask_pos + 1) % mask.size();
- }
- }
-
-void XOR_Cipher::key_schedule(const byte key[], u32bit length)
- {
- mask.set(key, length);
- }
+ public:
+ std::string provider_name() const { return "application"; }
+
+ StreamCipher* find_stream_cipher(const SCAN_Name& request,
+ Algorithm_Factory&) const
+ {
+ if(request.algo_name() == "XOR")
+ return new XOR_Cipher;
+ return 0;
+ }
+ };
-#include <fstream>
+#include <botan/botan.h>
#include <iostream>
#include <string>
-#include <vector>
-#include <cstring>
-
-#include <botan/lookup.h>
-#include <botan/filters.h>
-#include <botan/libstate.h>
int main()
{
Botan::LibraryInitializer init;
- global_state().algorithm_factory().add_stream_cipher(new XOR_Cipher, "app");
+ global_state().algorithm_factory().add_engine(
+ new Application_Engine);
// a hex key value
SymmetricKey key("010203040506070809101112AAFF");