diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index a84415814..e377616f8 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -341,10 +341,8 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/pm3_binlib.c ${PM3_ROOT}/client/src/pm3_bitlib.c ${PM3_ROOT}/client/src/pm3line.c - ${PM3_ROOT}/client/src/prng.c ${PM3_ROOT}/client/src/scandir.c ${PM3_ROOT}/client/src/scripting.c - ${PM3_ROOT}/client/src/tea.c ${PM3_ROOT}/client/src/ui.c ${PM3_ROOT}/client/src/util.c ${PM3_ROOT}/client/src/wiegand_formats.c diff --git a/client/Makefile b/client/Makefile index 1a11b2fe2..905609b36 100644 --- a/client/Makefile +++ b/client/Makefile @@ -634,14 +634,12 @@ SRCS = mifare/aiddesfire.c \ pm3_binlib.c \ pm3_bitlib.c \ preferences.c \ - prng.c \ pm3line.c \ proxmark3.c \ scandir.c \ uart/uart_posix.c \ uart/uart_win32.c \ scripting.c \ - tea.c \ ui.c \ util.c \ version_pm3.c \ diff --git a/client/experimental_lib/CMakeLists.txt b/client/experimental_lib/CMakeLists.txt index ac455eaec..a31a3110d 100644 --- a/client/experimental_lib/CMakeLists.txt +++ b/client/experimental_lib/CMakeLists.txt @@ -342,10 +342,8 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/pm3_binlib.c ${PM3_ROOT}/client/src/pm3_bitlib.c ${PM3_ROOT}/client/src/pm3line.c - ${PM3_ROOT}/client/src/prng.c ${PM3_ROOT}/client/src/scandir.c ${PM3_ROOT}/client/src/scripting.c - ${PM3_ROOT}/client/src/tea.c ${PM3_ROOT}/client/src/ui.c ${PM3_ROOT}/client/src/util.c ${PM3_ROOT}/client/src/wiegand_formats.c diff --git a/client/src/cmdanalyse.c b/client/src/cmdanalyse.c index 5de3bc063..a2ebf9d23 100644 --- a/client/src/cmdanalyse.c +++ b/client/src/cmdanalyse.c @@ -29,7 +29,6 @@ #include "crc.h" #include "crc16.h" // crc16 ccitt #include "crc32.h" // crc32_ex -#include "tea.h" #include "legic_prng.h" #include "cmddata.h" // g_DemodBuffer #include "graph.h" @@ -489,55 +488,6 @@ static int CmdAnalyseDates(const char *Cmd) { return PM3_SUCCESS; } -static int CmdAnalyseTEASelfTest(const char *Cmd) { - CLIParserContext *ctx; - CLIParserInit(&ctx, "analyse tea", - "Crypto TEA self tests", - "analyse tea -d 1122334455667788" - ); - - void *argtable[] = { - arg_param_begin, - arg_str1("d", "data", "", "bytes to encrypt ( 8 hex bytes )"), - arg_param_end - }; - CLIExecWithReturn(ctx, Cmd, argtable, true); - int dlen = 0; - uint8_t data[8] = {0x00}; - int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, sizeof(data), &dlen); - CLIParserFree(ctx); - if (res) { - PrintAndLogEx(FAILED, "Error parsing bytes"); - return PM3_EINVARG; - } - - uint8_t v_le[8]; - memset(v_le, 0x00, sizeof(v_le)); - uint8_t *v_ptr = v_le; - - SwapEndian64ex(data, 8, 4, v_ptr); - - // ENCRYPTION KEY: - uint8_t key[16] = {0x55, 0xFE, 0xF6, 0x30, 0x62, 0xBF, 0x0B, 0xC1, 0xC9, 0xB3, 0x7C, 0x34, 0x97, 0x3E, 0x29, 0xFB }; - uint8_t keyle[16]; - uint8_t *key_ptr = keyle; - SwapEndian64ex(key, sizeof(key), 4, key_ptr); - - PrintAndLogEx(INFO, "TEA crypto testing"); - PrintAndLogEx(INFO, "-----------------------------------+---------"); - PrintAndLogEx(INFO, "LE enc.... %s", sprint_hex_ascii(v_ptr, 8)); - - tea_decrypt(v_ptr, key_ptr); - PrintAndLogEx(INFO, "LE dec.... %s", sprint_hex_ascii(v_ptr, 8)); - - tea_encrypt(v_ptr, key_ptr); - PrintAndLogEx(INFO, "enc1...... %s", sprint_hex_ascii(v_ptr, 8)); - tea_encrypt(v_ptr, key_ptr); - PrintAndLogEx(INFO, "enc2...... %s", sprint_hex_ascii(v_ptr, 8)); - PrintAndLogEx(NORMAL, ""); - return PM3_SUCCESS; -} - static int CmdAnalyseA(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "analyse a", @@ -1205,7 +1155,6 @@ static command_t CommandTable[] = { {"crc", CmdAnalyseCRC, AlwaysAvailable, "Stub method for CRC evaluations"}, {"chksum", CmdAnalyseCHKSUM, AlwaysAvailable, "Checksum with adding, masking and one's complement"}, {"dates", CmdAnalyseDates, AlwaysAvailable, "Look for datestamps in a given array of bytes"}, - {"tea", CmdAnalyseTEASelfTest, AlwaysAvailable, "Crypto TEA test"}, {"lfsr", CmdAnalyseLfsr, AlwaysAvailable, "LFSR tests"}, {"a", CmdAnalyseA, AlwaysAvailable, "num bits test"}, {"nuid", CmdAnalyseNuid, AlwaysAvailable, "create NUID from 7byte UID"}, diff --git a/client/src/prng.c b/client/src/prng.c deleted file mode 100644 index bfea60504..000000000 --- a/client/src/prng.c +++ /dev/null @@ -1,53 +0,0 @@ -//----------------------------------------------------------------------------- -// Borrowed initially from http://burtleburtle.net/bob/rand/smallprng.html -// Copyright (C) Bob Jenkins -// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU 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. -// -// See LICENSE.txt for the text of the license. -//----------------------------------------------------------------------------- -// Burtle Prng - Modified. 42iterations instead of 20. -//----------------------------------------------------------------------------- -#include "prng.h" - -#define rot(x,k) (((x)<<(k))|((x)>>(32-(k)))) -uint32_t burtle_get_mod(prng_ctx_t *x) { - uint32_t e = x->a - rot(x->b, 21); - x->a = x->b ^ rot(x->c, 19); - x->b = x->c + rot(x->d, 6); - x->c = x->d + e; - x->d = e + x->a; - return x->d; -} - -void burtle_init_mod(prng_ctx_t *x, uint32_t seed) { - x->a = 0xf1ea5eed; - x->b = x->c = x->d = seed; - for (uint8_t i = 0; i < 42; ++i) { - (void)burtle_get_mod(x); - } -} - -void burtle_init(prng_ctx_t *x, uint32_t seed) { - uint32_t i; - x->a = 0xf1ea5eed, x->b = x->c = x->d = seed; - for (i = 0; i < 20; ++i) { - (void)burtle_get_mod(x); - } -} - - -uint32_t GetSimplePrng(uint32_t seed) { - seed *= 0x19660D; - seed += 0x3C6EF35F; - return seed; -} diff --git a/client/src/prng.h b/client/src/prng.h deleted file mode 100644 index 97bd83ac7..000000000 --- a/client/src/prng.h +++ /dev/null @@ -1,40 +0,0 @@ -//----------------------------------------------------------------------------- -// Borrowed initially from http://burtleburtle.net/bob/rand/smallprng.html -// Copyright (C) Bob Jenkins -// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU 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. -// -// See LICENSE.txt for the text of the license. -//----------------------------------------------------------------------------- -// Burtle Prng - Modified. 42iterations instead of 20. -//----------------------------------------------------------------------------- - -#ifndef __PRNG_H -#define __PRNG_H - -#include "common.h" - -typedef struct { - uint32_t a; - uint32_t b; - uint32_t c; - uint32_t d; -} prng_ctx_t; - -//uint32_t burtle_get( prng_ctx_t *x ); -uint32_t burtle_get_mod(prng_ctx_t *x); -void burtle_init_mod(prng_ctx_t *x, uint32_t seed); -void burtle_init(prng_ctx_t *x, uint32_t seed); - -uint32_t GetSimplePrng(uint32_t seed); - -#endif /* __PRNG_H */ diff --git a/client/src/tea.c b/client/src/tea.c deleted file mode 100644 index ae5aa366d..000000000 --- a/client/src/tea.c +++ /dev/null @@ -1,79 +0,0 @@ -//----------------------------------------------------------------------------- -// Borrowed initially from -// https://web.archive.org/web/20070920142755/http://www.simonshepherd.supanet.com:80/source.htm#ansi -// Copyright (C) Simon Shepherd 2003 -// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU 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. -// -// See LICENSE.txt for the text of the license. -//----------------------------------------------------------------------------- -// Generic TEA crypto code. -//----------------------------------------------------------------------------- -#include "tea.h" - -#include "commonutil.h" // bytes_to_num etc - -#define ROUNDS 32 -#define DELTA 0x9E3779B9 -#define SUM 0xC6EF3720 - -void tea_encrypt(uint8_t *v, uint8_t *key) { - - uint32_t a = 0, b = 0, c = 0, d = 0, y = 0, z = 0; - uint32_t sum = 0; - uint8_t n = ROUNDS; - - //key - a = bytes_to_num(key, 4); - b = bytes_to_num(key + 4, 4); - c = bytes_to_num(key + 8, 4); - d = bytes_to_num(key + 12, 4); - - //input - y = bytes_to_num(v, 4); - z = bytes_to_num(v + 4, 4); - - while (n-- > 0) { - sum += DELTA; - y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); - z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); - } - - num_to_bytes(y, 4, v); - num_to_bytes(z, 4, v + 4); -} - -void tea_decrypt(uint8_t *v, uint8_t *key) { - - uint32_t a = 0, b = 0, c = 0, d = 0, y = 0, z = 0; - uint32_t sum = SUM; - uint8_t n = ROUNDS; - - //key - a = bytes_to_num(key, 4); - b = bytes_to_num(key + 4, 4); - c = bytes_to_num(key + 8, 4); - d = bytes_to_num(key + 12, 4); - - //input - y = bytes_to_num(v, 4); - z = bytes_to_num(v + 4, 4); - - /* sum = delta<<5, in general sum = delta * n */ - while (n-- > 0) { - z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); - y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); - sum -= DELTA; - } - num_to_bytes(y, 4, v); - num_to_bytes(z, 4, v + 4); -} diff --git a/client/src/tea.h b/client/src/tea.h deleted file mode 100644 index 62a67fa7b..000000000 --- a/client/src/tea.h +++ /dev/null @@ -1,30 +0,0 @@ -//----------------------------------------------------------------------------- -// Borrowed initially from -// https://web.archive.org/web/20070920142755/http://www.simonshepherd.supanet.com:80/source.htm#ansi -// Copyright (C) Simon Shepherd 2003 -// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU 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. -// -// See LICENSE.txt for the text of the license. -//----------------------------------------------------------------------------- -// Generic TEA crypto code. -//----------------------------------------------------------------------------- - -#ifndef __TEA_H -#define __TEA_H - -#include "common.h" - -void tea_encrypt(uint8_t *v, uint8_t *key); -void tea_decrypt(uint8_t *v, uint8_t *key); - -#endif /* __TEA_H */