Comparison and Improvement of RC5 and RC6 Algorithms of Atmega128 Microcontroller

Publisher:HappyExplorerLatest update time:2011-12-28 Keywords:RC5  RC6  Flash Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

In a wireless LAN, the transmission medium is mainly radio waves and infrared rays. Any eavesdropper with receiving ability may intercept the data in the wireless channel, grasp the content of the transmission, and cause data leakage. Therefore, for wireless LAN, data encryption is one of the key technologies.

AVR high-speed embedded microcontroller is an 8-bit RISC MCU. It only takes one clock cycle to execute most instructions. It is fast (the running speed of 8MHz AVR is approximately equal to that of 200MHz C51). 32 general registers are directly connected to ALU to eliminate the bottleneck of operation. It has built-in Flash and EPPROM that can be serially downloaded or self-programmed, with many functions and multiple operating modes.

According to the 802.11 wireless LAN protocol standard released by IEEE in 1999, the wireless data transmission device was developed using Atmel's Atmega128 high-speed embedded single-chip microcomputer. In order to achieve the security of wireless data transmission and save costs as much as possible, software is used for encryption and decryption. This puts high demands on the simplicity, high speed and adaptability of the algorithm. The two new block encryption algorithms RC5 and RC6 can better meet the above requirements.

1 RC5 and RC6 algorithms

1.1 Parameters of RC5 and RC6

RC5 and RC6 are parameter variable grouping algorithms, which are actually a family of encryption algorithms determined by three parameters. A specific RC5 or RC6 can be expressed as RC5-w/r/b or RC6-w/r/b. The three parameters w, f and b are defined as listed in Table 1.

Table 1 RC5 and RC6 algorithm parameter definitions

Parameters Definition Commonly used
w Word size in bits 16,32,64
r Number of encryption rounds 0~255
b The length of the key in bytes 0~255

1.2 RC5 and RC6 word operation components

Both RC5 and RC6 consist of three parts: the mixed key generation process, the encryption process, and the decryption process. In these two algorithms, a total of six basic operations are used:

① Modulo 2w addition operation, represented by "+";

② Modulo 2w subtraction operation, represented by "-";

③ Bit-by-bit XOR operation, expressed as +;

④ Circular left shift: word a is circularly shifted left by b bits as “a<<

⑤ Circular right shift: word a is circularly shifted right by b bits as “a>>>b”;

⑥ Modulo 2w multiplication, expressed as “×”.

The RC5 algorithm uses the above-mentioned ① to ⑤ calculation parts, and the RC6 algorithm uses all of the above-mentioned calculation parts.

1.3 RC5 Algorithm

(1) Pseudocode representation of the RC5 algorithm hybrid key generation process

S[0]=Pw

for i=1 to t-1 do

S[i]=S[i-1]+Qw

Input user keys K[0] to K[b-1] with a bit size of 8 and a key length of b

Convert K[0] to K[b-1] to an L[] array with length c and number of bits w

i=j=0 x=y=0

do 3×max(t,c)times:

S[i]=(S[i]+x+y)<<<3;X=S[i];i=(i+1)mod t

L[j]=(L[j]+x+y)<<<(x,y);X=L[j];j=(j+1)modC

Where c = [b × 8 / w] square brackets indicate the rounding operation, t = 2r + 2, when w is 16, 32, 64, respectively, the constants Pw, Qw are listed in Table 2.

Table 2 Constants Pw, Qw value table

W 16 32 64
P 0xB7E1 0xB7E15163 0xB7E151628AED2A6B
QUR 0x9E37 0x9E3779B9 0x9E3770B97F4A7C15

(2) Pseudocode representation of the RC5 encryption algorithm process

Input(A,B)

A=A+S(0)B=B+S[1]

for i=1 to r do

A=((A+B)<<

B=((B+A)<<

Output(A,B)

The initial A and B are two bits of data w to be encrypted, and the final A and B are two bits of data w encrypted.

(3) Pseudocode representation of the RC5 decryption algorithm process

Input(A,B)

for i=r down to 1 do

B=((BS[2i+1])>>>A)+A

A=((AS[2i])>>>B)+B

A=AS[0] B=BS[1]

Output (A,B)

The data in the initial A and B are the encrypted data with the number of bits being w, and the data in the final A and B are the decrypted data with the number of bits being w.

1.4 RC6 Algorithm

(1) Pseudocode representation of the RC6 algorithm hybrid key generation process

The RC6 hybrid key generation process is the same as RC5, except that the value of t is 2r+4.

(2) Pseudocode representation of the RC6 encryption algorithm process

Input(A,B,C,D)

B=B+S[0]D=D+S[1]

for i=1 to r do

t=(B×(2B+1))<<

u=(D×(2D+1))<<<1og2w

A=((A+t)<<

C=((C+u)<<

(A,B,C,D)=(B,C,D,A)

A=A+S[2i+2]C=C+S[2i+3]

Output(A,B,C,D)

The initial A, B, C, and D are four bits of data w to be encrypted, and the final A, B, C, and D are four bits of data w that have been encrypted.

(3) Pseudocode representation of the RC6 decryption algorithm process

Input(A,B,C,D)

C=CS[2i+3]A=AS[2i+2]

for i=1 to r do

(A,B,C,D)=(D,A,B,C)

u=(D×(2D+1))<<

t=(B×(2B+1))<<

C = ((CS[2(ri)+3])>>>t)+u

A=((AS[2(ri)+2])>>>u)+t

D=DS[1] B=BS[0]

Output(A,B,C,D)

The initial A, B, C, and D are four bits of data with a number of w that have been encrypted, and the final A, B, C, and D are four bits of data with a number of w that have been decrypted.

2 Implementation and Improvement of RC5 and RC6 Algorithms

2.1 RC5 and RC6 algorithm flow of AVR microcontroller

The implementation flow chart of the RC5 and RC6 algorithm encryption process is shown in Figure 1, the implementation flow chart of the decryption process is shown in Figure 2, and the overall process flow chart is shown in Figure 3.

2.2 Improvement of RC5 and RC6 algorithms for AVR microcontrollers

① When arranging the algorithm flow, considering that the AVR high-speed embedded microcontroller has only 32 8-bit registers, in order to save the use of registers, the data to be encrypted should be assigned to the registers after the hybrid key generation process is executed. In this way, the registers before the hybrid key generation process can be used without affecting the execution result of the entire algorithm.

② When selecting the parameters of the RC5 and RC6 algorithms, considering that the AVR high-speed embedded microcontroller instructions only support 16-bit data addition at most and the simplicity of the program, w is selected as 16 instead of 32 in this program, and the values ​​of r and b are taken as 12 and 16 respectively according to Rivest's suggestion.

③ When executing the left or right loop operation in the algorithm, considering the effect of circular shift, the actual number of bits of circular shift should be the lower 1log2w bits of the number of shifts to be performed. In this program, it is the last four bits of the number of shifts to be performed.

④ When executing the modulo 2w addition, modulo 2w subtraction, and modulo 2w multiplication operations in the algorithm, since the value of 2w is 65536, and the two 8-bit registers (0 to 15 bits) can represent a maximum data value of 65535, if the data is larger, it must be carried to the higher bits. Therefore, when executing the above algorithm in this program, you only need to consider the values ​​expressed by the two 8-bit registers to obtain the final result of the above operation without performing the modulo 2w operation.

⑤ In order to increase the speed of data encryption and decryption, the mixed key generation process can be executed in advance to generate a mixed key table. This table is loaded into the Flash of the Atmega128 high-speed embedded microcontroller at the data sending end and the Atmega128 high-speed embedded microcontroller at the data receiving end, so that the mixed key can be directly used in the subsequent encryption and decryption process. It is worth noting that whenever the user key entered by the user changes, the mixed key generation process must be re-executed and the regenerated mixed key table must be re-loaded into the Flash. In this program, the RC5 mixed key table occupies a total of 52 8-bit register units, and the RC6 mixed key table occupies a total of 56 8-bit storage units.

⑥ In this program, addition and shift operations are used to implement the unsigned operation of 16-bit binary number multiplication by 16-bit binary number. The subroutine of this operation is as follows:

chengfa:clr result2

clr result3

ldi count1,16

lsr chengshu1

ror chengshu0

chengfa0:

brcc chengfa1

add result2,beichengshu0

adc result3,beichengshu1

chengfa1:

ror result3

ror result2

ror result1

ror result0

dec count1

brne chengfa0

ret

3 Experimental results, comparison and analysis of RC5 and RC6 algorithms

The comparison of the effects of the mixed key process, encryption process, decryption process and overall process of the RC5 and RC6 algorithm experiments is listed in Tables 3, 4, 5 and 6.

Table 3 Comparison of the effects of the mixed key process of the RC5 and RC6 algorithms

Hybrid key generation process Cycle Count Stop observation/μs Program size/words c t
RC5 algorithm 15 248 1270.67 141 8 26
RC6 algorithm 15 246 1270.50 141 8 28

Table 4 Comparison of the encryption process effects of RC5 and RC6 algorithms

Encryption process (not taking into account the time to generate the hybrid key) Cycle Count Stop observation/μs Program size/words The number of bits of data processed Efficiency/(bit/s)
RC5 algorithm 2511 209.25 66 32 Approximately 152,927
RC6 algorithm 62529 5210.75 170 64 Approximately 12 282

Table 5 Comparison of the decryption process effects of RC5 and RC6 algorithms

Decryption process (not taking into account the time to generate the hybrid key) Cycle Count Stop observation/μs Program size/words The number of bits of data processed Efficiency/(bit/s)
RC5 algorithm 2509 209.08 68 32 Approximately 153 051
RC6 algorithm 62527 5210.58 176 64 Approximately 12 283

Table 6 Comparison of overall process effects of RC5 and RC6 algorithms

Overall algorithmic process (considering the time to generate the mixed key, ignoring the time for data transmission) Cycle Count Stop observation/μs Program size/words The number of bits of data processed Efficiency/(bit/s)
RC5 algorithm 20 260 1688.33 267 32 Approximately 18,594
RC6 algorithm 140 274 11 689.50 455 64 Approximately 5475

From Table 3, we can find that the size of the program for generating a mixed key is the same for the RC6 algorithm and the RC5 algorithm, but the RC6 algorithm saves more time than the RC5 algorithm. This is because the mixed key generation method executes a loop and performs a comparison operation when finally generating a mixed key. When the comparison range t is exceeded, the pointer address must be reset. The value of t in the RC6 algorithm is greater than the value of t in the RC5 algorithm, so the RC6 algorithm performs fewer reset operations. This saves the running cycle, so the RC6 algorithm saves more time than the RC5 algorithm when generating a mixed key.

All the above experimental results are obtained by using Atmel's Atmega128 high-speed embedded microcontroller as the experimental equipment platform on the AVR Studio4.07 simulation software. Select parameters w=16, r=12, b=16, and calculate c=8, t=26 (RC5 algorithm) or t=28 (RC6 algorithm) according to the calculation formula at a simulation speed of 12MHz.

From the experimental results in Tables 3, 4, 5 and 6, the following conclusions can be clearly drawn.

① From the perspective of program execution efficiency, the RC5 algorithm is more efficient than the RC6 algorithm in both encryption and decryption.

Therefore, the RC5 algorithm should be used in situations where program execution efficiency is very important but data security requirements are not very high.

② From the perspective of program execution time, whether in the encryption process or not in the decryption process, the RC5 algorithm saves time than the RC6 algorithm. Therefore, in some cases where the program execution time is very demanding and the data security requirements are not very high, the RC5 algorithm can be used.

③From the perspective of program size, the RC5 algorithm is simpler than the RC6 algorithm in both encryption and decryption. Therefore, the RC5 algorithm can be used in some cases where the program space size is very high and the data security requirements are not very high.

④ From the perspective of security, the RC6 algorithm is based on the RC5 algorithm to address the loopholes in the RC5 algorithm. The main problem is that the displacement of the cyclic shift does not depend on all the bits to be moved. By introducing the multiplication operation to determine the number of cyclic shifts, the RC5 algorithm is improved, thereby greatly improving the security of the RC6 algorithm. Therefore, in some cases where data security is very high, the RC6 algorithm should be used.

Conclusion

RC5 and RC6 algorithms are two new block ciphers, both of which have variable word length, variable number of encryption rounds, and variable key length; at the same time, they only use common elementary operations, which makes them very adaptable, high computing speed, and very suitable for hardware and software implementation. The two algorithms have their own advantages and disadvantages. In engineering applications, the most suitable method should be selected according to actual needs to obtain the best effect.

Keywords:RC5  RC6  Flash Reference address:Comparison and Improvement of RC5 and RC6 Algorithms of Atmega128 Microcontroller

Previous article:Atmega128 MCU CRC check code table lookup and direct generation
Next article:Application of AVR single chip microcomputer in digital signal processing of frequency hopping system

Recommended ReadingLatest update time:2024-11-16 15:36

1.6.1_NOR_FLASH principle and hardware operation
The recorded video uses the MX29LV800BBTC model NOR FLASH chip, and the one on the S3C2440 development board is MX29LV16, but in fact their operation methods are the same. NOR FLASH can be read like memory, but cannot be written like memory. Some special operations are required to write. I won't list the compariso
[Microcontroller]
1.6.1_NOR_FLASH principle and hardware operation
Design of frequency measuring meter based on single chip microcomputer
1 Introduction Frequency is one of the basic parameters that reflect signal characteristics, and frequency measurement plays an important role in the field of applied electronic technology. The digitization and intelligence of measurement are the current development trends of measurement technology. Digital processi
[Microcontroller]
Design of frequency measuring meter based on single chip microcomputer
A FLASH Bootloader for PIC16 and PIC18 Devices
Author:  Ross M. Fosler and              Rodger Richey              Microchip Technology Inc. Translator: Zhuying Linux WRITING CODE The bootloader operates as a separate entity, which means that an application can be developed with very little concern about what the bootloader is  doing . This is as it should be;
[Microcontroller]
A FLASH Bootloader for PIC16 and PIC18 Devices
STM32 flash read and write operations
1. Introduction to Flash   The programming operation of stm32 can be realized by reading and writing the flash inside stm32.   The built-in programmable Flash of stm32 is of great significance in many occasions. For example, its support for ICP (In Circuit Programming) allows developers to debug and develop stm32,
[Microcontroller]
STM32 internal FLASH routine
#include "stm32f10x.h" #include   /* STM32 internal FLASH configuration */ #define STM32_FLASH_SIZE 512 /* FLASH capacity of the selected STM32 (in K) */   #if STM32_FLASH_SIZE 256   #define STM_SECTOR_SIZE 1024 /* 256 means 1K byte page, =256 means 2K page*/ #else    #define STM_SECTOR_SIZE 2048 #endif   /* Appli
[Microcontroller]
Kernel transplantation based on Tiny 6410 (NAND FLASH, UBIFS)
1. Environment 1. Development board Tiny6410  NAND: 2G  RAM: 256M  MLC 2. Operating System Ubuntu10 3. Cross-tool compilation chain arm-linux-gcc-4.5.1 2. Download the kernel source package linux-2.6.38 3. Decompress the kernel tar –jxvf linux-2.6.38.tar.bz2
[Microcontroller]
IAR for AVR Study Notes (4) --Flash Operation
Specific operation methods of common types of FLASH 4.1. FLASH area data storage. Use the keyword __flash to control storage. The effect is the same whether the __flash keyword is written before or after the data type __flash unsigned char a; //Define a variable and store it in the flash space unsigned char __flash
[Microcontroller]
STM32 flash operation
Functions that operate the internal flash of the chip, including reading, status, erasing, writing, etc., can allow the program to operate the data on the flash. Basic application 1, FLASH timing delays several cycles and waits for bus synchronization operation. It is recommended to follow the operating frequency of
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号