1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 
4 #include "tomcrypt_private.h"
5 
6 #ifdef LTC_SOSEMANUK
7 
8 /**
9    Encrypt (or decrypt) bytes of ciphertext (or plaintext) with Sosemanuk
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 */
sosemanuk_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 sosemanuk_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    sosemanuk_state st;
25    int err;
26 
27    if ((err = sosemanuk_setup(&st, key, keylen)) != CRYPT_OK) goto WIPE_KEY;
28    if ((err = sosemanuk_setiv(&st, iv, ivlen))   != CRYPT_OK) goto WIPE_KEY;
29    err = sosemanuk_crypt(&st, datain, datalen, dataout);
30 WIPE_KEY:
31    sosemanuk_done(&st);
32    return err;
33 }
34 
35 #endif /* LTC_SOSEMANUK */
36