S
S
synapse_people2017-12-26 17:39:41
PHP
synapse_people, 2017-12-26 17:39:41

Is it possible to implement the AES algorithm this way?

Hello.
I'm interested in the possibility of implementing the x86 instruction of the intel processor AESENC, which performs 1 round of AES encryption using strings of 16 bytes, that is, 128 bits.
After all, AESENC takes two 128-bit ints as parameters - the state and the round key. It then returns the state, also as a 128 bit int...
Is it possible to implement a function in PHP that would do 1 round of encryption using only strings, without arrays?
Benchmarks show that access to index values, changing values ​​in arrays, xors, shifts - all this takes a very long time.
For example, to match the state with a key, you can write $state ^= $key; for strings - this is enough, each byte of the state will be zaxored with a key ... but what about those functions where permutations occur?
tell....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2017-12-26
@usdglander

Well, purely theoretically, you can cut a string into blocks of 4 characters each, convert them to numbers, perform the necessary operations with numbers, then convert them back to strings and glue them together. The unpack() and pack() functions can help with this.
It works without arrays. And all operations with numbers, including permutations of bits, are done using the bitwise operations &, |, !, ^. Well, multiplication / division by 2 to control the shifted bit.
But, in all honesty, PHP is not the best option for implementing crypto algorithms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question