1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3
4 #include "tomcrypt_private.h"
5
6 #ifdef LTC_RC4_STREAM
7
8 /**
9 Encrypt (or decrypt) bytes of ciphertext (or plaintext) with RC4
10 @param key The key
11 @param keylen The key length
12 @param datain The plaintext (or ciphertext)
13 @param datalen The length of the input and output (octets)
14 @param dataout [out] The ciphertext (or plaintext)
15 @return CRYPT_OK if successful
16 */
rc4_stream_memory(const unsigned char * key,unsigned long keylen,const unsigned char * datain,unsigned long datalen,unsigned char * dataout)17 int rc4_stream_memory(const unsigned char *key, unsigned long keylen,
18 const unsigned char *datain, unsigned long datalen,
19 unsigned char *dataout)
20 {
21 rc4_state st;
22 int err;
23
24 if ((err = rc4_stream_setup(&st, key, keylen)) != CRYPT_OK) goto WIPE_KEY;
25 err = rc4_stream_crypt(&st, datain, datalen, dataout);
26 WIPE_KEY:
27 rc4_stream_done(&st);
28 return err;
29 }
30
31 #endif /* LTC_RC4_STREAM */
32