2 The UEFI Inline Cryptographic Interface protocol provides services to abstract
3 access to inline cryptographic capabilities.
5 Copyright (c) 2015-2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
8 @par Revision Reference:
9 This Protocol was introduced in UEFI Specification 2.5.
13 #ifndef __BLOCK_IO_CRYPTO_H__
14 #define __BLOCK_IO_CRYPTO_H__
16 #include <Protocol/BlockIo.h>
18 #define EFI_BLOCK_IO_CRYPTO_PROTOCOL_GUID \
20 0xa00490ba, 0x3f1a, 0x4b4c, {0xab, 0x90, 0x4f, 0xa9, 0x97, 0x26, 0xa1, 0xe8} \
23 typedef struct _EFI_BLOCK_IO_CRYPTO_PROTOCOL EFI_BLOCK_IO_CRYPTO_PROTOCOL
;
26 /// The struct of Block I/O Crypto Token.
30 // If Event is NULL, then blocking I/O is performed. If Event is not NULL and
31 // non-blocking I/O is supported, then non-blocking I/O is performed, and
32 // Event will be signaled when the read request is completed and data was
33 // decrypted (when Index was specified).
37 // Defines whether or not the signaled event encountered an error.
39 EFI_STATUS TransactionStatus
;
40 } EFI_BLOCK_IO_CRYPTO_TOKEN
;
44 // GUID of the algorithm.
48 // Specifies KeySizein bits used with this Algorithm.
52 // Specifies bitmask of block sizes supported by this algorithm.
53 // Bit j being set means that 2^j bytes crypto block size is supported.
55 UINT64 CryptoBlockSizeBitMask
;
56 } EFI_BLOCK_IO_CRYPTO_CAPABILITY
;
59 /// EFI_BLOCK_IO_CRYPTO_IV_INPUT structure is used as a common header in CryptoIvInput
60 /// parameters passed to the ReadExtended and WriteExtended methods for Inline
61 /// Cryptographic Interface.
62 /// Its purpose is to pass size of the entire CryptoIvInputparameter memory buffer to
63 /// the Inline Cryptographic Interface.
67 } EFI_BLOCK_IO_CRYPTO_IV_INPUT
;
69 #define EFI_BLOCK_IO_CRYPTO_ALGO_GUID_AES_XTS \
71 0x2f87ba6a, 0x5c04, 0x4385, {0xa7, 0x80, 0xf3, 0xbf, 0x78, 0xa9, 0x7b, 0xec} \
74 extern EFI_GUID gEfiBlockIoCryptoAlgoAesXtsGuid
;
77 EFI_BLOCK_IO_CRYPTO_IV_INPUT Header
;
78 UINT64 CryptoBlockNumber
;
79 UINT64 CryptoBlockByteSize
;
80 } EFI_BLOCK_IO_CRYPTO_IV_INPUT_AES_XTS
;
82 #define EFI_BLOCK_IO_CRYPTO_ALGO_GUID_AES_CBC_MICROSOFT_BITLOCKER \
84 0x689e4c62, 0x70bf, 0x4cf3, {0x88, 0xbb, 0x33, 0xb3, 0x18, 0x26, 0x86, 0x70} \
87 extern EFI_GUID gEfiBlockIoCryptoAlgoAesCbcMsBitlockerGuid
;
90 EFI_BLOCK_IO_CRYPTO_IV_INPUT Header
;
91 UINT64 CryptoBlockByteOffset
;
92 UINT64 CryptoBlockByteSize
;
93 } EFI_BLOCK_IO_CRYPTO_IV_INPUT_AES_CBC_MICROSOFT_BITLOCKER
;
95 #define EFI_BLOCK_IO_CRYPTO_INDEX_ANY 0xFFFFFFFFFFFFFFFF
99 // Is inline cryptographic capability supported on this device.
103 // Maximum number of keys that can be configured at the same time.
107 // Number of supported capabilities.
109 UINT64 CapabilityCount
;
111 // Array of supported capabilities.
113 EFI_BLOCK_IO_CRYPTO_CAPABILITY Capabilities
[1];
114 } EFI_BLOCK_IO_CRYPTO_CAPABILITIES
;
118 // Configuration table index. A special Index EFI_BLOCK_IO_CRYPTO_INDEX_ANY can be
119 // used to set any available entry in the configuration table.
123 // Identifies the owner of the configuration table entry. Entry can also be used
124 // with the Nil value to clear key from the configuration table index.
126 EFI_GUID KeyOwnerGuid
;
128 // A supported capability to be used. The CryptoBlockSizeBitMask field of the
129 // structure should have only one bit set from the supported mask.
131 EFI_BLOCK_IO_CRYPTO_CAPABILITY Capability
;
133 // Pointer to the key. The size of the key is defined by the KeySize field of
134 // the capability specified by the Capability parameter.
137 } EFI_BLOCK_IO_CRYPTO_CONFIGURATION_TABLE_ENTRY
;
141 // Configuration table index.
145 // Identifies the current owner of the entry.
147 EFI_GUID KeyOwnerGuid
;
149 // The capability to be used. The CryptoBlockSizeBitMask field of the structure
150 // has only one bit set from the supported mask.
152 EFI_BLOCK_IO_CRYPTO_CAPABILITY Capability
;
153 } EFI_BLOCK_IO_CRYPTO_RESPONSE_CONFIGURATION_ENTRY
;
156 Reset the block device hardware.
158 The Reset() function resets the block device hardware.
160 As part of the initialization process, the firmware/device will make a quick but
161 reasonable attempt to verify that the device is functioning.
163 If the ExtendedVerificationflag is TRUE the firmware may take an extended amount
164 of time to verify the device is operating on reset. Otherwise the reset operation
165 is to occur as quickly as possible.
167 The hardware verification process is not defined by this specification and is left
168 up to the platform firmware or driver to implement.
170 @param[in] This Pointer to the EFI_BLOCK_IO_CRYPTO_PROTOCOL instance.
171 @param[in] ExtendedVerification Indicates that the driver may perform a more exhausive
172 verification operation of the device during reset.
174 @retval EFI_SUCCESS The block device was reset.
175 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could
177 @retval EFI_INVALID_PARAMETER This is NULL.
182 (EFIAPI
*EFI_BLOCK_IO_CRYPTO_RESET
) (
183 IN EFI_BLOCK_IO_CRYPTO_PROTOCOL
*This
,
184 IN BOOLEAN ExtendedVerification
188 Get the capabilities of the underlying inline cryptographic interface.
190 The GetCapabilities() function determines whether pre-OS controllable inline crypto
191 is supported by the system for the current disk and, if so, returns the capabilities
192 of the crypto engine.
194 The caller is responsible for providing the Capabilities structure with a sufficient
197 If the structure is too small, the EFI_BUFFER_TOO_SMALL error code is returned and the
198 CapabilityCount field contains the number of entries needed to contain the capabilities.
200 @param[in] This Pointer to the EFI_BLOCK_IO_CRYPTO_PROTOCOL instance.
201 @param[out] Capabilities Pointer to the EFI_BLOCK_IO_CRYPTO_CAPABILITIES structure.
203 @retval EFI_SUCCESS The ICI is ready for use.
204 @retval EFI_BUFFER_TOO_SMALL The Capabilities structure was too small. The number of
205 entries needed is returned in the CapabilityCount field
207 @retval EFI_NO_RESPONSE No response was received from the ICI.
208 @retval EFI_DEVICE_ERROR An error occurred when attempting to access the ICI.
209 @retval EFI_INVALID_PARAMETER This is NULL.
210 @retval EFI_INVALID_PARAMETER Capabilities is NULL.
215 (EFIAPI
*EFI_BLOCK_IO_CRYPTO_GET_CAPABILITIES
) (
216 IN EFI_BLOCK_IO_CRYPTO_PROTOCOL
*This
,
217 OUT EFI_BLOCK_IO_CRYPTO_CAPABILITIES
*Capabilities
221 Set the configuration of the underlying inline cryptographic interface.
223 The SetConfiguration() function allows the user to set the current configuration of the
224 inline cryptographic interface and should be called before attempting any crypto operations.
226 This configures the configuration table entries with algorithms, key sizes and keys. Each
227 configured entry can later be referred to by index at the time of storage transaction.
229 The configuration table index will refer to the combination ofKeyOwnerGuid, Algorithm, and
232 KeyOwnerGuid identifies the component taking ownership of the entry. It helps components to
233 identify their own entries, cooperate with other owner components, and avoid conflicts. This
234 Guid identifier is there to help coordination between cooperating components and not a security
235 or synchronization feature. The Nil GUID can be used by a component to release use of entry
236 owned. It is also used to identify potentially available entries (see GetConfiguration).
238 CryptoKey specifies algorithm-specific key material to use within parameters of selected crypto
241 This function is called infrequently typically once, on device start, before IO starts. It
242 can be called at later times in cases the number of keysused on the drive is higher than what
243 can be configured at a time or a new key has to be added.
245 Components setting or changing an entry or entries for a given index or indices must ensure
246 that IO referencing affected indices is temporarily blocked (run-down) at the time of change.
248 Indices parameters in each parameter table entry allow to set only a portion of the available
249 table entries in the crypto module anywhere from single entry to entire table supported.
251 If corresponding table entry or entries being set are already in use by another owner the call
252 should be failed and none of the entries should be modified. The interface implementation must
253 enforce atomicity of this operation (should either succeed fully or fail completely without
256 Note that components using GetConfiguration command to discover available entries should be
257 prepared that by the time of calling SetConfiguration the previously available entry may have
258 become occupied. Such components should be prepared to re-try the sequence of operations.
260 Alternatively EFI_BLOCK_IO_CRYPTO_INDEX_ANY can be used to have the implementation discover
261 and allocate available,if any, indices atomically.
263 An optional ResultingTable pointer can be provided by the caller to receive the newly configured
264 entries. The array provided by the caller must have at least ConfigurationCount of entries.
266 @param[in] This Pointer to the EFI_BLOCK_IO_CRYPTO_PROTOCOL instance.
267 @param[in] ConfigurationCount Number of entries being configured with this call.
268 @param[in] ConfigurationTable Pointer to a table used to populate the configuration table.
269 @param[out] ResultingTable Optional pointer to a table that receives the newly configured
272 @retval EFI_SUCCESS The ICI is ready for use.
273 @retval EFI_NO_RESPONSE No response was received from the ICI.
274 @retval EFI_DEVICE_ERROR An error occurred when attempting to access the ICI.
275 @retval EFI_INVALID_PARAMETER This is NULL.
276 @retval EFI_INVALID_PARAMETER ConfigurationTable is NULL.
277 @retval EFI_INVALID_PARAMETER ConfigurationCount is 0.
278 @retval EFI_OUT_OF_RESOURCES Could not find the requested number of available entries in the
284 (EFIAPI
*EFI_BLOCK_IO_CRYPTO_SET_CONFIGURATION
) (
285 IN EFI_BLOCK_IO_CRYPTO_PROTOCOL
*This
,
286 IN UINT64 ConfigurationCount
,
287 IN EFI_BLOCK_IO_CRYPTO_CONFIGURATION_TABLE_ENTRY
*ConfigurationTable
,
288 OUT EFI_BLOCK_IO_CRYPTO_RESPONSE_CONFIGURATION_ENTRY
*ResultingTable OPTIONAL
292 Get the configuration of the underlying inline cryptographic interface.
294 The GetConfiguration() function allows the user to get the configuration of the inline
295 cryptographic interface.
297 Retrieves, entirely or partially, the currently configured key table. Note that the keys
298 themselves are not retrieved, but rather just indices, owner GUIDs and capabilities.
300 If fewer entries than specified by ConfigurationCount are returned, the Index field of the
301 unused entries is set to EFI_BLOCK_IO_CRYPTO_INDEX_ANY.
303 @param[in] This Pointer to the EFI_BLOCK_IO_CRYPTO_PROTOCOL instance.
304 @param[in] StartIndex Configuration table index at which to start the configuration
306 @param[in] ConfigurationCount Number of entries to return in the response table.
307 @param[in] KeyOwnerGuid Optional parameter to filter response down to entries with a
308 given owner. A pointer to the Nil value can be used to return
309 available entries. Set to NULL when no owner filtering is required.
310 @param[out] ConfigurationTable Table of configured configuration table entries (with no CryptoKey
311 returned): configuration table index, KeyOwnerGuid, Capability.
312 Should have sufficient space to store up to ConfigurationCount
315 @retval EFI_SUCCESS The ICI is ready for use.
316 @retval EFI_NO_RESPONSE No response was received from the ICI.
317 @retval EFI_DEVICE_ERROR An error occurred when attempting to access the ICI.
318 @retval EFI_INVALID_PARAMETER This is NULL.
319 @retval EFI_INVALID_PARAMETER Configuration table is NULL.
320 @retval EFI_INVALID_PARAMETER StartIndex is out of bounds.
325 (EFIAPI
*EFI_BLOCK_IO_CRYPTO_GET_CONFIGURATION
) (
326 IN EFI_BLOCK_IO_CRYPTO_PROTOCOL
*This
,
327 IN UINT64 StartIndex
,
328 IN UINT64 ConfigurationCount
,
329 IN EFI_GUID
*KeyOwnerGuid OPTIONAL
,
330 OUT EFI_BLOCK_IO_CRYPTO_RESPONSE_CONFIGURATION_ENTRY
*ConfigurationTable
334 Reads the requested number of blocks from the device and optionally decrypts
337 TheReadExtended() function allows the caller to perform a storage device read
338 operation. The function reads the requested number of blocks from the device
339 and then if Index is specified decrypts them inline. All the blocks are read
340 and decrypted (if decryption requested), or an error is returned.
342 If there is no media in the device, the function returns EFI_NO_MEDIA. If the
343 MediaId is not the ID for the current media in the device, the function returns
346 If EFI_DEVICE_ERROR, EFI_NO_MEDIA, or EFI_MEDIA_CHANGED is returned and nonblocking
347 I/O is being used, the Event associated with this request will not be signaled.
349 In addition to standard storage transaction parameters (LBA, IO size, and buffer),
350 this command will also specify a configuration table Index and CryptoIvInput
351 when data has to be decrypted inline by the controller after being read from
352 the storage device. If an Index parameter is not specified, no decryption is
355 @param[in] This Pointer to the EFI_BLOCK_IO_CRYPTO_PROTOCOL instance.
356 @param[in] MediaId The media ID that the read request is for.
357 @param[in] LBA The starting logical block address to read from on
359 @param[in, out] Token A pointer to the token associated with the transaction.
360 @param[in] BufferSize The size of the Buffer in bytes. This must be a multiple
361 of the intrinsic block size of the device.
362 @param[out] Buffer A pointer to the destination buffer for the data. The
363 caller is responsible for either having implicit or
364 explicit ownership of the buffer.
365 @param[in] Index A pointer to the configuration table index. This is
367 @param[in] CryptoIvInput A pointer to a buffer that contains additional
368 cryptographic parameters as required by the capability
369 referenced by the configuration table index, such as
370 cryptographic initialization vector.
372 @retval EFI_SUCCESS The read request was queued if Token-> Event is not NULL.
373 The data was read correctly from the device if the
374 Token->Event is NULL.
375 @retval EFI_DEVICE_ERROR The device reported an error while attempting to perform
376 the read operation and/or decryption operation.
377 @retval EFI_NO_MEDIA There is no media in the device.
378 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
379 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic
380 block size of the device.
381 @retval EFI_INVALID_PARAMETER This is NULL, or the read request contains LBAs that are
382 not valid, or the buffer is not on proper alignment.
383 @retval EFI_INVALID_PARAMETER CryptoIvInput is incorrect.
384 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of
390 (EFIAPI
*EFI_BLOCK_IO_CRYPTO_READ_EXTENDED
) (
391 IN EFI_BLOCK_IO_CRYPTO_PROTOCOL
*This
,
394 IN OUT EFI_BLOCK_IO_CRYPTO_TOKEN
*Token
,
395 IN UINT64 BufferSize
,
397 IN UINT64
*Index OPTIONAL
,
398 IN VOID
*CryptoIvInput OPTIONAL
402 Optionally encrypts a specified number of blocks inline and then writes to the
405 The WriteExtended() function allows the caller to perform a storage device write
406 operation. The function encrypts the requested number of blocks inline if Index
407 is specified and then writes them to the device. All the blocks are encrypted
408 (if encryption requested) and written, or an error is returned.
410 If there is no media in the device, the function returns EFI_NO_MEDIA. If the
411 MediaId is not the ID for the current media in the device, the function returns
414 If EFI_DEVICE_ERROR, EFI_NO_MEDIA, or EFI_MEDIA_CHANGED is returned and nonblocking
415 I/O is being used, the Event associated with this request will not be signaled.
417 In addition to standard storage transaction parameters (LBA, IO size, and buffer),
418 this command will also specify a configuration table Index and a CryptoIvInput
419 when data has to be decrypted inline by the controller before being written to
420 the storage device. If no Index parameter is specified, no encryption is performed.
422 @param[in] This Pointer to the EFI_BLOCK_IO_CRYPTO_PROTOCOL instance.
423 @param[in] MediaId The media ID that the read request is for.
424 @param[in] LBA The starting logical block address to read from on
426 @param[in, out] Token A pointer to the token associated with the transaction.
427 @param[in] BufferSize The size of the Buffer in bytes. This must be a multiple
428 of the intrinsic block size of the device.
429 @param[in] Buffer A pointer to the source buffer for the data.
430 @param[in] Index A pointer to the configuration table index. This is
432 @param[in] CryptoIvInput A pointer to a buffer that contains additional
433 cryptographic parameters as required by the capability
434 referenced by the configuration table index, such as
435 cryptographic initialization vector.
437 @retval EFI_SUCCESS The request to encrypt (optionally) and write was queued
438 if Event is not NULL. The data was encrypted (optionally)
439 and written correctly to the device if the Event is NULL.
440 @retval EFI_WRITE_PROTECTED The device cannot be written to.
441 @retval EFI_NO_MEDIA There is no media in the device.
442 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
443 @retval EFI_DEVICE_ERROR The device reported an error while attempting to encrypt
444 blocks or to perform the write operation.
445 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic
446 block size of the device.
447 @retval EFI_INVALID_PARAMETER This is NULL, or the write request contains LBAs that are
448 not valid, or the buffer is not on proper alignment.
449 @retval EFI_INVALID_PARAMETER CryptoIvInput is incorrect.
450 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of
456 (EFIAPI
*EFI_BLOCK_IO_CRYPTO_WRITE_EXTENDED
) (
457 IN EFI_BLOCK_IO_CRYPTO_PROTOCOL
*This
,
460 IN OUT EFI_BLOCK_IO_CRYPTO_TOKEN
*Token
,
461 IN UINT64 BufferSize
,
463 IN UINT64
*Index OPTIONAL
,
464 IN VOID
*CryptoIvInput OPTIONAL
468 Flushes all modified data toa physical block device.
470 The FlushBlocks() function flushes all modified data to the physical block device.
471 Any modified data that has to be encrypted must have been already encrypted as a
472 part of WriteExtended() operation - inline crypto operation cannot be a part of
475 All data written to the device prior to the flush must be physically written before
476 returning EFI_SUCCESS from this function. This would include any cached data the
477 driver may have cached, and cached data the device may have cached. A flush may
478 cause a read request following the flush to force a device access.
480 If EFI_DEVICE_ERROR, EFI_NO_MEDIA, EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is
481 returned and non-blocking I/O is being used, the Event associated with this request
482 will not be signaled.
484 @param[in] This Pointer to the EFI_BLOCK_IO_CRYPTO_PROTOCOL instance.
485 @param[in, out] Token A pointer to the token associated with the transaction.
487 @retval EFI_SUCCESS The flush request was queued if Event is not NULL. All
488 outstanding data was written correctly to the device if
490 @retval EFI_DEVICE_ERROR The device reported an error while attempting to write data.
491 @retval EFI_WRITE_PROTECTED The device cannot be written to.
492 @retval EFI_NO_MEDIA There is no media in the device.
493 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
494 @retval EFI_INVALID_PARAMETER This is NULL.
495 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of
501 (EFIAPI
*EFI_BLOCK_IO_CRYPTO_FLUSH
) (
502 IN EFI_BLOCK_IO_CRYPTO_PROTOCOL
*This
,
503 IN OUT EFI_BLOCK_IO_CRYPTO_TOKEN
*Token
507 /// The EFI_BLOCK_IO_CRYPTO_PROTOCOL defines a UEFI protocol that can be used by UEFI
508 /// drivers and applications to perform block encryption on a storage device, such as UFS.
510 struct _EFI_BLOCK_IO_CRYPTO_PROTOCOL
{
511 EFI_BLOCK_IO_MEDIA
*Media
;
512 EFI_BLOCK_IO_CRYPTO_RESET Reset
;
513 EFI_BLOCK_IO_CRYPTO_GET_CAPABILITIES GetCapabilities
;
514 EFI_BLOCK_IO_CRYPTO_SET_CONFIGURATION SetConfiguration
;
515 EFI_BLOCK_IO_CRYPTO_GET_CONFIGURATION GetConfiguration
;
516 EFI_BLOCK_IO_CRYPTO_READ_EXTENDED ReadExtended
;
517 EFI_BLOCK_IO_CRYPTO_WRITE_EXTENDED WriteExtended
;
518 EFI_BLOCK_IO_CRYPTO_FLUSH FlushBlocks
;
521 extern EFI_GUID gEfiBlockIoCryptoProtocolGuid
;