From 2c61530cba785b0e050ff0d50c512a8aa677d38d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 6 Jun 2022 12:59:09 +0200 Subject: [PATCH] minors stuff, added some blowfish decrypt --- client/src/crypto/libpcrypto.c | 18 ++++++++++++++++++ client/src/crypto/libpcrypto.h | 2 ++ client/src/emv/tlv.c | 11 ++++++----- client/src/fileutils.c | 11 +++++++++-- client/src/fileutils.h | 1 + client/src/mifare/mad.c | 2 +- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/client/src/crypto/libpcrypto.c b/client/src/crypto/libpcrypto.c index 0d641d22a..00b2fb8c9 100644 --- a/client/src/crypto/libpcrypto.c +++ b/client/src/crypto/libpcrypto.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "util.h" #include "ui.h" @@ -614,3 +615,20 @@ size_t FindISO9797M2PaddingDataLen(const uint8_t *data, size_t datalen) { } return 0; } + + +int blowfish_decrypt(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length) { + uint8_t iiv[16] = {0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + if (iv) + memcpy(iiv, iv, 16); + + mbedtls_blowfish_context blow; + mbedtls_blowfish_init(&blow); + if (mbedtls_blowfish_setkey(&blow, key, 64)) + return 1; + if (mbedtls_blowfish_crypt_cbc(&blow, MBEDTLS_BLOWFISH_DECRYPT, length, iiv, input, output)) + return 2; + mbedtls_blowfish_free(&blow); + + return 0; +} diff --git a/client/src/crypto/libpcrypto.h b/client/src/crypto/libpcrypto.h index 121b666d4..301633fde 100644 --- a/client/src/crypto/libpcrypto.h +++ b/client/src/crypto/libpcrypto.h @@ -61,5 +61,7 @@ void bin_xor(uint8_t *d1, const uint8_t *d2, size_t len); void AddISO9797M2Padding(uint8_t *ddata, size_t *ddatalen, uint8_t *sdata, size_t sdatalen, size_t blocklen); size_t FindISO9797M2PaddingDataLen(const uint8_t *data, size_t datalen); +// BLOWFISH +int blowfish_decrypt(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length); #endif /* libpcrypto.h */ diff --git a/client/src/emv/tlv.c b/client/src/emv/tlv.c index 64a3c0a1b..f22bfea4c 100644 --- a/client/src/emv/tlv.c +++ b/client/src/emv/tlv.c @@ -23,19 +23,20 @@ #endif #include "tlv.h" - #include #include #include +#include -#define TLV_TAG_CLASS_MASK 0xc0 + +#define TLV_TAG_CLASS_MASK 0xC0 #define TLV_TAG_COMPLEX 0x20 -#define TLV_TAG_VALUE_MASK 0x1f -#define TLV_TAG_VALUE_CONT 0x1f +#define TLV_TAG_VALUE_MASK 0x1F +#define TLV_TAG_VALUE_CONT 0x1F #define TLV_TAG_INVALID 0 #define TLV_LEN_LONG 0x80 -#define TLV_LEN_MASK 0x7f +#define TLV_LEN_MASK 0x7F #define TLV_LEN_INVALID (~0) // http://radek.io/2012/11/10/magical-container_of-macro/ diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 49ea6c312..3dee474c0 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -83,7 +83,7 @@ DumpFileType_t getfiletype(const char *filename) { } else if (str_endswith(s, "json")) { o = JSON; } else if (str_endswith(s, "dic")) { - o = DICTIONARY; + o = DICTIONARY; } else { // mfd, trc, trace is binary o = BIN; @@ -1916,4 +1916,11 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl } return res; -} \ No newline at end of file +} + +int pm3_save_dump(const char *fn, uint8_t *d, size_t n, JSONFileType jsft, size_t blocksize) { + saveFile(fn, ".bin", d, n); + saveFileEML(fn, d, n, blocksize); + saveFileJSON(fn, jsft, d, n, NULL); + return PM3_SUCCESS; +} diff --git a/client/src/fileutils.h b/client/src/fileutils.h index ebc6e6a4a..c440c7c26 100644 --- a/client/src/fileutils.h +++ b/client/src/fileutils.h @@ -272,4 +272,5 @@ DumpFileType_t getfiletype(const char *filename); */ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumplen); +int pm3_save_dump(const char *fn, uint8_t *d, size_t n, JSONFileType jsft, size_t blocksize); #endif // FILEUTILS_H diff --git a/client/src/mifare/mad.c b/client/src/mifare/mad.c index 759f5540a..61843542a 100644 --- a/client/src/mifare/mad.c +++ b/client/src/mifare/mad.c @@ -403,4 +403,4 @@ bool HasMADKey(uint8_t *d) { return false; return (memcmp(d + (3 * MFBLOCK_SIZE), g_mifare_mad_key, sizeof(g_mifare_mad_key)) == 0); -} \ No newline at end of file +}