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的更多相关文章

  1. SQL Server安全(8/11):数据加密(Data Encryption)

    在保密你的服务器和数据,防备当前复杂的攻击,SQL Server有你需要的一切.但在你能有效使用这些安全功能前,你需要理解你面对的威胁和一些基本的安全概念.这篇文章提供了基础,因此你可以对SQL Se ...

  2. 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 ...

  3. mysql表空间加密 keyring encryption

    从5.7.11开始,mysql开始支持物理表空间的加密,它使用两层加密架构.包括:master key 和 tablespace key master key用于加密tablespace key,加密 ...

  4. TEA加密算法java版

    这个算法简单,而且效率高,每次可以操作8个字节的数据,加密解密的KEY为16字节,即包含4个int数据的int型数组,加密轮数应为8的倍数,一般比较常用的轮数为64,32,16,推荐用64轮. 源代码 ...

  5. [JavaSecurity] - AES Encryption

    1. AES Algorithm The Advanced Encryption Standard (AES), also as known as Rijndael (its original nam ...

  6. 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 ...

  7. 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 ...

  8. 【openwrt】再设置

    https://wiki.openwrt.org/zh-cn/doc/uci/network https://wiki.openwrt.org/zh-cn/doc/uci/wireless https ...

  9. [转载] TLS协议分析 与 现代加密通信协议设计

    https://blog.helong.info/blog/2015/09/06/tls-protocol-analysis-and-crypto-protocol-design/?from=time ...

随机推荐

  1. Codeforces 463D Gargari and Permutations

    http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...

  2. 【转】linux tree命令以树形结构显示文件目录结构 ---- 不错

    原文网址:http://jingyan.baidu.com/article/acf728fd19c7eff8e510a3eb.html 今天小编来给分享Linux 系统下一个非常有用的命令的使用:tr ...

  3. c#实现文件拖放

    1. 选择form窗口,在事件分别双击双击DragDrop和DragEnter private void Form1_DragDrop(object sender, DragEventArgs e) ...

  4. JS的substr与substring的区别

    substr返回从指定位置开始的指定长度的子字符串 str.substr(star[,length])  第二个参数可选,不选的话,截取到最后,如果length为0或者负数,那么返回的将是一个空字符串 ...

  5. C++字符串指针与字符数组的区别

    今天发现这样一个问题 #include <iostream> using namespace std; int main() { ]; strcpy_s(ch1,");//编译通 ...

  6. Using HTML5 audio and video

    From:https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_HTML5_audio_and_video Using HTML5 ...

  7. UVa 11401 三角形的个数

    题意:由1,2,3...n组成的序列中找三个数,且以这三个数为变长能组成三角形,求这样的三角形个数. 思路:当每次输入n时重新都计算一遍会TLE...先预处理,将结果存入ans数组. 代码: #inc ...

  8. bzoj2049-洞穴勘测(动态树lct模板题)

    Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...

  9. MVC中使用EF(1):为ASP.NET MVC程序创建Entity Framework数据模型

    为ASP.NET MVC程序创建Entity Framework数据模型 (1 of 10) By  Tom Dykstra |July 30, 2013 Translated by litdwg   ...

  10. [置顶] Objective-C ,ios,iphone开发基础:自定义控件:Eg: UIButton

    第一步:新建一个工程,在 .h文件中坐如下声明: #import <UIKit/UIKit.h> @interface MyButtonViewController : UIViewCon ...