From 99bc47c1acf74d0bb6574b0884ce17023491c8c2 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Fri, 13 Aug 2021 21:27:46 +0300 Subject: [PATCH] add module --- client/CMakeLists.txt | 1 + client/Makefile | 1 + client/src/crypto/libpcrypto.h | 3 +++ client/src/mifare/desfirecrypto.h | 1 - client/src/mifare/lrpcrypto.c | 28 ++++++++++++++++++++++++++ client/src/mifare/lrpcrypto.h | 33 +++++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 client/src/mifare/lrpcrypto.c create mode 100644 client/src/mifare/lrpcrypto.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 4eca55906..ec9bebde2 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -228,6 +228,7 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/mifare/mifaredefault.c ${PM3_ROOT}/client/src/mifare/mifarehost.c ${PM3_ROOT}/client/src/nfc/ndef.c + ${PM3_ROOT}/client/src/mifare/lrpcrypto.c ${PM3_ROOT}/client/src/mifare/desfirecrypto.c ${PM3_ROOT}/client/src/mifare/desfiresecurechan.c ${PM3_ROOT}/client/src/mifare/desfirecore.c diff --git a/client/Makefile b/client/Makefile index ef9913149..33b624388 100644 --- a/client/Makefile +++ b/client/Makefile @@ -588,6 +588,7 @@ SRCS = mifare/aiddesfire.c \ loclass/cipherutils.c \ loclass/elite_crack.c \ loclass/ikeys.c \ + mifare/lrpcrypto.c \ mifare/desfirecrypto.c \ mifare/desfirecore.c \ mifare/desfiresecurechan.c \ diff --git a/client/src/crypto/libpcrypto.h b/client/src/crypto/libpcrypto.h index c589f61f6..89f13f486 100644 --- a/client/src/crypto/libpcrypto.h +++ b/client/src/crypto/libpcrypto.h @@ -16,6 +16,9 @@ #include #include +#define CRYPTO_AES_BLOCK_SIZE 16 +#define CRYPTO_AES128_KEY_SIZE 16 + 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); diff --git a/client/src/mifare/desfirecrypto.h b/client/src/mifare/desfirecrypto.h index df5d22d71..a5de60a87 100644 --- a/client/src/mifare/desfirecrypto.h +++ b/client/src/mifare/desfirecrypto.h @@ -24,7 +24,6 @@ #include "common.h" #include "crypto/libpcrypto.h" -#define CRYPTO_AES_BLOCK_SIZE 16 #define MAX_CRYPTO_BLOCK_SIZE 16 #define DESFIRE_MAX_CRYPTO_BLOCK_SIZE 16 #define DESFIRE_MAX_KEY_SIZE 24 diff --git a/client/src/mifare/lrpcrypto.c b/client/src/mifare/lrpcrypto.c new file mode 100644 index 000000000..3f656d396 --- /dev/null +++ b/client/src/mifare/lrpcrypto.c @@ -0,0 +1,28 @@ +/*- + * Copyright (C) 2021 Merlok + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * + * $Id$ + */ + +#include "lrpcrypto.h" + +#include +#include +#include +#include "ui.h" +#include "aes.h" +#include "commonutil.h" + diff --git a/client/src/mifare/lrpcrypto.h b/client/src/mifare/lrpcrypto.h new file mode 100644 index 000000000..25369b36d --- /dev/null +++ b/client/src/mifare/lrpcrypto.h @@ -0,0 +1,33 @@ +/*- + * Copyright (C) 2021 Merlok + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * + * $Id$ + */ + +#ifndef __LRPCRYPTO_H +#define __LRPCRYPTO_H + +#include "common.h" +#include "crypto/libpcrypto.h" + +typedef struct { + uint8_t key[CRYPTO_AES128_KEY_SIZE]; +} LRPContext; + +void LRPSetKey(LRPContext *ctx); + + +#endif // __LRPCRYPTO_H