mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
Remove aes.c in favor of mbedtls implementation.
Changelog
This commit is contained in:
parent
ec534305de
commit
996ed197fb
9 changed files with 34 additions and 1229 deletions
|
@ -4,6 +4,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
|
||||||
|
|
||||||
## [unreleased][unreleased]
|
## [unreleased][unreleased]
|
||||||
- Add documentation for usage of Proxmark3 under WSL (@doegox)
|
- Add documentation for usage of Proxmark3 under WSL (@doegox)
|
||||||
|
- Change: replace aes.c with mbedtls version (@slurdge)
|
||||||
- Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox)
|
- Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox)
|
||||||
- Add config for RaspberryPi in JTAG tools (@doegox)
|
- Add config for RaspberryPi in JTAG tools (@doegox)
|
||||||
- Add config for FTDI C232HM-DDHSL-0 in JTAG tools (@doegox)
|
- Add config for FTDI C232HM-DDHSL-0 in JTAG tools (@doegox)
|
||||||
|
|
|
@ -30,7 +30,7 @@ SRC_ISO15693 = iso15693.c iso15693tools.c
|
||||||
SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c
|
SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c
|
||||||
SRC_ISO14443b = iso14443b.c
|
SRC_ISO14443b = iso14443b.c
|
||||||
SRC_FELICA = felica.c
|
SRC_FELICA = felica.c
|
||||||
SRC_CRAPTO1 = crypto1.c des.c aes.c desfire_key.c desfire_crypto.c mifaredesfire.c
|
SRC_CRAPTO1 = crypto1.c des.c desfire_key.c desfire_crypto.c mifaredesfire.c aes.c platform_util.c
|
||||||
SRC_CRC = crc.c crc16.c crc32.c
|
SRC_CRC = crc.c crc16.c crc32.c
|
||||||
SRC_ICLASS = iclass.c optimized_cipher.c
|
SRC_ICLASS = iclass.c optimized_cipher.c
|
||||||
SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c
|
SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c
|
||||||
|
|
1170
armsrc/aes.c
1170
armsrc/aes.c
File diff suppressed because it is too large
Load diff
34
armsrc/aes.h
34
armsrc/aes.h
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* AES Cryptographic Algorithm Header File. Include this header file in
|
|
||||||
* your source which uses these given APIs. (This source is kept under
|
|
||||||
* public domain)
|
|
||||||
*/
|
|
||||||
#ifndef __AES_H
|
|
||||||
#define __AES_H
|
|
||||||
|
|
||||||
// AES context structure
|
|
||||||
typedef struct {
|
|
||||||
unsigned int Ek[60];
|
|
||||||
unsigned int Dk[60];
|
|
||||||
unsigned int Iv[4];
|
|
||||||
unsigned char Nr;
|
|
||||||
unsigned char Mode;
|
|
||||||
} AesCtx;
|
|
||||||
|
|
||||||
// key length in bytes
|
|
||||||
#define KEY128 16
|
|
||||||
#define KEY192 24
|
|
||||||
#define KEY256 32
|
|
||||||
// block size in bytes
|
|
||||||
#define BLOCKSZ 16
|
|
||||||
// mode
|
|
||||||
#define EBC 0
|
|
||||||
#define CBC 1
|
|
||||||
|
|
||||||
// AES API function prototype
|
|
||||||
|
|
||||||
int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode);
|
|
||||||
int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen);
|
|
||||||
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -571,15 +571,19 @@ void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect,
|
||||||
case T_AES:
|
case T_AES:
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case MCO_ENCYPHER: {
|
case MCO_ENCYPHER: {
|
||||||
AesCtx ctx;
|
mbedtls_aes_context ctx;
|
||||||
AesCtxIni(&ctx, ivect, key->data, KEY128, CBC);
|
mbedtls_aes_init(&ctx);
|
||||||
AesEncrypt(&ctx, data, edata, sizeof(edata));
|
mbedtls_aes_setkey_enc(&ctx, key->data, 128);
|
||||||
|
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, sizeof(edata), ivect, data, edata);
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MCO_DECYPHER: {
|
case MCO_DECYPHER: {
|
||||||
AesCtx ctx;
|
mbedtls_aes_context ctx;
|
||||||
AesCtxIni(&ctx, ivect, key->data, KEY128, CBC);
|
mbedtls_aes_init(&ctx);
|
||||||
AesDecrypt(&ctx, edata, data, sizeof(edata));
|
mbedtls_aes_setkey_dec(&ctx, key->data, 128);
|
||||||
|
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, sizeof(edata), ivect, edata, data);
|
||||||
|
mbedtls_aes_free(&ctx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -433,15 +433,9 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
desfirekey_t key = &defaultkey;
|
desfirekey_t key = &defaultkey;
|
||||||
Desfire_aes_key_new(keybytes, key);
|
Desfire_aes_key_new(keybytes, key);
|
||||||
|
|
||||||
AesCtx ctx;
|
mbedtls_aes_context ctx;
|
||||||
uint8_t IV[16] = {0x00};
|
uint8_t IV[16] = {0x00};
|
||||||
if (AesCtxIni(&ctx, IV, key->data, KEY128, CBC) < 0) {
|
mbedtls_aes_init(&ctx);
|
||||||
if (DBGLEVEL >= 4) {
|
|
||||||
DbpString("AES context failed to init");
|
|
||||||
}
|
|
||||||
OnError(7);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd[0] = AUTHENTICATE_AES;
|
cmd[0] = AUTHENTICATE_AES;
|
||||||
cmd[1] = 0x00; //keynumber
|
cmd[1] = 0x00; //keynumber
|
||||||
|
@ -457,13 +451,27 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
memcpy(encRndB, resp + 3, 16);
|
memcpy(encRndB, resp + 3, 16);
|
||||||
|
|
||||||
// dekryptera tagnonce.
|
// dekryptera tagnonce.
|
||||||
AesDecrypt(&ctx, encRndB, decRndB, 16);
|
if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) {
|
||||||
|
if (DBGLEVEL >= 4) {
|
||||||
|
DbpString("mbedtls_aes_setkey_dec failed");
|
||||||
|
}
|
||||||
|
OnError(7);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, 16, IV, encRndB, decRndB);
|
||||||
rol(decRndB, 16);
|
rol(decRndB, 16);
|
||||||
uint8_t nonce[16] = {0x00};
|
uint8_t nonce[16] = {0x00};
|
||||||
memcpy(both, nonce, 16);
|
memcpy(both, nonce, 16);
|
||||||
memcpy(both + 16, decRndB, 16);
|
memcpy(both + 16, decRndB, 16);
|
||||||
uint8_t encBoth[32] = {0x00};
|
uint8_t encBoth[32] = {0x00};
|
||||||
AesEncrypt(&ctx, both, encBoth, 32);
|
if (mbedtls_aes_setkey_enc(&ctx, key->data, 128) != 0) {
|
||||||
|
if (DBGLEVEL >= 4) {
|
||||||
|
DbpString("mbedtls_aes_setkey_enc failed");
|
||||||
|
}
|
||||||
|
OnError(7);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 32, IV, both, encBoth);
|
||||||
|
|
||||||
cmd[0] = ADDITIONAL_FRAME;
|
cmd[0] = ADDITIONAL_FRAME;
|
||||||
memcpy(cmd + 1, encBoth, 32);
|
memcpy(cmd + 1, encBoth, 32);
|
||||||
|
|
|
@ -63,7 +63,7 @@ DETECTED_OS=Windows
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory
|
# Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory
|
||||||
VPATH = . ../common ../common/crapto1 ../common/polarssl ../fpga ../zlib ../armsrc/Standalone ../uart
|
VPATH = . ../common ../common/crapto1 ../common/mbedtls ../fpga ../zlib ../armsrc/Standalone ../uart
|
||||||
|
|
||||||
INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h $(APP_INCLUDES)
|
INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h $(APP_INCLUDES)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "aes.h"
|
#include "mbedtls/aes.h"
|
||||||
#include "mifare.h"
|
#include "mifare.h"
|
||||||
|
|
||||||
#define MAX_CRYPTO_BLOCK_SIZE 16
|
#define MAX_CRYPTO_BLOCK_SIZE 16
|
||||||
|
@ -71,10 +71,6 @@ enum DESFIRE_CRYPTOALGO {
|
||||||
struct desfire_key {
|
struct desfire_key {
|
||||||
enum DESFIRE_CRYPTOALGO type;
|
enum DESFIRE_CRYPTOALGO type;
|
||||||
uint8_t data[24];
|
uint8_t data[24];
|
||||||
// DES_key_schedule ks1;
|
|
||||||
// DES_key_schedule ks2;
|
|
||||||
// DES_key_schedule ks3;
|
|
||||||
AesCtx aes_ks;
|
|
||||||
uint8_t cmac_sk1[24];
|
uint8_t cmac_sk1[24];
|
||||||
uint8_t cmac_sk2[24];
|
uint8_t cmac_sk2[24];
|
||||||
uint8_t aes_version;
|
uint8_t aes_version;
|
||||||
|
|
|
@ -60,9 +60,9 @@
|
||||||
* mbedtls_platform_zeroize() to use a suitable implementation for their
|
* mbedtls_platform_zeroize() to use a suitable implementation for their
|
||||||
* platform and needs.
|
* platform and needs.
|
||||||
*/
|
*/
|
||||||
static void *(* const volatile memset_func)(void *, int, size_t) = memset;
|
//static void *(* const volatile memset_func)(void *, int, size_t) = memset;
|
||||||
|
|
||||||
void mbedtls_platform_zeroize(void *buf, size_t len) {
|
void mbedtls_platform_zeroize(void *buf, size_t len) {
|
||||||
memset_func(buf, 0, len);
|
memset(buf, 0, len);
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */
|
#endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue