crypto_stream function

I've tried to implement the crypto_stream function, however I'm not sure if it's OK. It would be great if you could take a look at it.
Thank you :)