]> git.zerfleddert.de Git - proxmark3-svn/blob - common/polarssl/libpcrypto.c
032c3a18bcf49bb6fda4b996b329de4692ea568c
[proxmark3-svn] / common / polarssl / libpcrypto.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2018 Merlok
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // crypto commands
9 //-----------------------------------------------------------------------------
10
11 #include "polarssl/libpcrypto.h"
12 #include <polarssl/aes.h>
13
14 int aes_encode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length){
15 uint8_t iiv[16] = {0};
16 if (iv)
17 memcpy(iiv, iv, 16);
18
19 aes_context aes;
20 aes_init(&aes);
21 if (aes_setkey_enc(&aes, key, 128))
22 return 1;
23 if (aes_crypt_cbc(&aes, AES_ENCRYPT, length, iiv, input, output))
24 return 2;
25 aes_free(&aes);
26
27 return 0;
28 }
29
30 int aes_decode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length){
31 uint8_t iiv[16] = {0};
32 if (iv)
33 memcpy(iiv, iv, 16);
34
35 aes_context aes;
36 aes_init(&aes);
37 if (aes_setkey_dec(&aes, key, 128))
38 return 1;
39 if (aes_crypt_cbc(&aes, AES_DECRYPT, length, iiv, input, output))
40 return 2;
41 aes_free(&aes);
42
43 return 0;
44 }
Impressum, Datenschutz