Exemplo n.º 1
0
SEXP R_stream_xsalsa20(SEXP n, SEXP key, SEXP nonce){
  if(LENGTH(key) != crypto_stream_KEYBYTES)
    Rf_error("Invalid key, must be exactly %d bytes", crypto_stream_KEYBYTES);
  if(LENGTH(nonce) != crypto_stream_NONCEBYTES)
    Rf_error("Invalid nonce, must be exactly %d bytes", crypto_stream_NONCEBYTES);
  unsigned long long clen = (unsigned long long) asReal(n);
  SEXP res = allocVector(RAWSXP, clen);
  crypto_stream_xsalsa20(RAW(res), clen, RAW(nonce), RAW(key));
  return res;
}
Exemplo n.º 2
0
main()
{
  int i;
  crypto_stream_xsalsa20(rs,32,nonce,firstkey);
  for (i = 0;i < 32;++i) {
    printf(",0x%02x",(unsigned int) rs[i]);
    if (i % 8 == 7) printf("\n");
  }
  return 0;
}
Exemplo n.º 3
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_xsalsa20(subkey,32,n,k);
  if (crypto_onetimeauth_poly1305_verify(c + 16,c + 32,clen - 32,subkey) != 0) return -1;
  crypto_stream_xsalsa20_xor(m,c,clen,n,k);
  for (i = 0;i < 32;++i) m[i] = 0;
  return 0;
}
int crypto_secretbox_xsalsa20poly1305_open(
    unsigned char *m,
    const unsigned char *c,crypto_uint16 clen,
    const unsigned char *n,
    const unsigned char *k
    )
{
  int i;
  unsigned char x[32];
  if (clen < 32) return -1;
  crypto_stream_xsalsa20(x,32,n,k);
  if (crypto_onetimeauth_poly1305_verify(c + 16,c + 32,clen - 32,x) != 0) return -1;
  crypto_stream_xsalsa20_xor(m,c,clen,n,k);
  for(i=0;i<32;i++)
    m[i] = 0;
  return 0;
}
Exemplo n.º 5
0
int
crypto_stream(unsigned char *c, uint64_t clen,
              const unsigned char *n, const unsigned char *k)
{
    return crypto_stream_xsalsa20(c, clen, n, k);
}
Exemplo n.º 6
0
SODIUM_EXPORT int
crypto_stream_xsalsa20_ref(unsigned char *c, unsigned long long clen,
                           const unsigned char *n, const unsigned char *k)
{
    return crypto_stream_xsalsa20(c, clen, n, k);
}