Exemplo n.º 1
0
SODIUM_EXPORT int
crypto_stream_salsa20_ref(unsigned char *c,
                          unsigned long long clen,
                          const unsigned char *n,
                          const unsigned char *k)
{
    return crypto_stream_salsa20(c, clen, n, k);
}
Exemplo n.º 2
0
SEXP R_stream_salsa20(SEXP n, SEXP key, SEXP nonce){
  if(LENGTH(key) != crypto_stream_salsa20_KEYBYTES)
    Rf_error("Invalid key, must be exactly %d bytes", crypto_stream_salsa20_KEYBYTES);
  if(LENGTH(nonce) != crypto_stream_salsa20_NONCEBYTES)
    Rf_error("Invalid nonce, must be exactly %d bytes", crypto_stream_salsa20_NONCEBYTES);
  unsigned long long clen = (unsigned long long) asReal(n);
  SEXP res = allocVector(RAWSXP, clen);
  crypto_stream_salsa20(RAW(res), clen, RAW(nonce), RAW(key));
  return res;
}
Exemplo n.º 3
0
int crypto_stream(
        unsigned char *c,unsigned long long clen,
  const unsigned char *n,
  const unsigned char *k
)
{
  unsigned char subkey[32];
  crypto_core_hsalsa20(subkey,n,k,sigma);
  return crypto_stream_salsa20(c,clen,n + 16,subkey);
}
Exemplo n.º 4
0
int crypto_secretbox_open(
  unsigned char *m,
  const unsigned char *c,unsigned long long clen,
  const unsigned char *n,
  const unsigned char *k
)
{
  int i;
  unsigned char subkey[32];
  if (clen < 32) return -1;
  crypto_stream_salsa20(subkey,32,n,k);
  if (crypto_auth_hmacsha512256_verify(c,c + 32,clen - 32,subkey) != 0) return -1;
  crypto_stream_salsa20_xor(m,c,clen,n,k);
  for (i = 0;i < 32;++i) m[i] = 0;
  return 0;
}