USB Key design based on MC9S08JS16 and AES

Publisher:Serendipitous55Latest update time:2010-12-22 Source: 电子设计工程Keywords:MC9S08JS16  USB  Key Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

With the development of the Internet and e-commerce, network information security issues are particularly important. Data confidentiality transformation or information encryption has become the most practical and reliable method to protect computer information. Various encryption technologies such as software self-checking, password encryption, key disk and other soft encryption technologies and expansion cards, parallel port software encryption dogs and other hard encryption technologies have emerged, and USB interface keys (USB Key) are favored due to their unique advantages and high security.

USB Key is a small storage device that is directly connected to the computer through the USB (Universal Serial Bus) interface, has password verification function, and is reliable and high-speed. The USB Key is designed to be compact and exquisite, and easy to carry. Because it is a USB interface device, the USB Key works through the power provided by the USB port and does not require an additional power supply. The USB Key's own memory is used to store some personal information or certificates. The USB Key's internal cryptographic algorithm can provide a secure channel for data transmission, and is suitable for security protection products for stand-alone or network applications.

1 System Working Principle and Hardware Design

The USB Key (Ukey for short) is connected to the PC through the USB interface. The user can send commands to the Ukey through the client located in the PC. The Ukey implements data encryption through the algorithm in the internal firmware and then returns the encrypted data to the client. Its working principle is shown in Figure 1. The design uses the 8-bit USB microcontroller (MCU) MC9S08JS16. The MC9S08JS16 MCU has a built-in full-speed USB2.0 controller and integrates a USB transceiver, and contains up to 16 KB of Flash and 512 B of RAM.


The user can use the dedicated 3.3 V regulator on the chip or connect an external 3.3 V power supply to the VUSB3.3 pin to provide power for the USB transceiver and the pull-up resistor. Here, the 3.3 V regulator on the chip is used to provide power for the USB transceiver (the USBVREN bit in the USBCTL0 register must be enabled). The hardware connection diagram is shown in Figure 2.


The USB module requires two clock sources, a 24 MHz bus clock and a 48 MHz reference clock. The 48 MHz clock source is directly generated by MCGOUT. To obtain a 48 MHz clock rate, the MCG (universal clock generator) must be properly configured as PLL-enabled external occupied mode PEE (PLL Engaged External) and an external crystal oscillator. The USB module of the MC9S08JS16 selects an internal pull-up resistor (enables the USBPU bit in the USBCTL0 register). The USB host detects the connection of the USB device and determines the device speed by detecting the pull-up resistor.

2 System Software Design

2.1 USB device initialization

Figure 3 is a flowchart of USB module initialization. The firmware code initializes the USB module to prepare it to connect to the USB host. By setting the RESET bit of the USBCTL0 register, the USB module and all registers are reset to the default state, and the USB RAM and BD (buffer descriptor) registers are initialized. In particular, for the BD of endpoint 0, the EPAD register is set to indicate the storage of the endpoint register in the USB RAM. In order to receive the DATA0 data packet, the status and control registers are set to (DTS=1, OWN=1, DATAO/1=0). Enable endpoint 0, and configure the USB module according to the hardware design, enable the pull-up resistor, 3.3 V regulator and PHY. Open the USB module and USB interrupt, and the device is set to the connection state.


2.2 AES encryption algorithm

The system uses the 128-bit Advanced Encryption Standard AES (Riindael) algorithm for data encryption. AES (Advanced Encxyption Standard) is a specification used by the National Institute of Standards and Technology of the United States to encrypt electronic data. It is used to replace the existing DES algorithm. As a new generation of data encryption standard, AES brings together the advantages of strong security, high performance, high efficiency, ease of use and flexibility. It is expected to become a recognized method for encrypting digital information including finance, telecommunications and government.

The AES algorithm is based on permutation and substitution. Permutation is the rearrangement of data, while substitution is the replacement of one unit of data with another. The AES encryption routine starts by copying the 16-byte input array into a 4x4 byte matrix called State. The AES algorithm encryption process is shown in Figure 4.


The main loop of AES performs four different operations on the State matrix, which are called SubBytes (byte substitution), ShiftRows (row shift transformation), MixColumns (column mixing transformation) and AddRoundKey (round key addition) in the specification. The AES encryption algorithm uses a key schedule generated by the seed key byte array, which is called the key expansion routine (KeyExpans-ion) in the AES specification.

The following is a brief analysis of the AES (128 bits key) encryption process:

The SubBytes routine is a substitution operation that replaces each byte in the State matrix with a new byte determined by Sbox, which is an initialized 16x16 matrix. For example, if the value of State[0,1] is 0xXY, it is replaced by the value of Sbox[X,Y] in the Sbox table.

ShifiRows is a permute operation that rotates the bytes in the State matrix to the left. Row 0 of State is rotated 0 positions to the left, row 1 of State is rotated 1 position to the left, row 2 of State is rotated 2 positions to the left, and row 3 is rotated 3 positions to the left.

MixColumns is a column mixing transformation process in which each column of the state is treated as a polynomial in the finite field GF(28) and is replaced by a fixed polynomial.

, GF stands for Galois Field, which is expressed in matrix form as follows:

Each element in the product matrix is the sum of the products of the i-th row element in the coefficient matrix and the j-th column element State[j] in the State matrix. Both addition and multiplication here are defined over the finite field GF(28); addition is bitwise XOR, and multiplication follows the polynomial multiplication rule over GF(28).

AddRoundKey round key addition process, the elements in the State matrix are obtained by bitwise XOR with a round key.
KeyExpansion key expansion routine, used to generate the key schedule table W[]. The routine uses two subroutines RotWord and SubWord and a round constant table Rcon. RotWord will receive a 4-byte array and rotate them left by 1 bit. The SubWord routine uses the replacement Sbox to replace a given row of the key schedule table byte by byte. The loop of this process is:

2.3 Optimization of AES encryption algorithm

From the matrix function of formula (1), we can see that in the software implementation process, we only need to focus on how to implement the multiplication and addition of the State matrix elements with 0x01, 0x02, and 0x03 in GF(28). Multiplication with 0x01 in GF(28) is equivalent to multiplication with 1 in ordinary arithmetic and the result is the same. Any value multiplied by 0x01 is equal to itself; when multiplying with 0x02, as long as the multiplied value is less than 0x80, the result of the multiplication is the value shifted left by one bit. If the multiplied value is greater than or equal to 0x80, the result of the multiplication is shifted left by one bit and then XORed with the value 0x1b, which prevents "domain overflow" and keeps the product of the multiplication within the range; when multiplying with 0x03, it can be decomposed into the sum of powers of 2, that is, 0x03=0x02+0x01. To optimize the program, use the table lookup method to multiply the 16x16 Sbox table with 0x01, 0x02, and 0x03 to generate three 256-byte tables corresponding to Sbox: XtimeSbox[256]=Sbox[256], Xtime2Sbox[256], and Xtime3Sbox[256]. Store the generated tables in the code area. The MixColumns process and SubByte operation can be completed by the following program:



3 USB Key Performance Test

Considering the MCU performance, the four 256-byte data tables required for the encryption algorithm initialization are stored in the Code area, and the 128-bit-AES extended key ExpendedKey = 4xNbx(Nr+1) = 4×4×(10+1) = 176 is stored in the data area. Under the premise of ensuring the code space and operation speed, after optimization, the final AES encryption program occupies 3701 bytes of program storage units and 277 bytes of RAM.

The following are the results of two sets of 128-bit data encryption tests:


4 Conclusion

Compared with general disk media, UKev data is only stored in UKeY, which can prevent illegal copying, ensure the uniqueness of the data, and facilitate its use in public places.

The UKey designed in this solution can encrypt a small amount of data in a short time, and is suitable for occasions with small data requirements. It has high security and is easy to carry. It has irreplaceable advantages over other products in e-commerce and various PC-based security applications.

Keywords:MC9S08JS16  USB  Key Reference address:USB Key design based on MC9S08JS16 and AES

Previous article:Design of wide voltage intelligent flashing light based on MK6A11P single chip microcomputer
Next article:Application of CPCI Single Board Computer in Airbus Inflight Entertainment System

Recommended ReadingLatest update time:2024-11-16 17:49

STM32F103 Programming-9-USB to TTL Serial Port (Transmit and Receive)
This is modified based on the previous routine USB to TTL serial port (printf). The main modifications are as follows: 1. Since printf is not used anymore, remove the definition of PUTCHAR_PROTOTYPE. 2. Find the code for sending and receiving serial data from the official website routines, and integrate it into the ne
[Microcontroller]
Design and implementation of infrared data transmission system based on USB2.0
1 Introduction With the development and application of test technology and wireless communication technology, test instruments are developing towards miniaturization and low power consumption. Infrared data transmission is low-cost, simple and easy to use, and is widely used in many small devices. In order to a
[Test Measurement]
Design and implementation of infrared data transmission system based on USB2.0
Automotive USB Type-A/Type-C charging controller fully integrated solution
The USB port in the car's central control generally needs to transmit data and also support charging of mobile devices. MPS  Company has a chip with many advantages for this application field - MPQ4228-C. MPQ4228-C supports BC1.2 CDP mode and USB Type-C 5V @ 3A DFP mode. It is packaged in QFN-22 (4mmx4mm) and is com
[Automotive Electronics]
Automotive USB Type-A/Type-C charging controller fully integrated solution
OK6410 USB device driver
usb.c source code: // Reference: drivers/hid/usbhid/usbmouse.c #include "linux/kernel.h" #include "linux/slab.h" #include "linux/module.h" #include "linux/init.h" #include "linux/usb/input.h" #include "linux/hid.h" #include "linux/input.h"  static struct input_dev *mk_dev; static int len; static char *buf; static dma_
[Microcontroller]
S3C2440 USB device controller
The s3c2440 soc integrates a usb1.1 device controller, which can perform full-speed/low-speed control, interrupt and batch transmission. In addition to endpoint 0, it has four endpoints. Each endpoint can be used as an interrupt and batch endpoint. Each endpoint has a 128-byte FIFO, so the maximum packet of the endpoi
[Microcontroller]
Design of image processing system for uncooled infrared thermal imager based on USB2.0
Abstract: The infrared image acquisition is completed based on USB2.0 bus technology and video decoding chip SAA7114 , the video data stream is sent and received by FPGA , and the host is communicated through the USB interface chip Ez-USB FX2 CY7C68013 . The system is flexible, plug-and-pl
[Security Electronics]
Design of image processing system for uncooled infrared thermal imager based on USB2.0
i.MX6Q (TQIMX6Q/TQE9) study notes - USB HOST transplantation of the new version of BSP
USB HOST drivers are generally maintained by chip manufacturers, so we still only need to configure DTS to complete the porting of the USB HOST driver. DTS Configuration Refer to the DTS related to sabresd and add the following content to our DTS: / {   ... regulators { compatible = "simple-bus";   reg_usb
[Microcontroller]
USB3.0 interface technology and circuit design
As a new type of interface technology, USB is popular for its ease of use and high speed. This article briefly introduces the characteristics, hardware structure, data stream transmission and implementation of peripheral controller of USB interface. It also describes in detail the process of designing
[Analog Electronics]
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号