WEBVTT

00:04.780 --> 00:06.399
Hello, this is Dr. Miller and this

00:06.400 --> 00:07.919
is Episode fifteen point two of

00:08.109 --> 00:09.109
Assembly.

00:09.950 --> 00:11.269
Today, we're going to talk about

00:11.270 --> 00:13.669
SASE and Memex extensions

00:13.670 --> 00:15.769
and then the as an extension.

00:16.840 --> 00:18.390
So Zenimax Memex,

00:19.210 --> 00:21.219
so Memex generally

00:21.220 --> 00:22.869
is thought to stand for a multimedia

00:22.870 --> 00:23.870
extension.

00:24.250 --> 00:25.629
There's little controversy over what

00:25.630 --> 00:26.860
it actually stands for,

00:27.490 --> 00:28.629
but that's the easiest way to think

00:28.630 --> 00:30.009
about it. So in nineteen ninety

00:30.010 --> 00:31.186
seven, Intel added these

00:32.049 --> 00:33.372
multimedia instructions and

00:34.090 --> 00:35.829
so Memex defined

00:36.250 --> 00:37.720
eight registers that could be used

00:37.740 --> 00:39.340
M0 through M-m seven

00:39.820 --> 00:41.829
and these are 64 bit wide

00:42.670 --> 00:44.720
and that's on a 32 bit processor.

00:45.340 --> 00:46.809
And so then we can have that.

00:46.840 --> 00:48.069
They are packed into different

00:48.070 --> 00:49.479
sizes. So you could have a bunch of

00:49.480 --> 00:50.829
bytes, you could have a bunch of

00:50.830 --> 00:52.659
words, you could have

00:52.660 --> 00:54.069
a bunch of D words that all fit

00:54.070 --> 00:55.719
inside one instruction

00:56.050 --> 00:57.729
and then you can perform

00:58.090 --> 00:59.854
multiple operations on that piece of

00:59.890 --> 01:01.509
data such that

01:01.900 --> 01:03.759
you can do multimedia things,

01:03.760 --> 01:05.140
things that pixels and.

01:06.800 --> 01:08.180
That type of manipulation,

01:09.110 --> 01:10.709
but what they did is they used the

01:10.940 --> 01:12.649
Eighty-seven, so the floating point

01:12.650 --> 01:14.267
registers, and so that meant that

01:14.450 --> 01:15.969
you couldn't mix X and floating

01:16.340 --> 01:17.599
point operations.

01:19.340 --> 01:20.749
So then what they did is they

01:20.750 --> 01:22.640
created the C instructions.

01:22.650 --> 01:23.924
So this is streaming ACMD,

01:24.500 --> 01:26.049
Extension's or SASE.

01:26.600 --> 01:27.874
And so what that added was

01:28.430 --> 01:30.409
what we have ACMD

01:30.410 --> 01:31.929
is single instruction, multiple

01:32.000 --> 01:32.839
data.

01:32.840 --> 01:34.039
So again, we can have one

01:34.040 --> 01:35.629
instruction that operates on

01:35.630 --> 01:37.519
multiple pieces of data and then

01:37.520 --> 01:39.284
hopefully that can be more efficient

01:39.530 --> 01:41.119
than having a lot of instructions go

01:41.120 --> 01:42.109
over that.

01:42.110 --> 01:43.990
And so they extended the Intel X

01:44.000 --> 01:45.349
eighty six architecture in order to

01:45.350 --> 01:47.299
do this and then they again use

01:47.300 --> 01:48.420
this in multimedia.

01:48.680 --> 01:50.659
So what this did

01:50.660 --> 01:52.081
is it's a plan to those Memex

01:52.250 --> 01:53.689
instructions and we'll see why in a

01:53.690 --> 01:54.690
second.

01:54.980 --> 01:56.750
And that's because they they did

01:57.470 --> 01:58.699
address those floating point

01:58.700 --> 01:59.840
operations issues.

02:00.470 --> 02:01.793
So C one came out in ninety

02:02.540 --> 02:04.089
nine. So not too much later.

02:04.340 --> 02:05.899
And again, it added some additional

02:05.900 --> 02:07.069
registers. So now we have one

02:07.070 --> 02:07.999
hundred and twenty eight bit

02:08.000 --> 02:10.039
registers, Xenome

02:10.050 --> 02:12.169
zero through Ximenes seven.

02:12.200 --> 02:13.869
And again these can be packed.

02:13.880 --> 02:15.409
So for example we could have four

02:15.410 --> 02:17.240
integers in each one of

02:17.270 --> 02:19.070
these Zemun registers.

02:19.080 --> 02:20.479
And so that allows us to very

02:20.480 --> 02:21.754
efficiently load data from

02:22.430 --> 02:24.439
RAM into that register

02:24.440 --> 02:25.959
and then do operations that are

02:26.060 --> 02:27.060
S.A.M.

02:27.380 --> 02:28.380
d applicable to

02:29.270 --> 02:30.270
that.

02:30.800 --> 02:32.599
And so additionally.

02:32.600 --> 02:33.776
So Intel and AMD sort of

02:34.520 --> 02:35.959
we're we're at a battle at this

02:35.960 --> 02:37.699
point. They they have been for quite

02:37.700 --> 02:39.590
a long time and so

02:39.620 --> 02:42.080
they added Xome eight through 15.

02:42.090 --> 02:43.168
And so then when Intel

02:44.060 --> 02:45.619
came out with their X sixty four

02:45.620 --> 02:46.969
architecture than they of course

02:46.970 --> 02:48.639
added those as well.

02:49.130 --> 02:51.349
So we have 16 registers

02:51.350 --> 02:52.771
that can be used for these SC

02:53.300 --> 02:54.300
instructions.

02:54.800 --> 02:55.800
And then in

02:56.750 --> 02:58.879
2001 SC two came out

02:58.880 --> 03:00.830
and this allowed them to

03:01.550 --> 03:04.069
use those memex instructions

03:04.070 --> 03:06.710
and they could use them registers.

03:07.130 --> 03:08.479
And so this meant that you could

03:08.480 --> 03:10.097
basically convert all in the next

03:10.190 --> 03:11.509
code into S.

03:11.510 --> 03:12.510
E code and then use

03:13.400 --> 03:15.115
the X and then registers instead of

03:15.260 --> 03:16.460
the floating point registers.

03:16.490 --> 03:18.205
And so this sort of made it so that

03:18.620 --> 03:20.389
we didn't need Emacs anymore.

03:20.390 --> 03:21.860
We had the SC two that anybody

03:22.550 --> 03:23.779
could use for libraries

03:24.590 --> 03:26.750
and we also added Sesi

03:27.140 --> 03:28.140
three and four.

03:28.160 --> 03:29.960
So three was in 2004

03:30.830 --> 03:32.055
and we can operate on the

03:32.750 --> 03:34.909
data within the same register.

03:34.920 --> 03:36.650
And so, for example, we could add

03:36.950 --> 03:38.299
all of the numbers stored in one

03:38.300 --> 03:39.721
register together at the same

03:40.370 --> 03:42.109
time. And so again, it provided sort

03:42.110 --> 03:43.939
of better flow for

03:43.940 --> 03:44.940
our assembly code.

03:45.080 --> 03:47.479
And then SASE four came out in 2006

03:47.930 --> 03:49.369
and it added a bunch of string and

03:49.370 --> 03:51.240
text functions and

03:51.340 --> 03:52.614
added some math operations

03:53.300 --> 03:55.249
like Sum's on absolute differences

03:55.250 --> 03:56.250
and dot product.

03:56.570 --> 03:58.187
But again, they keep adding it to

03:58.310 --> 04:00.199
make it better so that you could

04:00.200 --> 04:01.621
do more with the instructions

04:01.880 --> 04:03.680
instead of trying to do

04:04.460 --> 04:05.959
use a lot of instructions in order

04:05.960 --> 04:07.139
to do the same thing.

04:07.160 --> 04:08.630
And so that's why they added a

04:09.020 --> 04:10.700
bunch of these different extensions.

04:12.280 --> 04:14.169
And then if you want to be able

04:14.170 --> 04:16.510
to use these intrinsic functions

04:16.779 --> 04:18.489
within your code or registers,

04:18.820 --> 04:20.559
you can basically include different

04:20.560 --> 04:21.699
library headers.

04:21.700 --> 04:23.979
And so we have again, Max,

04:23.980 --> 04:26.019
SCC two, three,

04:26.410 --> 04:27.669
and they have different versions of

04:27.670 --> 04:29.170
four that came out.

04:29.650 --> 04:31.259
And then we have as.

04:33.070 --> 04:34.899
So the as and I so this

04:34.900 --> 04:35.900
is the

04:36.760 --> 04:38.560
advanced encryption standard or a

04:38.570 --> 04:40.629
yes, and then and I very cleverly

04:40.630 --> 04:41.949
named new instructions.

04:42.430 --> 04:44.559
And so this provides specific

04:44.560 --> 04:45.969
instructions that can be used for

04:45.970 --> 04:47.490
the encryption standard.

04:47.500 --> 04:48.921
So when we created a standard

04:49.480 --> 04:51.549
that the the advanced encryption

04:51.550 --> 04:52.922
standard, then anybody could

04:53.410 --> 04:54.635
use that. And so this was

04:55.330 --> 04:57.039
the standard used by everybody.

04:57.100 --> 04:59.259
And so it made sense for Intel

04:59.260 --> 05:00.879
to implement these inside of

05:00.880 --> 05:02.499
instructions instead of people

05:02.830 --> 05:04.149
trying to rewrite the code from

05:04.150 --> 05:04.929
scratch.

05:04.930 --> 05:06.369
And so Intel has a really nice

05:06.370 --> 05:07.742
documentation that describes

05:08.380 --> 05:09.879
all of these instructions and gives

05:09.880 --> 05:11.589
examples of how they can be used.

05:13.650 --> 05:15.059
So I'll just explain a little bit

05:15.060 --> 05:17.220
about the algorithm.

05:17.430 --> 05:18.509
So there are a couple of different

05:18.510 --> 05:19.790
parts that we have for this.

05:20.190 --> 05:21.539
So the first is going to be a key

05:21.540 --> 05:22.569
expansion. So we take

05:23.490 --> 05:25.156
the key and we end up expanding it

05:25.320 --> 05:26.759
or running it through a bunch of

05:27.000 --> 05:28.559
operations in order to

05:29.130 --> 05:31.199
mix all the bits for when we use

05:31.200 --> 05:32.200
the encryption.

05:33.030 --> 05:34.500
And so the different key sizes

05:35.310 --> 05:36.779
determine the number of rounds that

05:36.780 --> 05:38.279
we end up using. So we keep doing

05:38.280 --> 05:40.079
this thing for a certain this

05:40.080 --> 05:41.399
process for a certain number of

05:41.400 --> 05:42.539
rounds. And so if we're doing one

05:42.540 --> 05:43.439
hundred and twenty eight bid

05:43.440 --> 05:44.649
encryption, it's ten rounds.

05:44.650 --> 05:45.739
If we're doing a hundred ninety two,

05:45.750 --> 05:46.750
it's twelve.

05:46.860 --> 05:48.209
And if we're doing two fifty six,

05:48.210 --> 05:49.210
it's 14.

05:49.560 --> 05:51.177
And then when we do encryption we

05:51.480 --> 05:53.160
basically add the round key

05:53.850 --> 05:55.190
and then we do these things of

05:55.200 --> 05:56.729
substitute some bytes, shift some

05:56.730 --> 05:58.102
rows and mixed some rows and

05:58.560 --> 05:59.999
then we end up repeating that

06:00.210 --> 06:01.210
multiple times.

06:01.230 --> 06:02.879
And then at the end we do one final

06:02.880 --> 06:03.880
round that doesn't

06:04.740 --> 06:05.790
do the mix columns.

06:05.800 --> 06:07.839
So you see it substitutes bytes,

06:07.860 --> 06:09.569
it shifts rows and then it adds

06:09.570 --> 06:10.529
around key.

06:10.530 --> 06:11.759
And so it doesn't do that next

06:11.760 --> 06:13.328
column. So it's the last step is

06:13.560 --> 06:15.119
just a little bit different than all

06:15.120 --> 06:16.120
the rest.

06:17.510 --> 06:18.649
So, again, I pulled these out of the

06:18.650 --> 06:20.389
white paper that Intel produced, so

06:20.390 --> 06:22.879
they have different operations.

06:22.880 --> 06:24.769
So one is a key

06:24.770 --> 06:25.770
genesis.

06:25.910 --> 06:27.282
And so this is helping us to

06:27.290 --> 06:29.269
generate an encryption key.

06:29.600 --> 06:31.459
And we can see here that

06:31.460 --> 06:33.126
this takes basically two registers

06:33.680 --> 06:35.299
and then the round constant and we

06:35.300 --> 06:37.209
can see the round constants in here.

06:37.730 --> 06:39.570
And so it's

06:39.590 --> 06:41.354
very specifically defines what those

06:41.360 --> 06:42.349
round constants are.

06:42.350 --> 06:43.940
So we've got one, two, four, eight,

06:44.360 --> 06:46.729
10, 20, 40, 80,

06:46.730 --> 06:48.589
one, B and thirty six

06:48.590 --> 06:49.590
all in hex.

06:49.970 --> 06:50.970
And so we can see

06:51.920 --> 06:53.209
that they end up calling these on

06:53.210 --> 06:55.159
the on the register.

06:55.470 --> 06:56.539
We got a couple of different

06:56.540 --> 06:57.912
registers, we got our result

06:58.670 --> 06:59.899
register and then our one hundred

06:59.900 --> 07:01.120
and twenty eight that input.

07:01.130 --> 07:02.599
And so we use those in order to

07:02.600 --> 07:03.600
generate

07:04.730 --> 07:06.679
the key or do the key

07:06.680 --> 07:08.300
expansion from that.

07:09.960 --> 07:11.038
We also have as E.M.S.

07:12.060 --> 07:13.060
or a script, and

07:13.890 --> 07:15.959
so it's going to perform one round

07:15.960 --> 07:17.799
of ass encryption, so and

07:17.820 --> 07:19.709
then one is our input data and

07:19.710 --> 07:21.420
X and then two is our round key.

07:21.750 --> 07:23.569
And what this does is it shifts,

07:23.570 --> 07:25.236
throws, substitutes, bytes, mixes,

07:25.290 --> 07:26.907
columns, and then takes them one.

07:27.360 --> 07:28.410
An exorcist with

07:29.580 --> 07:30.903
maximum two and maximum two

07:31.470 --> 07:32.870
is our round key.

07:32.890 --> 07:34.949
So it's moving the data around

07:34.950 --> 07:36.779
and then doing an X or at the very

07:36.780 --> 07:37.780
end.

07:38.640 --> 07:40.680
We also have a blast,

07:41.010 --> 07:42.959
and so, again, that very last step,

07:42.960 --> 07:44.620
we don't mix columns, right?

07:44.650 --> 07:46.109
And so it basically does all those

07:46.110 --> 07:48.149
things that the encrypt does, but

07:48.150 --> 07:49.739
it doesn't do a mix columns right

07:49.740 --> 07:51.210
here. It just does the X or at

07:51.660 --> 07:52.660
the very end.

07:54.290 --> 07:56.059
We also have the similar operations

07:56.060 --> 07:58.399
for decryption, so we got SDI

07:58.400 --> 08:00.319
or Decrypt, and again, we

08:00.320 --> 08:01.609
have our input data and we have

08:01.610 --> 08:03.019
around key. And so this is going to

08:03.020 --> 08:05.079
provide that inverse operation.

08:05.090 --> 08:07.119
So we're going to decrypt the data.

08:07.730 --> 08:09.151
And so here it's invert shift

08:09.620 --> 08:11.739
rows and substitute bytes, invert

08:11.750 --> 08:13.579
mixed columns, and

08:13.580 --> 08:14.903
then we do an X or with the

08:15.410 --> 08:17.269
data. And again, we should end up

08:17.270 --> 08:18.529
getting the result that we had

08:18.530 --> 08:19.530
before.

08:19.880 --> 08:21.301
But just as the encrypt does,

08:22.100 --> 08:23.890
the decrypt has a last operation.

08:23.900 --> 08:25.321
So again, that last operation

08:25.970 --> 08:27.734
doesn't mix columns just like we did

08:27.950 --> 08:28.939
before.

08:28.940 --> 08:30.889
So again, it doesn't shift invert

08:30.890 --> 08:32.605
substitute bytes and then does an X

08:32.659 --> 08:33.659
or.

08:35.220 --> 08:37.259
And then because we have

08:37.679 --> 08:39.569
the keys, there is a we do end

08:39.570 --> 08:41.549
up doing an invert mix columns,

08:42.299 --> 08:43.965
but that ends up being operated on

08:44.039 --> 08:45.869
the key in the initial step

08:45.870 --> 08:47.880
and not inside of

08:48.240 --> 08:49.169
the decryption.

08:49.170 --> 08:51.509
And so they have this as emcee

08:51.510 --> 08:52.859
or invert next columns

08:53.460 --> 08:54.460
that will be used

08:55.320 --> 08:57.090
with the after we

08:57.210 --> 08:58.729
after we expand our key, we use

08:59.160 --> 09:01.259
this in order to properly

09:01.260 --> 09:02.436
prepare the inverted key

09:03.210 --> 09:04.210
for it.

09:05.670 --> 09:07.809
So today we talked about CNM

09:07.810 --> 09:09.749
Amex extensions and then the

09:09.750 --> 09:11.369
as an extension.

09:13.120 --> 09:14.349
So looking forward, we're going to

09:14.350 --> 09:16.059
look at some aiyaz libraries that

09:16.060 --> 09:17.979
you can use and either you

09:17.980 --> 09:19.809
can use them inside of C-code

09:19.810 --> 09:21.880
or you can use the intrinsics and

09:23.200 --> 09:25.059
generate reassembly code for

09:25.060 --> 09:26.060
that.

09:27.840 --> 09:30.149
So what are some of the specific

09:30.150 --> 09:31.150
instructions?

09:33.200 --> 09:34.500
Well, here's the whole list of them.

09:34.670 --> 09:36.250
So we got key Genesis,

09:36.560 --> 09:38.079
encrypt, encrypt last, decrypt,

09:38.360 --> 09:40.279
decrypt last and mixed

09:40.280 --> 09:41.280
columns.

09:43.320 --> 09:44.609
If you have questions, you can email

09:44.610 --> 09:46.470
me, Miller, M.J., you and Kidada,

09:46.560 --> 09:47.819
and you can find me on Twitter at

09:47.820 --> 09:48.570
Milhouse 30.

