summaryrefslogtreecommitdiff
path: root/nacl/crypto_stream/wrapper-xor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/crypto_stream/wrapper-xor.cpp')
-rw-r--r--nacl/crypto_stream/wrapper-xor.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/nacl/crypto_stream/wrapper-xor.cpp b/nacl/crypto_stream/wrapper-xor.cpp
new file mode 100644
index 00000000..8d770d1e
--- /dev/null
+++ b/nacl/crypto_stream/wrapper-xor.cpp
@@ -0,0 +1,17 @@
1#include <string>
2using std::string;
3#include "crypto_stream.h"
4
5string crypto_stream_xor(const string &m,const string &n,const string &k)
6{
7 if (n.size() != crypto_stream_NONCEBYTES) throw "incorrect nonce length";
8 if (k.size() != crypto_stream_KEYBYTES) throw "incorrect key length";
9 size_t mlen = m.size();
10 unsigned char c[mlen];
11 crypto_stream_xor(c,
12 (const unsigned char *) m.c_str(),mlen,
13 (const unsigned char *) n.c_str(),
14 (const unsigned char *) k.c_str()
15 );
16 return string((char *) c,mlen);
17}