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