minors stuff, added some blowfish decrypt

This commit is contained in:
iceman1001 2022-06-06 12:59:09 +02:00
parent 2c06054881
commit 2c61530cba
6 changed files with 37 additions and 8 deletions

View file

@ -33,6 +33,7 @@
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/entropy.h>
#include <mbedtls/error.h>
#include <mbedtls/blowfish.h>
#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;
}

View file

@ -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 */

View file

@ -23,19 +23,20 @@
#endif
#include "tlv.h"
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#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/

View file

@ -1917,3 +1917,10 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl
return res;
}
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;
}

View file

@ -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