wrapper-xor.cpp 527 B

1234567891011121314151617
  1. #include <string>
  2. using std::string;
  3. #include "crypto_stream.h"
  4. string crypto_stream_xor(const string &m,const string &n,const string &k)
  5. {
  6. if (n.size() != crypto_stream_NONCEBYTES) throw "incorrect nonce length";
  7. if (k.size() != crypto_stream_KEYBYTES) throw "incorrect key length";
  8. size_t mlen = m.size();
  9. unsigned char c[mlen];
  10. crypto_stream_xor(c,
  11. (const unsigned char *) m.c_str(),mlen,
  12. (const unsigned char *) n.c_str(),
  13. (const unsigned char *) k.c_str()
  14. );
  15. return string((char *) c,mlen);
  16. }