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 ...
 
随机推荐
- elasticsearh 中每个节点中需要有相同的插件
			
elasticsearh 中每个节点中需要有相同的插件 [2016-09-13 19:25:24,049][INFO ][discovery.zen ] [node02] failed to send ...
 - 字符串转换为float<2>
			
Configuration OK zjtest7-frontend:/usr/local/logstash-2.3.4/config# ../bin/logstash -f g01.conf Sett ...
 - AJAX实例入门
			
一.开门见山 这些时间,瞎子也看得见,AJAX正大踏步的朝我们走来.不管我们是拥护也好,反对也罢,还是视而不见,AJAX像一阵潮流,席转了我们所有的人. 关于AJAX的定义也好,大话也好,早有人在网上 ...
 - uva10245-The Closest Pair Problem(平面上的点分治)
			
解析:平面上的点分治,先递归得到左右子区间的最小值d,再处理改区间,肯定不会考虑哪些距离已经大于d的点对,对y坐标归并排序,然后从小到大开始枚举更新d,对于某个点,x轴方向只用考虑[x-d,x+d]( ...
 - UIView 转 UIImage
			
这个方法很实用,特别是在做水印相机得时候... - (UIImage*) imageWithUIView:(UIView*) view{ // 创建一个bitmap的context // 并把它设置成 ...
 - 一步一步学数据结构之n--n(Prim算法)
			
在这里说下最小连通网的Prim算法: 而Kruskal算法,http://blog.csdn.net/nethanhan/article/details/10050735有介绍,大家可以去看下! Pr ...
 - 虚拟Linux 訪问win7共享文件夹方法
			
虚拟机訪问win7的共享文件夹 首先安装增强功能,这个不用多说 再者选择菜单中的设备->共享目录,设置为固定分配和自己主动挂载 在终端敲入命令df:发现有自己创建共享的文件夹 然后运行例如以下命 ...
 - Eclipse中使用正则屏蔽Logcat中的某些Tag
			
在使用Eclipse进行Android真机调试的时候经常会出现满屏幕的LogCat,即使设定了根据程序分类也不行 经常会有 Dalvikvm InputMethod这样的Tag出现 给自己的应用设定T ...
 - Android控件TextView的实现原理分析
			
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8636153 在前面一个系列的文章中,我们以窗口 ...
 - Unity 图片的灰度处理
			
我们平时在做项目时,经常遇到按钮的点击而且还要区分悬浮,点击,禁用的状态,美术要针对一张图片做多个状态图片,资源图片的数量也就增大了,那么打出的包的大小也就跟着上去了,所以我们可以针对原始图片进行Sh ...