mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
Merge pull request #1353 from merlokk/crypto_changes
move des functions to pcrypto
This commit is contained in:
commit
9d8ef863c3
7 changed files with 51 additions and 40 deletions
|
@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
|
||||||
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
||||||
|
|
||||||
## [unreleased][unreleased]
|
## [unreleased][unreleased]
|
||||||
|
- Fix - move des functions to libcrypto (@merlokk)
|
||||||
- Added `CLIGetOptionList` to cliparser that makes it easier to implement text options in the cli (@merlokk)
|
- Added `CLIGetOptionList` to cliparser that makes it easier to implement text options in the cli (@merlokk)
|
||||||
- Added experimental support for macOS users utilizing MacPorts instead of Homebrew (@linuxgemini)
|
- Added experimental support for macOS users utilizing MacPorts instead of Homebrew (@linuxgemini)
|
||||||
- Added `pm3_online_check.py` - a script to verify and initialize a Proxmark3 RDV4 device (@iceman1001)
|
- Added `pm3_online_check.py` - a script to verify and initialize a Proxmark3 RDV4 device (@iceman1001)
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
#include "protocols.h" // definitions of ISO14A/7816 protocol
|
#include "protocols.h" // definitions of ISO14A/7816 protocol
|
||||||
#include "iso7816/apduinfo.h" // GetAPDUCodeDescription
|
#include "iso7816/apduinfo.h" // GetAPDUCodeDescription
|
||||||
#include "iso7816/iso7816core.h" // Iso7816ExchangeEx etc
|
#include "iso7816/iso7816core.h" // Iso7816ExchangeEx etc
|
||||||
#include "crypto/libpcrypto.h" // Hash calculation (sha1, sha256, sha512)
|
#include "crypto/libpcrypto.h" // Hash calculation (sha1, sha256, sha512), des_encrypt/des_decrypt
|
||||||
#include "mifare/desfire_crypto.h" // des_encrypt/des_decrypt
|
|
||||||
#include "des.h" // mbedtls_des_key_set_parity
|
#include "des.h" // mbedtls_des_key_set_parity
|
||||||
#include "crapto1/crapto1.h" // prng_successor
|
#include "crapto1/crapto1.h" // prng_successor
|
||||||
#include "commonutil.h" // num_to_bytes
|
#include "commonutil.h" // num_to_bytes
|
||||||
|
@ -263,20 +262,6 @@ static int emrtd_get_asn1_field_length(uint8_t *datain, int datainlen, int offse
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void des_encrypt_ecb(uint8_t *key, uint8_t *input, uint8_t *output) {
|
|
||||||
mbedtls_des_context ctx_enc;
|
|
||||||
mbedtls_des_setkey_enc(&ctx_enc, key);
|
|
||||||
mbedtls_des_crypt_ecb(&ctx_enc, input, output);
|
|
||||||
mbedtls_des_free(&ctx_enc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void des_decrypt_ecb(uint8_t *key, uint8_t *input, uint8_t *output) {
|
|
||||||
mbedtls_des_context ctx_dec;
|
|
||||||
mbedtls_des_setkey_dec(&ctx_dec, key);
|
|
||||||
mbedtls_des_crypt_ecb(&ctx_dec, input, output);
|
|
||||||
mbedtls_des_free(&ctx_dec);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void des3_encrypt_cbc(uint8_t *iv, uint8_t *key, uint8_t *input, int inputlen, uint8_t *output) {
|
static void des3_encrypt_cbc(uint8_t *iv, uint8_t *key, uint8_t *input, int inputlen, uint8_t *output) {
|
||||||
mbedtls_des3_context ctx;
|
mbedtls_des3_context ctx;
|
||||||
mbedtls_des3_set2key_enc(&ctx, key);
|
mbedtls_des3_set2key_enc(&ctx, key);
|
||||||
|
@ -345,15 +330,15 @@ static void retail_mac(uint8_t *key, uint8_t *input, int inputlen, uint8_t *outp
|
||||||
intermediate[x] = intermediate[x] ^ block[x];
|
intermediate[x] = intermediate[x] ^ block[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
des_encrypt_ecb(k0, intermediate, intermediate_des);
|
des_encrypt(intermediate_des, intermediate, k0);
|
||||||
memcpy(intermediate, intermediate_des, 8);
|
memcpy(intermediate, intermediate_des, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
des_decrypt_ecb(k1, intermediate, intermediate_des);
|
des_decrypt(intermediate_des, intermediate, k1);
|
||||||
memcpy(intermediate, intermediate_des, 8);
|
memcpy(intermediate, intermediate_des, 8);
|
||||||
|
|
||||||
des_encrypt_ecb(k0, intermediate, intermediate_des);
|
des_encrypt(intermediate_des, intermediate, k0);
|
||||||
memcpy(output, intermediate_des, 8);
|
memcpy(output, intermediate_des, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "protocols.h"
|
#include "protocols.h"
|
||||||
#include "util_posix.h" // msclock
|
#include "util_posix.h" // msclock
|
||||||
#include "cmdhfmfhard.h"
|
#include "cmdhfmfhard.h"
|
||||||
#include "des.h" // des ecb
|
|
||||||
#include "crapto1/crapto1.h" // prng_successor
|
#include "crapto1/crapto1.h" // prng_successor
|
||||||
#include "cmdhf14a.h" // exchange APDU
|
#include "cmdhf14a.h" // exchange APDU
|
||||||
#include "crypto/libpcrypto.h"
|
#include "crypto/libpcrypto.h"
|
||||||
|
@ -5645,12 +5644,6 @@ static int CmdHf14AGen3Freeze(const char *Cmd) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void des_decrypt(void *out, const void *in, const void *key) {
|
|
||||||
mbedtls_des_context ctx;
|
|
||||||
mbedtls_des_setkey_dec(&ctx, key);
|
|
||||||
mbedtls_des_crypt_ecb(&ctx, in, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int CmdHf14AMfSuperCard(const char *Cmd) {
|
static int CmdHf14AMfSuperCard(const char *Cmd) {
|
||||||
|
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <mbedtls/asn1.h>
|
#include <mbedtls/asn1.h>
|
||||||
|
#include <mbedtls/des.h>
|
||||||
#include <mbedtls/aes.h>
|
#include <mbedtls/aes.h>
|
||||||
#include <mbedtls/cmac.h>
|
#include <mbedtls/cmac.h>
|
||||||
#include <mbedtls/pk.h>
|
#include <mbedtls/pk.h>
|
||||||
|
@ -27,6 +28,43 @@
|
||||||
#include <mbedtls/error.h>
|
#include <mbedtls/error.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
|
void des_encrypt(void *out, const void *in, const void *key) {
|
||||||
|
mbedtls_des_context ctx;
|
||||||
|
mbedtls_des_setkey_enc(&ctx, key);
|
||||||
|
mbedtls_des_crypt_ecb(&ctx, in, out);
|
||||||
|
mbedtls_des_free(&ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void des_decrypt(void *out, const void *in, const void *key) {
|
||||||
|
mbedtls_des_context ctx;
|
||||||
|
mbedtls_des_setkey_dec(&ctx, key);
|
||||||
|
mbedtls_des_crypt_ecb(&ctx, in, out);
|
||||||
|
mbedtls_des_free(&ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void des_encrypt_ecb(void *out, const void *in, const int length, const void *key) {
|
||||||
|
for (int i = 0; i < length; i += 8)
|
||||||
|
des_encrypt((uint8_t *)out + i, (uint8_t *)in + i, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void des_decrypt_ecb(void *out, const void *in, const int length, const void *key) {
|
||||||
|
for (int i = 0; i < length; i += 8)
|
||||||
|
des_decrypt((uint8_t *)out + i, (uint8_t *)in + i, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void des_encrypt_cbc(void *out, const void *in, const int length, const void *key, uint8_t *iv) {
|
||||||
|
mbedtls_des_context ctx;
|
||||||
|
mbedtls_des_setkey_enc(&ctx, key);
|
||||||
|
mbedtls_des_crypt_cbc(&ctx, MBEDTLS_DES_ENCRYPT, length, iv, in, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void des_decrypt_cbc(void *out, const void *in, const int length, const void *key, uint8_t *iv) {
|
||||||
|
mbedtls_des_context ctx;
|
||||||
|
mbedtls_des_setkey_dec(&ctx, key);
|
||||||
|
mbedtls_des_crypt_cbc(&ctx, MBEDTLS_DES_DECRYPT, length, iv, in, out);
|
||||||
|
}
|
||||||
|
|
||||||
// NIST Special Publication 800-38A — Recommendation for block cipher modes of operation: methods and techniques, 2001.
|
// NIST Special Publication 800-38A — Recommendation for block cipher modes of operation: methods and techniques, 2001.
|
||||||
int aes_encode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length) {
|
int aes_encode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length) {
|
||||||
uint8_t iiv[16] = {0};
|
uint8_t iiv[16] = {0};
|
||||||
|
|
|
@ -16,6 +16,13 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <mbedtls/pk.h>
|
#include <mbedtls/pk.h>
|
||||||
|
|
||||||
|
void des_encrypt(void *out, const void *in, const void *key);
|
||||||
|
void des_decrypt(void *out, const void *in, const void *key);
|
||||||
|
void des_encrypt_ecb(void *out, const void *in, const int length, const void *key);
|
||||||
|
void des_decrypt_ecb(void *out, const void *in, const int length, const void *key);
|
||||||
|
void des_encrypt_cbc(void *out, const void *in, const int length, const void *key, uint8_t *iv);
|
||||||
|
void des_decrypt_cbc(void *out, const void *in, const int length, const void *key, uint8_t *iv);
|
||||||
|
|
||||||
int aes_encode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length);
|
int aes_encode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length);
|
||||||
int aes_decode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length);
|
int aes_decode(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output, int length);
|
||||||
int aes_cmac(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *mac, int length);
|
int aes_cmac(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *mac, int length);
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include "commonutil.h"
|
#include "commonutil.h"
|
||||||
|
#include "crypto/libpcrypto.h"
|
||||||
#include "aes.h"
|
#include "aes.h"
|
||||||
#include "des.h"
|
#include "des.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
@ -53,18 +54,6 @@ static inline void update_key_schedules(desfirekey_t key) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void des_encrypt(void *out, const void *in, const void *key) {
|
|
||||||
mbedtls_des_context ctx;
|
|
||||||
mbedtls_des_setkey_enc(&ctx, key);
|
|
||||||
mbedtls_des_crypt_ecb(&ctx, in, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
void des_decrypt(void *out, const void *in, const void *key) {
|
|
||||||
mbedtls_des_context ctx;
|
|
||||||
mbedtls_des_setkey_dec(&ctx, key);
|
|
||||||
mbedtls_des_crypt_ecb(&ctx, in, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tdes_nxp_receive(const void *in, void *out, size_t length, const void *key, unsigned char iv[8], int keymode) {
|
void tdes_nxp_receive(const void *in, void *out, size_t length, const void *key, unsigned char iv[8], int keymode) {
|
||||||
if (length % 8)
|
if (length % 8)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -102,8 +102,6 @@ typedef unsigned long DES3_KS[48][2]; /* Triple-DES key schedule */
|
||||||
|
|
||||||
extern int Asmversion; /* 1 if we're linked with an asm version, 0 if C */
|
extern int Asmversion; /* 1 if we're linked with an asm version, 0 if C */
|
||||||
|
|
||||||
void des_encrypt(void *out, const void *in, const void *key);
|
|
||||||
void des_decrypt(void *out, const void *in, const void *key);
|
|
||||||
void tdes_nxp_receive(const void *in, void *out, size_t length, const void *key, unsigned char iv[8], int keymode);
|
void tdes_nxp_receive(const void *in, void *out, size_t length, const void *key, unsigned char iv[8], int keymode);
|
||||||
void tdes_nxp_send(const void *in, void *out, size_t length, const void *key, unsigned char iv[8], int keymode);
|
void tdes_nxp_send(const void *in, void *out, size_t length, const void *key, unsigned char iv[8], int keymode);
|
||||||
void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key);
|
void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue