TEA encryption with 128bit key
If anyone needs some basic encryption in software, here's one solution. This TEA implementation fits within less than 700 bytes. It's based on original TEA. P89LPC901 needs 300ms for 32 iterations. Compiled with "OPTIMIZE (9,SIZE)".
#define _DELTA 0x9E3779B9
#define _ITER 32
/* _ITER = the number of iterations.*/
/* 32 is ample, 16 is sufficient, */
/* as few as eight should be OK. */
#define _SUM 0xC6EF3720
/********************************************************************/
/* Global variables for encryption */
/********************************************************************/
unsigned long int v0,v1; /* encrypted/decrypted data */
volatile unsigned long int code
k0=0x1234aaaa, /* 128 bit key */
k1=0x5678bbbb, /* hard coded in internal */
k2=0x9abc4321, /* flash memory */
k3=0xdef0ffff; /* Same key used by host */
/********************************************************************/
/* */
/* TEA : The Tiny Encryption Algorithm (TEA) */
/* ba David Wheeler and Roger Needham at the Computer */
/* Laboratory of Cambridge University */
/* More info: http://www.simonshepherd.supanet.com/tea.htm */
/* */
/* TEA_decipher - decryption procedure */
/* uses global variables */
/* */
/* Source ported to Keil C51 by Marko Pavlin */
/********************************************************************/
void TEA_decipher(void)
{
unsigned long int sum=_SUM, delta=_DELTA;
unsigned char n = _ITER;
)
{
v1 -= (v0 << )+k2 ^ v0+sum ^ (v0 >> )+k3;
v0 -= (v1 << )+k0 ^ v1+sum ^ (v1 >> )+k1;
sum -= delta;
}
}
/********************************************************************/
/* */
/* TEA : The Tiny Encryption Algorithm (TEA) */
/* */
/* TEA_encipher - encryption procedure */
/* uses global variables */
/* */
/********************************************************************/
void TEA_encipher(void)
{
unsigned ,delta=_DELTA;
unsigned char n=_ITER;
)
{
sum += delta;
v0 += (v1 << )+k0 ^ v1+sum ^ (v1 >> )+k1;
v1 += (v0 << )+k2 ^ v0+sum ^ (v0 >> )+k3;
}
}
Variables are global. If there's enough memory available, use pointer parameters for key and data (adds about 400 bytes for pointer opertions).
Works with 16 bit (unsigned int), too. In this case replace constants with:
#define _DELTA 0x9E37 #define _SUM 0xC6EF
But key in this case is only 64bit.
TEA encryption with 128bit key的更多相关文章
- SQL Server安全(8/11):数据加密(Data Encryption)
在保密你的服务器和数据,防备当前复杂的攻击,SQL Server有你需要的一切.但在你能有效使用这些安全功能前,你需要理解你面对的威胁和一些基本的安全概念.这篇文章提供了基础,因此你可以对SQL Se ...
- GSM cell phone calls use outdated encryption that can now be cracked with rainbow tables on a PC
Decrypting GSM phone calls Motivation. GSM telephony is the world’s most popular communication techn ...
- mysql表空间加密 keyring encryption
从5.7.11开始,mysql开始支持物理表空间的加密,它使用两层加密架构.包括:master key 和 tablespace key master key用于加密tablespace key,加密 ...
- TEA加密算法java版
这个算法简单,而且效率高,每次可以操作8个字节的数据,加密解密的KEY为16字节,即包含4个int数据的int型数组,加密轮数应为8的倍数,一般比较常用的轮数为64,32,16,推荐用64轮. 源代码 ...
- [JavaSecurity] - AES Encryption
1. AES Algorithm The Advanced Encryption Standard (AES), also as known as Rijndael (its original nam ...
- Overview and Evaluation of Bluetooth Low Energy: An Emerging Low-Power Wireless Technology
转自:http://www.mdpi.com/1424-8220/12/9/11734/htm Sensors 2012, 12(9), 11734-11753; doi:10.3390/s12091 ...
- AESwithJCE http://www.coderanch.com/how-to/content/AES_v1.html
Using AES with Java Technology By Rags SrinivasJune 2003 In September 2000, the National Institute o ...
- 【openwrt】再设置
https://wiki.openwrt.org/zh-cn/doc/uci/network https://wiki.openwrt.org/zh-cn/doc/uci/wireless https ...
- [转载] TLS协议分析 与 现代加密通信协议设计
https://blog.helong.info/blog/2015/09/06/tls-protocol-analysis-and-crypto-protocol-design/?from=time ...
随机推荐
- 2015北大夏令营day1 B:An Idea of Mr. A
题意:给定一个范围l,r计算i,j(i<j)属于这个范围内的gcd(2^(2^i)+1,2^(2^j)+1)的总和. 思路:费马数的应用,让我惊呆的是当年居然有123个人会做,我tm毛都不会.. ...
- format %x invalid or incompatible with argument问题解决方法
现在还有好多朋友在用Protel 99se来画图,可是在现在的双核或四核电脑上运行Protel出现错误并且弹出对话框:“format '%x' invalid or incompatible with ...
- cf486A Calculating Function
A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...
- RFC3261--sip
本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...
- Hdu3640-I, zombie(模拟+二分)
The "endless" model in "I, zombie" of "Plants vs. Zombies" is my favou ...
- hdu 1829 A Bug's Life(并查集)
A Bu ...
- 关于Tcp三次握手的思考
一.为什么不能使两次握手,两次握手就应该可以保证线路的畅通? 1) 只能建立一个方向的连接,称为半连接 记住TCP是全双工的. A向B发出请求,同时收到B的确认,这时只有A.B知道A到B的连接成功了. ...
- android 缓存Bitmap - 开发文档翻译
由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链接链接 Loading a single bitmap into your user interf ...
- C++ I/O标准库
C++学习: 返回指向函数的指针: int (*ff(int))(int *,int) 想写好这样的代码很难,含义:首先将ff声明为一个函数,它带有一个int形参.该函数返回 int (*)(int* ...
- SVN版本分支合并
SVN,开发中常用的工具,也没什么可说的.这里只是记录一下,以免太久不用了想用的时候又忘了. 首先已经有两个目录,一个是分支目录SVNChild,一个是主干目录SVNMain.SVNChild是从SV ...