aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/dh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/dh.cpp')
-rw-r--r--doc/examples/dh.cpp62
1 files changed, 0 insertions, 62 deletions
diff --git a/doc/examples/dh.cpp b/doc/examples/dh.cpp
deleted file mode 100644
index d62d49f65..000000000
--- a/doc/examples/dh.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <botan/botan.h>
-#include <botan/dh.h>
-#include <botan/pubkey.h>
-using namespace Botan;
-
-#include <iostream>
-#include <memory>
-
-int main()
- {
- try
- {
- LibraryInitializer init;
-
- AutoSeeded_RNG rng;
-
- // Alice and Bob agree on a DH domain to use
- DL_Group shared_domain("modp/ietf/2048");
-
- // Alice creates a DH key
- DH_PrivateKey private_a(rng, shared_domain);
-
- // Bob creates a key with a matching group
- DH_PrivateKey private_b(rng, shared_domain);
-
- // Alice sends to Bob her public key and a session parameter
- std::vector<byte> public_a = private_a.public_value();
- const std::string session_param =
- "Alice and Bob's shared session parameter";
-
- // Bob sends his public key to Alice
- std::vector<byte> public_b = private_b.public_value();
-
- // Now Alice performs the key agreement operation
- PK_Key_Agreement ka_alice(private_a, "KDF2(SHA-256)");
- SymmetricKey alice_key = ka_alice.derive_key(32, public_b, session_param);
-
- // Bob does the same:
- PK_Key_Agreement ka_bob(private_b, "KDF2(SHA-256)");
- SymmetricKey bob_key = ka_bob.derive_key(32, public_a, session_param);
-
- if(alice_key == bob_key)
- {
- std::cout << "The two keys matched, everything worked\n";
- std::cout << "The shared key was: " << alice_key.as_string() << "\n";
- }
- else
- {
- std::cout << "The two keys didn't match! Hmmm...\n";
- std::cout << "Alice's key was: " << alice_key.as_string() << "\n";
- std::cout << "Bob's key was: " << bob_key.as_string() << "\n";
- }
-
- // Now use the shared key for encryption or MACing or whatever
- }
- catch(std::exception& e)
- {
- std::cout << e.what() << std::endl;
- return 1;
- }
- return 0;
- }