Top Qs
Timeline
Chat
Perspective
List of x86 cryptographic instructions
From Wikipedia, the free encyclopedia
Remove ads
Instructions that have been added to the x86 instruction set in order to assist efficient calculation of cryptographic primitives, such as e.g. AES encryption, SHA hash calculation and random number generation.
Intel AES instructions
Summarize
Perspective
6 new instructions.
- The
SubBytes
andShiftRows
steps of an AES encryption round may be performed in either order - the result of the instruction is the same either way.[1] (Intel documentation describes theShiftRows
step as being performed first, while AMD documentation describesSubBytes
as being performed first.) This also applies to theInvShiftRows
/InvSubBytes
steps of an AES decryption round. - For the intended AES decode flow under AES-NI (a series of
AESDEC
instructions followed by anAESDECLAST
), theAESDEC
instruction performs theInvMixColumns
andAddRoundKey
steps in the opposite order of what the AES specification (FIPS 197) indicates.
As a result of this, the AES round key provided as the second source argument toAESDEC
cannot just be taken from the Rijndael key schedule directly, but instead has to be postprocessed by performing anInvMixColumn
on the round key after the key schedule and before it's used withAESDEC
[1] (this can be done with theAESIMC
instruction or by doing anAESENCLAST
+AESDEC
sequence with the round key set to 0.)
This issue is specific to(V)AESDEC
and does not apply to round keys used with theAESENC
,AESENCLAST
orAESDECLAST
instructions.
Remove ads
CLMUL instructions
Remove ads
RDRAND and RDSEED
- The
RDRAND
andRDSEED
instructions may fail to obtain and return a random number if the CPU's random number generators cannot keep up with the issuing of these instructions – if this happens, then software may retry the instructions (although the number of retries should be limited, in order to ensure forward progress[2]). The instructions setEFLAGS.CF
to 1 if a random number was successfully obtained and 0 otherwise. ForRDSEED
, failure to obtain a random number will also set the instruction's destination register to 0.
Intel SHA and SM3 instructions
Summarize
Perspective
These instructions provide support for cryptographic hash functions such as SHA-1, SHA-256, SHA-512 and SM3. Each of these hash functions works on fixed-size data blocks, where the processing of each data-block mostly consists of two major phases:[3]
- First expand the data-block using a message schedule (that is specific to each hash function)
- Then perform a series of rounds of a compression function to combine the expanded data into a hash state.
For each of the supported hash functions, separate instructions are provided to help compute the message schedule (instructions with "MSG" in their names) and to help perform the compression function rounds (instructions with "RND" in their names).
Remove ads
Intel Key Locker instructions
Summarize
Perspective
These instructions, available in Tiger Lake and later Intel processors, are designed to enable encryption/decryption with an AES key without having access to any unencrypted copies of the key during the actual encryption/decryption process.
Remove ads
VIA/Zhaoxin PadLock instructions
Summarize
Perspective
The VIA/Zhaoxin PadLock instructions are instructions designed to apply cryptographic primitives in bulk, similar to the 8086 repeated string instructions. As such, unless otherwise specified, they take, as applicable, pointers to source data in ES:rSI and destination data in ES:rDI, and a data-size or count in rCX. Like the old string instructions, they are all designed to be interruptible.[4][5]
Remove ads
Footnotes
- For instruction mnemonics that are listed with a hyphen, different VIA PadLock documents differ with respect to whether the instruction names have a hyphen or not (e.g. version 1.0 of the ACE programming guide uses the hyphens,[6] while v1.66 does not.[4]) and assemblers may accept instruction mnemonics with or without the hyphen - e.g. GNU Binutils rev 2.17 and later accepts both.
Some assemblers may also consider theREP
prefix optional for instructions other thanXSTORE
- with such assemblers, the PadLock instructions will be assembled with oneF3
(REP
) prefix byte regardless of whether the assembly instruction is written withREP
or not. (TheF3
prefix is mandatory for all PadLock instructions exceptXSTORE
.) - On some processors that support PadLock, the
REP XSTORE
instruction (but notREP XRNG2
) may write not just the number of bytes specified in ECX, but up to 7 additional bytes as well.[7] - As of 2024, the
REP XRNG2
,REP XSHA384
,REP XSHA512
,REP MONTMUL2
andREP XMODEXP
instructions exist as documented instructions only on Zhaoxin processors.[5]
A VIA-provided OpenSSL patch from 2011[8] indicates that these instructions were present on the VIA Nano, however VIA has not published documentation for these instructions. - On VIA Nano and later processors, setting rAX to an all-1s value for the
REP XSHA*
instructions will enable an alternate operation mode, where rCX specifies the number of 64-byte blocks, and where the standard FIPS-180-2 length extension procedure at the end of the hash calculation is omitted. This makes for a variant more suitable for data streaming than the original EAX=0 variant.[10] This functionality also exists forCCS_HASH
.
- The data structure to
REP MONTMUL
contains six 32-bit elements, where the first one is a negated modular inverse of the bottom 32 bits of the modulus and the remaining 5 are pointers to various memory buffers (each of which uses the ES segment and must be 16-byte aligned): - Given a bignum size of N bits, the scratchpad memory area pointed to by ES:rSI for the
REP MONTMUL2
andREP XMODEXP
must have a size of at least bytes (e.g. for a 2048-bit bignum size, the scratchpad must be at least 808 bytes). Also, before starting either of these instructions, the 8 first bytes of this scratchpad must be zeroed out and the bignum size given in ECX must also be written as a 64-bit integer to the next 8 bytes.
Remove ads
References
Wikiwand - on
Seamless Wikipedia browsing. On steroids.
Remove ads