TEA encryption with 128bit key

时间:2022-09-20 09:26:02

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&sol;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. &lbrack;JavaSecurity&rsqb; - 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&colon; 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&colon;&sol;&sol;www&period;coderanch&period;com&sol;how-to&sol;content&sol;AES&lowbar;v1&period;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. &lbrack;转载&rsqb; TLS协议分析 与 现代加密通信协议设计

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

随机推荐

  1. Yii2 – 如何写一个插件 , 如何做一个扩展

    原文地址: http://www.fancyecommerce.com/2016/05/10/yii2-%E5%A6%82%E4%BD%95%E5%86%99%E4%B8%80%E4%B8%AA%E6 ...

  2. C Primer Plus&lowbar;第四章&lowbar;字符串和格式化输入输出&lowbar;编程练习

    Practice 1.输入名字和姓氏,以"名字,姓氏"的格式输出打印. #include int main(void) { char name[20]; char family[2 ...

  3. wndows系统命令总结

    window8系统下 打开运行窗口----------鼠标放到任务栏的windows图标下,右击,弹出菜单中如上图或者 打开运行窗口---------按“WIN+R”键, cmd-------打开命令 ...

  4. MySQL存储引擎总结

    MySQL存储引擎总结 作者:果冻想 字体:[增加 减小] 类型:转载   这篇文章主要介绍了MySQL存储引擎总结,本文讲解了什么是存储引擎.MyISAM.InnoDB.MEMORY.MERGE等内 ...

  5. CSS样式设置记录

    在不懂php和wordpress的情况下,需要按照样式内容用php+wordpress+mysql做个网站,网页上有许多样式需要设置,包括颜色字体等要跟要求一致,记录下今天的结果. <div i ...

  6. sqlserver表分区与调优与行列转换

    转自: http://www.cnblogs.com/knowledgesea/p/3696912.html http://www.open-open.com/lib/view/open1418462 ...

  7. Linux 模拟 鼠标 键盘 事件

    /************************************************************************ * Linux 模拟 鼠标 键盘 事件 * 说明: ...

  8. Cocos2d-x 安装教程for mac(Xcode)

    cocos2d v3.x 版本出来后,从配置安装到创建项目都是命令行,下面简单说一下. 1. 下载地址    http://cn.cocos2d-x.org/download/ (虽然没有标明 for ...

  9. tomcat启动时间过长的问题

    阿里云下的服务器安装jdk1.8和tomcat之后出现了一个问题,初次运行tomcat没有问题,可以正常访问tomcat首页,但是关闭之后再重启就发现tomcat首页刷不出来.而且再次关闭之后还报错了 ...

  10. &lbrack;LeetCode&rsqb; Continuous Subarray Sum 连续的子数组之和

    Given a list of non-negative numbers and a target integer k, write a function to check if the array ...