Sha256: f11fa4f63a1115b55a16a8c1a0a06eb23b44852b759c9830274cebe1e0d437ef

Contents?: true

Size: 795 Bytes

Versions: 3

Compression:

Stored size: 795 Bytes

Contents

#include <string>
using std::string;
#include "crypto_secretbox.h"

string crypto_secretbox(const string &m,const string &n,const string &k)
{
  if (k.size() != crypto_secretbox_KEYBYTES) throw "incorrect key length";
  if (n.size() != crypto_secretbox_NONCEBYTES) throw "incorrect nonce length";
  size_t mlen = m.size() + crypto_secretbox_ZEROBYTES;
  unsigned char mpad[mlen];
  for (int i = 0;i < crypto_secretbox_ZEROBYTES;++i) mpad[i] = 0;
  for (int i = crypto_secretbox_ZEROBYTES;i < mlen;++i) mpad[i] = m[i - crypto_secretbox_ZEROBYTES];
  unsigned char cpad[mlen];
  crypto_secretbox(cpad,mpad,mlen,(const unsigned char *) n.c_str(),(const unsigned char *) k.c_str());
  return string(
    (char *) cpad + crypto_secretbox_BOXZEROBYTES,
    mlen - crypto_secretbox_BOXZEROBYTES
  );
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby_nacl-0.1.2 ext/ruby_nacl/NaCl/crypto_secretbox/wrapper-box.cpp
ruby_nacl-0.1.1 ext/ruby_nacl/NaCl/crypto_secretbox/wrapper-box.cpp
ruby_nacl-0.1.0 ext/ruby_nacl/NaCl/crypto_secretbox/wrapper-box.cpp