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. BZOJ 1001 狼抓兔子

    链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子 ...

  2. 画图工具Graphviz安装配置

    Graphviz (英文:Graph Visualization Software的缩写)是一个由AT&T实验室启动的开源工具包,用于绘制DOT语言脚本描述的图形.它也提供了供其它软件使用的库 ...

  3. 深入浅出Node.js (3) - 异步I/O

    3.1 为什么要异步I/O 3.1.1 用户体验 3.1.2 资源分配 3.2 异步I/O实现现状 3.2.1 异步I/O与非阻塞I/O 3.2.2 理想的非阻塞异步I/O 3.2.3 现实的异步I/ ...

  4. c++ 02

    一.堆内存的动态分配与释放 malloc/calloc/realloc/free new/delete:详见memory.cpp 1.通过new运算符分配单个变量 数据类型* 指针变量 = new 数 ...

  5. 【CF 549G Happy Line】排序

    题目链接:http://codeforces.com/problemset/problem/549/G 题意:给定一个n个元素的整数序列a[], 任意时刻对于任一对相邻元素a[i-1]. a[i],若 ...

  6. linux之getcwd函数解析

    [lingyun@localhost getcwd]$ cat getcwd.c /********************************************************** ...

  7. MySQL学习笔记:MySQL: ERROR 1064(42000)

    ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL s ...

  8. jquery返回顶部

    // 返回顶部 var fixed_totop = $('.back_top').on('click',function(){ $('html, body').animate({scrollTop: ...

  9. vs2013 创建网站

    从文件菜单中选择新建网站,版本选择4,如果选择更高级的版本在发布的时候老是会报错,暂时找不到解决的方法,所以就选择4这个版本了.选择asp的空网站,在下面选择文件系统. 项目建好后如下,然后添加一个w ...

  10. Android SQLite的使用2(非原创)

    1.数据库的增.删.改.查:execSQL方法 public void insertAction() {//添加信息 db.execSQL("insert into Emp(name,sal ...