3194 views|6 replies

11

Posts

0

Resources
The OP
 

Verilog implementation of TEA encryption algorithm [Copy link]

//Encryption algorithm void EncryptTEA(unsigned int *firstChunk, unsigned int *secondChunk, unsigned int* key) 2 { 3 unsigned int y = *firstChunk; 4 unsigned int z = *secondChunk; 5 unsigned int sum = 0; 6 7 unsigned int delta = 0x9e3779b9; 8 9 for (int i = 0; i < 8; i++)//8 rounds of operation (need to correspond to the same number of rounds of the decryption core function below)10 {11 sum += delta;12 y += ((z << 4) + key[0]) ^ (z + sum) ^ ((z >> 5) + key[1]);13 z += ((y << 4) + key[2]) ^ (y + sum) ^ ((y >> 5) + key[3]);14 }15 16 17 *secondChunk = z;18 } //Decryption algorithm 1 void DecryptTEA(unsigned int *firstChunk, unsigned int *secondChunk, unsigned int* key) 2 { 3 unsigned int sum = 0; 4 unsigned int y = *firstChunk; 5 unsigned int z = *secondChunk; 6 unsigned int delta = 0x9e3779b9; 7 8 sum = delta << 3; //32 rounds of operations, so it is 2 to the fifth power; 16 rounds of operations, so it is 2 to the fourth power; 8 rounds of operations, so it is 2 to the third power9 10 for (int i = 0; i < 8; i++) //8 rounds of operations11 {12 z -= (y << 4) + key[2] ^ y + sum ^ (y >> 5) + key[3];13 y -= (z << 4) + key[0] ^ z + sum ^ (z >> 5) + key[1];14 sum -= delta;15 }16 17 *firstChunk = y;18 *secondChunk = z;


This post is from FPGA/CPLD

Latest reply

Vivado has an HLS function. See if it is suitable for you. It can convert C or C++ code into Verilog, but the generated code is not very readable. There is a link in this forum. I just started watching it. In addition, how do you use the encryption chip you mentioned?  Details Published on 2019-5-14 14:19
 

11

Posts

0

Resources
2
 
  1. void encrypt(unsigned long *v, unsigned long *k) {
  2. 2     unsigned long y=v[0], z=v[1], sum=0, i;         /* set up */
  3. 3     unsigned long delta=0x9e3779b9;                 /* a key schedule constant */
  4. 4     unsigned long a=k[0], b=k[1], c=k[2], d=k[3];   /* cache key */
  5. 5     for (i=0; i < 32; i++) {                        /* basic cycle start */
  6. 6         sum += delta;
  7. 7         y += ((z<<4) + a) ^ (z + sum) ^ ((z>>5) + b);
  8. 8         z += ((y<<4) + c) ^ (y + sum) ^ ((y>>5) + d);/* end cycle */
  9. 9     }
  10. 10     v[0]=y;
  11. 11     v[1]=z;
  12. 12 }
  13. 13
  14. 14 void decrypt(unsigned long *v, unsigned long *k) {
  15. 15     unsigned long y=v[0], z=v[1], sum=0xC6EF3720, i; /* set up */
  16. 16     unsigned long delta=0x9e3779b9;                  /* a key schedule constant */
  17. 17     unsigned long a=k[0], b=k[1], c=k[2], d=k[3];    /* cache key */
  18. 18     for(i=0; i<32; i++) {                            /* basic cycle start */
  19. 19         z -= ((y<<4) + c) ^ (y + sum) ^ ((y>>5) + d);
  20. 20         y -= ((z<<4) + a) ^ (z + sum) ^ ((z>>5) + b);
  21. 21         sum -= delta;                                /* end cycle */
  22. 22     }
  23. 23     v[0]=y;
  24. 24     v[1]=z;
  25. 25 }
复制代码
This post is from FPGA/CPLD
 
 

693

Posts

7

Resources
3
 
May I ask where this is used specifically? How to use it? I don't quite understand.
This post is from FPGA/CPLD

Comments

I have never used HDL to implement this type of encryption algorithm before, so I chose the simplest TEA encryption to learn, and I have not considered using it yet.  Details Published on 2019-4-29 11:10
 
 
 

55

Posts

0

Resources
4
 
Is it safer and better to directly plug in an encryption chip AES 256 or SHA256 algorithm?
This post is from FPGA/CPLD

Comments

Thank you for your reply. I am a newbie in IC design and have never done encryption. I have used C language a lot and have no idea about how to implement encryption algorithm in HDL. So I picked the simplest encryption algorithm to ask for your advice, so that I can learn from it!  Details Published on 2019-4-29 11:16
Personal signature

深圳市全球芯科技 有限公司(加密芯片/SRAM/pSRAM/图像传感器 13924645577 )

 
 
 

11

Posts

0

Resources
5
 
bqgup posted on 2019-4-27 09:50 May I ask where this is used specifically? How to use it, I am a little confused,
I have never used HDL to implement this type of encryption algorithm before, so I chose a simplest TEA encryption to learn, and I have not considered using it yet.
This post is from FPGA/CPLD
 
 
 

11

Posts

0

Resources
6
 
Global Core published on 2019-4-28 15:14 Is it safer and better to directly use an external encryption chip AES 256 or SHA256 algorithm?
Thank you for your reply. I am a novice in IC design and have never done encryption. I have used C language a lot and have no idea about how to implement encryption algorithm in HDL. So I picked the simplest encryption algorithm to ask for your advice, so that I can learn from it!
This post is from FPGA/CPLD
 
 
 

2113

Posts

0

Resources
7
 
Vivado has an HLS function. See if it is suitable for you. It can convert C or C++ code into Verilog, but the generated code is not very readable. There is a link in this forum. I just started watching it. In addition, how do you use the encryption chip you mentioned?
This post is from FPGA/CPLD
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list