mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
summer restructuring:
* .h include only the strict minimum for their own parsing * this forces all files to include explicitment their needs and not count on far streched dependencies * this helps Makefile to rebuild only the minimum * according to this rule, most standalone .h are now gone * big app.h is gone * remove seldom __cplusplus, if c++ happens, everything will have to be done properly anyway * all unrequired include were removed * split common/ into common/ (client+arm) and common_arm/ (os+bootloader) * bring zlib to common/ * bring stuff not really/not yet used in common back to armsrc/ or client/ * bring liblua into client/ * bring uart into client/ * move some portions of code around (dbprint, protocols,...) * rename unused files into *_disabled.[ch] to make it explicit * rename soft Uarts between 14a, 14b and iclass, so a standalone could use several without clash * remove PrintAndLogDevice * move deprecated-hid-flasher from client to tools * Makefiles * treat deps in armsrc/ as in client/ * client: stop on warning (-Werror), same as for armsrc/ Tested on: * all standalone modes * Linux
This commit is contained in:
parent
b7d412d27b
commit
d19754567d
447 changed files with 2553 additions and 2599 deletions
67
client/tea.c
Normal file
67
client/tea.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Generic TEA crypto code.
|
||||
// ref: http://143.53.36.235:8080/source.htm#ansi
|
||||
//-----------------------------------------------------------------------------
|
||||
#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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue