]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - common/polarssl/libpcrypto.c
13e37f00a4ceed844014d38a546dae7eeead7930
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2018 Merlok
3 // Copyright (C) 2018 drHatson
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
10 //-----------------------------------------------------------------------------
12 #include "polarssl/libpcrypto.h"
13 #include <polarssl/aes.h>
14 #include <polarssl/aes_cmac128.h>
16 // NIST Special Publication 800-38A \97 Recommendation for block cipher modes of operation: methods and techniques, 2001.
17 int aes_encode(uint8_t *iv
, uint8_t *key
, uint8_t *input
, uint8_t *output
, int length
){
18 uint8_t iiv
[16] = {0};
24 if (aes_setkey_enc(&aes
, key
, 128))
26 if (aes_crypt_cbc(&aes
, AES_ENCRYPT
, length
, iiv
, input
, output
))
33 int aes_decode(uint8_t *iv
, uint8_t *key
, uint8_t *input
, uint8_t *output
, int length
){
34 uint8_t iiv
[16] = {0};
40 if (aes_setkey_dec(&aes
, key
, 128))
42 if (aes_crypt_cbc(&aes
, AES_DECRYPT
, length
, iiv
, input
, output
))
49 // NIST Special Publication 800-38B \97 Recommendation for block cipher modes of operation: The CMAC mode for authentication.
50 // https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/AES_CMAC.pdf
51 int aes_cmac(uint8_t *iv
, uint8_t *key
, uint8_t *input
, uint8_t *mac
, int length
) {
52 memset(mac
, 0x00, 16);
53 uint8_t iiv
[16] = {0};
58 aes_cmac128_context ctx
;
59 aes_cmac128_starts(&ctx
, key
);
60 aes_cmac128_update(&ctx
, input
, length
);
61 aes_cmac128_final(&ctx
, mac
);
66 int aes_cmac8(uint8_t *iv
, uint8_t *key
, uint8_t *input
, uint8_t *mac
, int length
) {
67 uint8_t cmac
[16] = {0};
70 int res
= aes_cmac(iv
, key
, input
, cmac
, length
);
74 for(int i
= 0; i
< 8; i
++)
75 mac
[i
] = cmac
[i
* 2 + 1];