problem in GF(2^8) multiplication using matlab

Status
Not open for further replies.

ahmeddeia

Member level 2
Joined
Jun 27, 2010
Messages
50
Helped
6
Reputation
12
Reaction score
5
Trophy points
1,288
Location
Egypt
Activity points
1,645
Al salam alikom

h r u all? i hope ur are fine

well if i want to multiply 135 by 2 as both are hexadecimals using GF(2^8) multiplication rule by hand we get the decimal result =21

but when i define them in matlab as GF elements---> the result become= 19 ??? well what wrong???

knowing that i use the following command:
gf(135,8)*gf(2,8)
and the result is
ans = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D^2+1 (285 decimal)

Array elements =

19


can u please help me??
thanks and salam alikom
 

hi Ahmeddeia ,
i could n't find any problem with Matlab

Actually the Matlab

gf(135,8)*gf(2,8)

here 135,2 are Decimal

so hex representation is 87 and 02 ...

Actually matlab computes

Code:
gf(hex2dec('87'),8)*gf(hex2dec('02'),8)
 
ans = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D^2+1 (285 decimal)
 
Array elements = 
 
     19


Also in the GF(2^8 )

The elements of X must be
integers between 0 and 2^M-1

0 -255


and hex 135 is decimal 309 and obviously outside the range


so when you try to multiply hex 135 and 02

matlab will issue this warning

Code:
gf(hex2dec('135'),8)*gf(hex2dec('02'),8)
??? Error using ==> gf.gf
X must be between 0 and 2^m-1


blooz
 
Last edited:
Al salam alikom

thanks Blooz for ur reply, pls try to multiply both 135 and 2 in GF(2^8) by hand not by matlab and u will find that the result is 21 not 19
so there is a problem in matlab input for this command.

thanks again for ur reply, i really appreciate it

salam alikom
 


Are trying to multiply decimal 135 and 2

if it is then the manual calculation


hex 87 * hex 02

answer is hex 10E

then after modular reduction that is 10E xor 11D

Answer is hex 13

decimal 19


Yes you can have 21 as answer ,then you would be probably using some other modulus other than 11D

for Eg .AES uses 11B instead of 11D and

so the Answer will be

10E xor 11B

hex 15

decimal 21


by default matlab uses 11D as the primitive polynomial

As per your requirement

you can use the following command

Code:
gf(135,8,283)*gf(2,8,283)

ans = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D+1 (283 decimal)
 
Array elements = 
 
     21
 
Last edited:
Al salam alikom

well Blooz, i really thank u for ur reply, it really helped me....

but when i used it matlab, it gives a warning that this polymonial is not the default and also it tells me that i can use gftable command for faster computations

>> gf(135,8,283)*gf(2,8,283)
Warning: PRIM_POLY must be a primitive polynomial.
> In gf.gf at 96
Warning: PRIM_POLY must be a primitive polynomial.
> In gf.gf at 96
Warning: Lookup tables not defined for this order 2^8 and
primitive polynomial 283. Arithmetic still works
correctly but multiplication, exponentiation, and
inversion of elements is faster with lookup tables.
Use gftable to create and save the lookup tables.
> In gf.gettables at 35
In gf.mtimes at 20
Warning: PRIM_POLY must be a primitive polynomial.
> In gf.gf at 96
In gf.mtimes at 25

ans = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D+1 (283 decimal)

Array elements =

21



so how can i use it within writing m-files within a user defined function

thanks again for ur help, i really appreciate it

salam alikom
 

First create the gftable so that it will accelerate the calculations

Code:
GFTABLE(M,PRIM_POLY) 
gftable(8,283)


then for this particular case you can suppress the warning

Warning: PRIM_POLY must be a primitive polynomial.


type this command
Code:
warning off comm:gf:primPolyPrim
 
Last edited:

Al salam alikom

thanks for ur help, it really helped me

salam alikom
 

anybody can give idea to shifting rows in aes in matlab?

- - - Updated - - -

anybody can give idea to shifting rows in aes in matlab?
 

salam alikom

you will find a matlab command called cirshift or something like that, I don't remember.
However this will help you to make shift rows in AES

thanks,

Salam alikom

anybody can give idea to shifting rows in aes in matlab?

- - - Updated - - -

anybody can give idea to shifting rows in aes in matlab?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…