1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6

7
#include <TrustWalletCore/TWAES.h>
8

9
#include <../../src/Encrypt.h>
10

11
using namespace TW;
12

13 1
TWData *_Nullable TWAESEncryptCBC(TWData *_Nonnull key, TWData *_Nonnull data, TWData *_Nonnull iv, enum TWAESPaddingMode mode) {
14
    try {
15 1
        Data encrypted = Encrypt::AESCBCEncrypt(*((Data*)key), *((Data*)data), *((Data*)iv), mode);
16 1
        return TWDataCreateWithData(&encrypted);
17 1
    } catch (...) {
18 0
        return nullptr;
19
    }
20
}
21

22 1
TWData *_Nullable TWAESDecryptCBC(TWData *_Nonnull key, TWData *_Nonnull data, TWData *_Nonnull iv, enum TWAESPaddingMode mode) {
23
    try {
24 1
        Data decrypted = Encrypt::AESCBCDecrypt(*((Data*)key), *((Data*)data), *((Data*)iv), mode);
25 1
        return TWDataCreateWithData(&decrypted);
26 1
    } catch (...) {
27 0
        return nullptr;
28
    }
29
}
30

31 1
TWData *_Nullable TWAESEncryptCTR(TWData *_Nonnull key, TWData *_Nonnull data, TWData *_Nonnull iv) {
32
    try {
33 1
        Data encrypted = Encrypt::AESCTREncrypt(*((Data*)key), *((Data*)data), *((Data*)iv));
34 1
        return TWDataCreateWithData(&encrypted);
35 1
    } catch (...) {
36 0
        return nullptr;
37
    }
38
}
39

40 1
TWData *_Nullable TWAESDecryptCTR(TWData *_Nonnull key, TWData *_Nonnull data, TWData *_Nonnull iv) {
41
    try {
42 1
        Data decrypted = Encrypt::AESCTRDecrypt(*((Data*)key), *((Data*)data), *((Data*)iv));
43 1
        return TWDataCreateWithData(&decrypted);
44 1
    } catch (...) {
45 0
        return nullptr;
46
    }
47
}

Read our documentation on viewing source code .

Loading