1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3  *
4  * LibTomCrypt is a library that provides various cryptographic
5  * algorithms in a highly modular and flexible manner.
6  *
7  * The library is free for all purposes without any express
8  * guarantee it works.
9  */
10 
11 #include "tomcrypt_private.h"
12 
13 #ifdef LTC_SOBER128_STREAM
14 
15 /**
16    Encrypt (or decrypt) bytes of ciphertext (or plaintext) with SOBER128
17    @param key     The key
18    @param keylen  The key length
19    @param iv      The initial vector
20    @param ivlen   The initial vector length
21    @param datain  The plaintext (or ciphertext)
22    @param datalen The length of the input and output (octets)
23    @param dataout [out] The ciphertext (or plaintext)
24    @return CRYPT_OK if successful
25 */
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)26 int sober128_stream_memory(const unsigned char *key,    unsigned long keylen,
27                            const unsigned char *iv,     unsigned long ivlen,
28                            const unsigned char *datain, unsigned long datalen,
29                            unsigned char *dataout)
30 {
31    sober128_state st;
32    int err;
33 
34    if ((err = sober128_stream_setup(&st, key, keylen)) != CRYPT_OK) goto WIPE_KEY;
35    if ((err = sober128_stream_setiv(&st, iv, ivlen))   != CRYPT_OK) goto WIPE_KEY;
36    err = sober128_stream_crypt(&st, datain, datalen, dataout);
37 WIPE_KEY:
38    sober128_stream_done(&st);
39    return err;
40 }
41 
42 #endif /* LTC_SOBER128_STREAM */
43 
44 /* ref:         $Format:%D$ */
45 /* git commit:  $Format:%H$ */
46 /* commit time: $Format:%ai$ */
47