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 #include "tomcrypt_private.h"
11 
12 /**
13    @file lrw_decrypt.c
14    LRW_MODE implementation, Decrypt blocks, Tom St Denis
15 */
16 
17 #ifdef LTC_LRW_MODE
18 
19 /**
20   LRW decrypt blocks
21   @param ct     The ciphertext
22   @param pt     [out] The plaintext
23   @param len    The length in octets, must be a multiple of 16
24   @param lrw    The LRW state
25 */
lrw_decrypt(const unsigned char * ct,unsigned char * pt,unsigned long len,symmetric_LRW * lrw)26 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw)
27 {
28    int err;
29 
30    LTC_ARGCHK(pt  != NULL);
31    LTC_ARGCHK(ct  != NULL);
32    LTC_ARGCHK(lrw != NULL);
33 
34    if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) {
35       return err;
36    }
37 
38    if (cipher_descriptor[lrw->cipher]->accel_lrw_decrypt != NULL) {
39       return cipher_descriptor[lrw->cipher]->accel_lrw_decrypt(ct, pt, len, lrw->IV, lrw->tweak, &lrw->key);
40    }
41 
42    return lrw_process(ct, pt, len, LRW_DECRYPT, lrw);
43 }
44 
45 
46 #endif
47 
48 /* ref:         $Format:%D$ */
49 /* git commit:  $Format:%H$ */
50 /* commit time: $Format:%ai$ */
51