Sha256: a8d367b6b43427d96c21bd15b8c9b64d6005662328c2b4e5bce346407acb9c74

Contents?: true

Size: 900 Bytes

Versions: 3

Compression:

Stored size: 900 Bytes

Contents

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

string crypto_box(const string &m,const string &n,const string &pk,const string &sk)
{
  if (pk.size() != crypto_box_PUBLICKEYBYTES) throw "incorrect public-key length";
  if (sk.size() != crypto_box_SECRETKEYBYTES) throw "incorrect secret-key length";
  if (n.size() != crypto_box_NONCEBYTES) throw "incorrect nonce length";
  size_t mlen = m.size() + crypto_box_ZEROBYTES;
  unsigned char mpad[mlen];
  for (int i = 0;i < crypto_box_ZEROBYTES;++i) mpad[i] = 0;
  for (int i = crypto_box_ZEROBYTES;i < mlen;++i) mpad[i] = m[i - crypto_box_ZEROBYTES];
  unsigned char cpad[mlen];
  crypto_box(cpad,mpad,mlen,
    (const unsigned char *) n.c_str(),
    (const unsigned char *) pk.c_str(),
    (const unsigned char *) sk.c_str()
    );
  return string(
    (char *) cpad + crypto_box_BOXZEROBYTES,
    mlen - crypto_box_BOXZEROBYTES
  );
}

Version data entries

3 entries across 3 versions & 1 rubygems

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