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
SubBytesandShiftRowssteps 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 theShiftRowsstep as being performed first, while AMD documentation describesSubBytesas being performed first.) This also applies to theInvShiftRows/InvSubBytessteps of an AES decryption round. - For the intended AES decode flow under AES-NI (a series of
AESDECinstructions followed by anAESDECLAST), theAESDECinstruction performs theInvMixColumnsandAddRoundKeysteps 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 toAESDECcannot just be taken from the Rijndael key schedule directly, but instead has to be postprocessed by performing anInvMixColumnon the round key after the key schedule and before it's used withAESDEC[1] (this can be done with theAESIMCinstruction or by doing anAESENCLAST+AESDECsequence with the round key set to 0.)
This issue is specific to(V)AESDECand does not apply to round keys used with theAESENC,AESENCLASTorAESDECLASTinstructions.
Remove ads
CLMUL instructions
Remove ads
RDRAND and RDSEED
- The
RDRANDandRDSEEDinstructions 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.CFto 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.
- Under Intel APX, none of the Key Locker instructions can be encoded with the EVEX prefix - this prevents the use of the
r16-r31andxmm16-xmm31registers with these instructions. - The flags available for the
LOADIWKEYinstruction in the EAX register are: - The handle restrictions available for the explicit source argument to
ENCODEKEY128andENCODEKEY256are: - All of the AES Key Locker encode/decode instructions will check whether the handle is valid for the current IWKey and encode/decode data only if the handle is valid. These instructions will set the ZF flag to indicate whether the provided handle was valid (ZF=0) or not (ZF=1).
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 theREPprefix 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 withREPor not. (TheF3prefix is mandatory for all PadLock instructions exceptXSTORE.) - For the
REP XRNG2instruction, bits 1:0 of EDX are used to indicate whether the instruction should return hardware random numbers directly (EDX[1:0]==0) or return postprocessed numbers (EDX[1:0] ≠ 0). - As of 2024, the
REP XRNG2,REP XSHA384,REP XSHA512,REP MONTMUL2andREP XMODEXPinstructions 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. - The control word for
REP XCRYPT*is a 16-byte (128-bit) data structure with the following layout:If bit 5 is set in order to allow unaligned data, then theREP XCRYPT*instructions will use the 112 bytes directly after the control word as a scratchpad memory area for data realignment. - In addition to the new
REP XCRYPT-CTRinstruction, ACE2 also adds extra features to the otherREP XCRYPTinstructions: a digest mode for the CBC and CFB instructions, and the ability to use input/output data that are not 16-byte aligned for the non-ECB 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 per-chunk calculation is identical for SHA-384 and SHA-512 - as a result of this, the
REP XSHA384andREP XSHA512instructions perform identical operations. - The
REP MONTMULinstruction is only supported with an AddressSize of 32 bits - for this reason, the address-size override prefix (67h) is required in 16-bit and 64-bit modes, but disallowed in 32-bit mode. - The data structure to
REP MONTMULcontains 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): - For
REP MONTMUL2andREP XMODEXP, the modulus is required to be greater than both and , and is also required to be odd. The instructions will produce a #GP exception if this is not the case. - Given a bignum size of N bits, the scratchpad memory area pointed to by ES:rSI for the
REP MONTMUL2andREP XMODEXPmust 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. - The
CCS_ENCRYPTcontrol word in rAX has the following format:Remaining bits in rAX must be set to all-0s. Of bits 10:6 in rAX (block mode selection), exactly one bit must be set, or else behavior is undefined. - The supported functions in bits 5:0 of EDX for the
SM2instruction are:
Remove ads
References
Wikiwand - on
Seamless Wikipedia browsing. On steroids.
Remove ads