Hello, this is Dr. Miller and this
is Episode fifteen point two of
Assembly.
Today, we're going to talk about
SASE and Memex extensions
and then the as an extension.
So Zenimax Memex,
so Memex generally
is thought to stand for a multimedia
extension.
There's little controversy over what
it actually stands for,
but that's the easiest way to think
about it. So in nineteen ninety
seven, Intel added these
multimedia instructions and
so Memex defined
eight registers that could be used
M0 through M-m seven
and these are 64 bit wide
and that's on a 32 bit processor.
And so then we can have that.
They are packed into different
sizes. So you could have a bunch of
bytes, you could have a bunch of
words, you could have
a bunch of D words that all fit
inside one instruction
and then you can perform
multiple operations on that piece of
data such that
you can do multimedia things,
things that pixels and.
That type of manipulation,
but what they did is they used the
Eighty-seven, so the floating point
registers, and so that meant that
you couldn't mix X and floating
point operations.
So then what they did is they
created the C instructions.
So this is streaming ACMD,
Extension's or SASE.
And so what that added was
what we have ACMD
is single instruction, multiple
data.
So again, we can have one
instruction that operates on
multiple pieces of data and then
hopefully that can be more efficient
than having a lot of instructions go
over that.
And so they extended the Intel X
eighty six architecture in order to
do this and then they again use
this in multimedia.
So what this did
is it's a plan to those Memex
instructions and we'll see why in a
second.
And that's because they they did
address those floating point
operations issues.
So C one came out in ninety
nine. So not too much later.
And again, it added some additional
registers. So now we have one
hundred and twenty eight bit
registers, Xenome
zero through Ximenes seven.
And again these can be packed.
So for example we could have four
integers in each one of
these Zemun registers.
And so that allows us to very
efficiently load data from
RAM into that register
and then do operations that are
S.A.M.
d applicable to
that.
And so additionally.
So Intel and AMD sort of
we're we're at a battle at this
point. They they have been for quite
a long time and so
they added Xome eight through 15.
And so then when Intel
came out with their X sixty four
architecture than they of course
added those as well.
So we have 16 registers
that can be used for these SC
instructions.
And then in
2001 SC two came out
and this allowed them to
use those memex instructions
and they could use them registers.
And so this meant that you could
basically convert all in the next
code into S.
E code and then use
the X and then registers instead of
the floating point registers.
And so this sort of made it so that
we didn't need Emacs anymore.
We had the SC two that anybody
could use for libraries
and we also added Sesi
three and four.
So three was in 2004
and we can operate on the
data within the same register.
And so, for example, we could add
all of the numbers stored in one
register together at the same
time. And so again, it provided sort
of better flow for
our assembly code.
And then SASE four came out in 2006
and it added a bunch of string and
text functions and
added some math operations
like Sum's on absolute differences
and dot product.
But again, they keep adding it to
make it better so that you could
do more with the instructions
instead of trying to do
use a lot of instructions in order
to do the same thing.
And so that's why they added a
bunch of these different extensions.
And then if you want to be able
to use these intrinsic functions
within your code or registers,
you can basically include different
library headers.
And so we have again, Max,
SCC two, three,
and they have different versions of
four that came out.
And then we have as.
So the as and I so this
is the
advanced encryption standard or a
yes, and then and I very cleverly
named new instructions.
And so this provides specific
instructions that can be used for
the encryption standard.
So when we created a standard
that the the advanced encryption
standard, then anybody could
use that. And so this was
the standard used by everybody.
And so it made sense for Intel
to implement these inside of
instructions instead of people
trying to rewrite the code from
scratch.
And so Intel has a really nice
documentation that describes
all of these instructions and gives
examples of how they can be used.
So I'll just explain a little bit
about the algorithm.
So there are a couple of different
parts that we have for this.
So the first is going to be a key
expansion. So we take
the key and we end up expanding it
or running it through a bunch of
operations in order to
mix all the bits for when we use
the encryption.
And so the different key sizes
determine the number of rounds that
we end up using. So we keep doing
this thing for a certain this
process for a certain number of
rounds. And so if we're doing one
hundred and twenty eight bid
encryption, it's ten rounds.
If we're doing a hundred ninety two,
it's twelve.
And if we're doing two fifty six,
it's 14.
And then when we do encryption we
basically add the round key
and then we do these things of
substitute some bytes, shift some
rows and mixed some rows and
then we end up repeating that
multiple times.
And then at the end we do one final
round that doesn't
do the mix columns.
So you see it substitutes bytes,
it shifts rows and then it adds
around key.
And so it doesn't do that next
column. So it's the last step is
just a little bit different than all
the rest.
So, again, I pulled these out of the
white paper that Intel produced, so
they have different operations.
So one is a key
genesis.
And so this is helping us to
generate an encryption key.
And we can see here that
this takes basically two registers
and then the round constant and we
can see the round constants in here.
And so it's
very specifically defines what those
round constants are.
So we've got one, two, four, eight,
10, 20, 40, 80,
one, B and thirty six
all in hex.
And so we can see
that they end up calling these on
the on the register.
We got a couple of different
registers, we got our result
register and then our one hundred
and twenty eight that input.
And so we use those in order to
generate
the key or do the key
expansion from that.
We also have as E.M.S.
or a script, and
so it's going to perform one round
of ass encryption, so and
then one is our input data and
X and then two is our round key.
And what this does is it shifts,
throws, substitutes, bytes, mixes,
columns, and then takes them one.
An exorcist with
maximum two and maximum two
is our round key.
So it's moving the data around
and then doing an X or at the very
end.
We also have a blast,
and so, again, that very last step,
we don't mix columns, right?
And so it basically does all those
things that the encrypt does, but
it doesn't do a mix columns right
here. It just does the X or at
the very end.
We also have the similar operations
for decryption, so we got SDI
or Decrypt, and again, we
have our input data and we have
around key. And so this is going to
provide that inverse operation.
So we're going to decrypt the data.
And so here it's invert shift
rows and substitute bytes, invert
mixed columns, and
then we do an X or with the
data. And again, we should end up
getting the result that we had
before.
But just as the encrypt does,
the decrypt has a last operation.
So again, that last operation
doesn't mix columns just like we did
before.
So again, it doesn't shift invert
substitute bytes and then does an X
or.
And then because we have
the keys, there is a we do end
up doing an invert mix columns,
but that ends up being operated on
the key in the initial step
and not inside of
the decryption.
And so they have this as emcee
or invert next columns
that will be used
with the after we
after we expand our key, we use
this in order to properly
prepare the inverted key
for it.
So today we talked about CNM
Amex extensions and then the
as an extension.
So looking forward, we're going to
look at some aiyaz libraries that
you can use and either you
can use them inside of C-code
or you can use the intrinsics and
generate reassembly code for
that.
So what are some of the specific
instructions?
Well, here's the whole list of them.
So we got key Genesis,
encrypt, encrypt last, decrypt,
decrypt last and mixed
columns.
If you have questions, you can email
me, Miller, M.J., you and Kidada,
and you can find me on Twitter at
Milhouse 30.