Specific column mixing Algorithm in AES Encryption

Source: Internet
Author: User

AES plaintext encryption involves the process of byte substitution, row shifting, column mixing, and round key addition. Here we will give some simple explanations for the column-mixed algorithm.
Column mixing is actually used to multiply each column of a State by a matrix, where multiplication is performed within the finite field GF (2 ^ 8, x ^ 8 + x ^ 4 + x ^ 2 + x + 1

First, list the algorithm code:

Void AES: mixcolumns (unsigned char State [] [4]) // column mixing {unsigned char T [4]; int R, C; For (C = 0; c <4; C ++) // process by column {for (r = 0; r <4; r ++) {T [R] = State [r] [c]; // copy each byte in each column to T [R]} For (r = 0; r <4; r ++) {State [r] [c] = ffmul (0x02, t [R]) // matrix calculation, the addition is exclusive or ^ ffmul (0x03, t [(R + 1) % 4]) ^ ffmul (0x01, t [(R + 2) % 4]) ^ ffmul (0x01, t [(R + 3) % 4]) ;}} unsigned char AES: ffmul (unsigned char, unsigned char B) // multiplication over a finite field GF (2 ^ 8) {unsigned char BW [4]; unsigned char res = 0; int I; BW [0] = B; for (I = 1; I <4; I ++) {BW [I] = BW [I-1] <1; if (BW [I-1] & 0x80) {BW [I] ^ = 0x1b ;}}for (I = 0; I <4; I ++) {If (A> I) & 0x01) {res ^ = BW [I] ;}} return res ;}

Here the emphasis is on Multiplication over the finite field GF (2 ^ 8. The principle of the algorithm used is as follows:
1. in GF (2 ^ 8), any number multiplied by 0x01 remains unchanged.
2. Calculate the multiplication of 0x02 in GF (2 ^ 8), which can be considered in two situations:
(1) If the original value is smaller than (1000 0000) 2, that is, 0x80, the first 8th bits after multiplication 2 will not overflow, and the result is that the original value is shifted to the first place;
(2) When the original value is greater than (1000 0000) 2, that is, 0x80, the first 8th bits after multiplication 2 will overflow, the result is subtracted from an irrevocable polynomial (X8 + X4 + X2 + x + 1). Note that the subtraction in GF (2 ^ 8) is addition, then, the result is that the original value is shifted to the first digit (multiplied by 2) and then (0001 1011) 2, that is, 0x1b, or (X8 has been reduced here, you only need to subtract X4 + X2 + x + 1 ).
3. Similar to the 2nd point, the result of multiplication 4 and multiplication 8 in GF (2 ^ 8) is obtained;
4. When calculating the multiplication other number in GF (2 ^ 8), it can be expressed as a linear combination of multiplication 1, 2, 4, and 8.

The Multiplication Source Code on the finite field GF (2 ^ 8) is explained based on the above points:

Unsigned char AES: ffmul (unsigned char a, unsigned char B) // multiplication on the finite field GF (2 ^ 8) {unsigned char BW [4]; unsigned char res = 0; int I; BW [0] = B; for (I = 1; I <4; I ++) // loops three times, the values after parameters B multiplication 2, 4, and 8 are obtained and stored in BW [I] {BW [I] = BW [I-1] <1; // The original value is multiplied by 2 if (BW [I-1] & 0x80) // determine whether the original value is smaller than 0x80 {BW [I] ^ = 0x1b; // if it is greater than 0x80, subtract an irrevocable polynomial }}for (I = 0; I <4; I ++) {If (A> I) & 0x01) // represents a linear combination of values of parameter A as 1, 2, 4, and 8 {res ^ = BW [I] ;}} return res ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.