UFS 15 - UFS RPMB operation

UFS 1 - Introduction to UFS Architecture 1
UFS 2 - Introduction to UFS Architecture 2
UFS 3 - UFS RPMB
UFS 4 - UFS Boot
UFS 5 - UFS UIC Layer: MIPI M-PHY
UFS 6 - UAP – SCSI Commands (1)
UFS 7 - UAP – SCSI Commands (2)
UFS 8 - UAP - SCSI Commands (3)
UFS 9 - UAP - SCSI Commands (4)
UFS 10 - UAP - SCSI Commands (5)
UFS 11 - UFS RPMB partition function verification
UFS 12 - UAP - SCSI Commands (6)
UFS 13 - Logical Unit Management
UFS 14 - UFS RPMB security read and write commands

In this blog post, we will introduce RPMB's Authentication Key Programming, Read Counter Value, Authenticated Data Write, Authenticated Data Read and other operations

1 Request Type Message Delivery

  • Only one RPMB operation can be executed at any time.
  • Only one RPMB operation can be performed at any time.
    • An initiator sends request type message to RPMB well known logical unit to request the execution of an operation.
    • The initiator sends a request type message to the RPMB W-LUN to request an operation to be performed.
  • To deliver a request type message, the initiator sends a SECURITY PROTOCOL OUT command with SECURITY PROTOCOL field is set to ECh (i.e., the JEDEC Universal Flash Storage) and indicating the target RPMB region in the SECURITY PROTOCOL SPECIFIC field.
  • To deliver a request type message, the initiator sends a SECURITY PROTOCOL OUT command with the SECURITY PROTOCOL field set to ECh (i.e., JEDEC Generic Flash Storage) and indicating the target RPMB region in the SECURITY PROTOCOL SPECIFIC field.
  • For an authenticated data write request, the data to be written into the RPMB data area is included in the request message. The maximum data size in a single Authenticated Data Write request is equal to bRPMB_ReadWriteSize × 256 bytes; multiple Authenticated Data Write operations should be executed if the desired data size exceeds this value.
  • For authenticated data write requests, the data to be written to the RPMB data area is included in the request message. The maximum data size of a single Authenticated Data Write request is equal to bRPMB_ReadWriteSize × 256 bytes; if the required data size exceeds this value, multiple authenticated data write operations should be performed .
  • For SECURITY PROTOCOL OUT command, the Flags.W in the COMMAND UPIU is set to one since data is transferred from the host to the device.
  • For the SECURITY PROTOCOL OUT command, Flags.W in COMMAND UPIU is set to 1 because data is transferred from the host to the device.
  • Table 12.17 defines the Expected Data Transfer Length field value in the COMMAND UPIU for the various cases.
  • Table 12.17 defines the expected data transfer length field values ​​in COMMAND UPIU for various cases.
    insert image description here
  • The device indicates to the host that it is ready to receive the request type message sending READY TO TRANSFER UPIU. If the Expected Data Transfer Length is 512 byte, then Data Buffer Offset field shall be set to a value of zero and Data Transfer Count field shall be set to a value of 512.
  • The device indicates to the host that it is ready to receive request type messages, sending READY TO TRANSFER UPIU. If the expected data transfer length is 512 bytes, the Data Buffer Offset field should be set to a value of 0 and the Data Transfer Count field should be set to a value of 512.
  • The number of bytes requested in a single READY TO TRANSFER UPIU shall not be greater than the value indicated by bMaxDataOutSize attribute. A single READY TO TRANSFER UPIU may request the transfer of one or more RPMB Messages.
  • The number of bytes requested in a single READY TO TRANSFER UPIU shall not be greater than the value indicated by the bMaxDataOutSize attribute. A single prepare-to-transfer UPIU may request the transmission of one or more RPMB messages.
  • In response to each READY TO TRANSFER UPIU, the host delivers the requested portion of the message sending DATA OUT UPIU.
  • In response to each READY TO TRANSFER UPIU, the host transmits the request part of the message to send a DATA OUT UPIU.
  • To complete the SECURITY PROTOCOL OUT command, the device returns a RESPONSE UPIU with the status.
  • To complete a SECURITY PROTOCOL OUT command, the device returns a RESPONSE UPIU with status.
  • Figure 12.2 depicts a request type message delivery. The application client loads the RPMB Message in the Data Out Buffer and indicates the target RPMB Region in SECURITY PROTOCOL SPECIFIC field.
  • Figure 12.2 depicts message passing for request types. The application client loads the RPMB message into the data output buffer and indicates the target RPMB area in the security protocol specific field.
    insert image description here
    This description corresponds to the struct sec_proto_cdb structure in the ufs-utils open source tool, and corresponds to the sec_out_cmd and sec_in_cmd in the scsi_security_out and scsi_security_in interfaces.
#define SEC_PROTOCOL_CMD_SIZE           (12)
#define SEC_PROTOCOL_UFS                (0xEC)
#define SECURITY_PROTOCOL_IN  0xa2
#define SECURITY_PROTOCOL_OUT 0xb5

unsigned char sec_out_cmd[SEC_PROTOCOL_CMD_SIZE] = {
    
     
                        SECURITY_PROTOCOL_OUT, SEC_PROTOCOL_UFS,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

unsigned char sec_in_cmd[SEC_PROTOCOL_CMD_SIZE] = {
    
    
                        SECURITY_PROTOCOL_IN, SEC_PROTOCOL_UFS,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0};


/*
 * CDB format of SECURITY PROTOCOL IN/OUT commands
 * (JEDEC Standard No. 220D, Page 264)
 */
struct sec_proto_cdb {
    
    
    /*  
     * OPERATION CODE = A2h for SECURITY PROTOCOL IN command,
     * OPERATION CODE = B5h for SECURITY PROTOCOL OUT command.
     */
    uint8_t opcode;
    /* SECURITY PROTOCOL = ECh (JEDEC Universal Flash Storage) */
    uint8_t sec_proto;
    /*  
     * The SECURITY PROTOCOL SPECIFIC field specifies the RPMB Protocol ID.
     * CDB Byte 2 = 00h and CDB Byte 3 = 01h for RPMB Region 0.
     */
    uint8_t cdb_byte_2;
    uint8_t cdb_byte_3;
    /*  
     * Byte 4 and 5 are reserved.
     */
    uint8_t cdb_byte_4;
    uint8_t cdb_byte_5;
    /* ALLOCATION/TRANSFER LENGTH in big-endian */                                                                                                                                                                 
    uint32_t length;
    /* Byte 9 is reserved. */
    uint8_t cdb_byte_10;
    /* CONTROL = 00h. */
    uint8_t ctrl;
} __packed;

2 Response Type Message Delivery

  • A initiator requests the RPMB well known logical unit to send a response type message to retrieve the result of a previous operation, to retrieve the Write Counter, to retrieve data from the RPMB data area, or to retrieve the contents of a Secure Write Protect Configuration Block.
  • The initiator requests that the RPMB well-known logical unit send a response type message to retrieve the results of previous operations, retrieve write counters, retrieve data from the RPMB data area, or retrieve secure write-protected configuration blocks.
  • To request the delivery of a response type message, the host sends a SECURITY PROTOCOL IN command with SECURITY PROTOCOL field is set to ECh (i.e., the JEDEC Universal Flash Storage) and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field.
  • To request delivery of a response type message, the host sends a SECURITY PROTOCOL IN command with the SECURITY PROTOCOL field set to ECh (ie, JEDEC Universal Flash Storage) and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field.
  • For an authenticated data read the data from the RPMB data area is included in the response message.
  • For authenticated data reads, data from the RPMB data area is included in the response message.
  • For SECURITY PROTOCOL IN command, the Flags.R in the COMMAND UPIU is set to one since data is transferred from the device to the host.
  • For SECURITY PROTOCOL IN commands, Flags.R in COMMAND UPIU is set to 1 as data is transferred from the device to the host.
  • Table 12.18 defines the Expected Data Transfer Length field value in the COMMAND UPIU for the various cases.
  • Table 12.18 defines the expected data transfer length field values ​​in COMMAND UPIU for various cases.
    insert image description here
  • The device returns the result or data requested in the RPMB message. The RPMB message is delivered by sending one or more DATA IN UPIU in the data phase. A single DATA IN UPIU may deliver one or more RPMB Messages.
  • The device returns the results or data requested in the RPMB message. RPMB messages are delivered by sending one or more DATA IN UPIUs during the data phase. A single DATA IN UPIU can carry one or more RPMB messages.
  • The data size in DATA IN UPIU shall not exceed the value indicated by bMaxDataInSize attribute.
  • The size of the data in DATA IN UPIU shall not exceed the value indicated by the bMaxDataInSize attribute.
  • To complete the SECURITY PROTOCOL IN, the device sends a RESPONSE UPIU with the status.
  • To complete the SECURITY PROTOCOL IN, the device sends a RESPONSE UPIU with status.
  • Figure 12.3 depicts a response type message delivery. An application client requests a RPMB Region to transfer the RPMB Message in the Data In Buffer specifying the RPMB Region ID in SECURITY PROTOCOL SPECIFIC field of the CDB.
  • Figure 12.3 depicts response type messaging. The application client requests the RPMB message in the data in the RPMB region transfer buffer, specifying the RPMB region ID in the security protocol-specific field of the CDB.
    insert image description here
    Same as the previous chapter, the command format is the same, but the OPERATION CODE is A2h
#define SEC_PROTOCOL_CMD_SIZE           (12)
#define SEC_PROTOCOL_UFS                (0xEC)
#define SECURITY_PROTOCOL_IN  0xa2
#define SECURITY_PROTOCOL_OUT 0xb5

unsigned char sec_out_cmd[SEC_PROTOCOL_CMD_SIZE] = {
    
     
                        SECURITY_PROTOCOL_OUT, SEC_PROTOCOL_UFS,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

unsigned char sec_in_cmd[SEC_PROTOCOL_CMD_SIZE] = {
    
    
                        SECURITY_PROTOCOL_IN, SEC_PROTOCOL_UFS,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0};


/*
 * CDB format of SECURITY PROTOCOL IN/OUT commands
 * (JEDEC Standard No. 220D, Page 264)
 */
struct sec_proto_cdb {
    
    
    /*  
     * OPERATION CODE = A2h for SECURITY PROTOCOL IN command,
     * OPERATION CODE = B5h for SECURITY PROTOCOL OUT command.
     */
    uint8_t opcode;
    /* SECURITY PROTOCOL = ECh (JEDEC Universal Flash Storage) */
    uint8_t sec_proto;
    /*  
     * The SECURITY PROTOCOL SPECIFIC field specifies the RPMB Protocol ID.
     * CDB Byte 2 = 00h and CDB Byte 3 = 01h for RPMB Region 0.
     */
    uint8_t cdb_byte_2;
    uint8_t cdb_byte_3;
    /*  
     * Byte 4 and 5 are reserved.
     */
    uint8_t cdb_byte_4;
    uint8_t cdb_byte_5;
    /* ALLOCATION/TRANSFER LENGTH in big-endian */                                                                                                                                                                 
    uint32_t length;
    /* Byte 9 is reserved. */
    uint8_t cdb_byte_10;
    /* CONTROL = 00h. */
    uint8_t ctrl;
} __packed;

3 Authentication Key Programming

3.1 Authentication Key Programming

  • The Authentication Key programming is initiated by a SECURITY PROTOCOL OUT command
  • Authentication key programming is initiated by the SECURITY PROTOCOL OUT command
    • An initiator sends the SECURITY PROTOCOL OUT command with SECURITY PROTOCOL field set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field. The RPMB data frame includes the Request Message Type = 0001h and the Authentication Key.
    • The initiator sends the SECURITY PROTOCOL OUT command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field. RPMB data frames include Request Message Type = 0001h and Authentication Key.
    • The device returns GOOD status in status response when Authentication Key programming is completed.
    • When the verification key programming is complete, the device returns a GOOD status in the status response.
  • The Authentication Key programming verification process starts by issuing a SECURITY PROTOCOL OUT command
  • The authentication key programming verification process is started by issuing the SECURITY PROTOCOL OUT command
    • An initiator sends a SECURITY PROTOCOL OUT command with SECURITY PROTOCOL field set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field. The RPMB data frame contains the Request Message Type = 0005h (Result read request). Note that any request other than the Result read request from any initiator will overwrite the Result register of the RPMB Region.
    • The initiator sends the SECURITY PROTOCOL OUT command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field. RPMB data frames contain Request Message Type = 0005h (Result Read Request). Note that any request other than a result read request from any initiator will overwrite the result registers in the RPMB area.
    • The device returns GOOD status in status response when the operation result is ready for retrieval.
    • The device returns a GOOD status in a status response when the result of the operation is ready to be retrieved.
  • An initiator retrieves the operation result by issuing a SECURITY PROTOCOL IN command.
  • The initiator retrieves the result of the operation by issuing the SECURITY PROTOCOL IN command.
    • The SECURITY PROTOCOL field is set to ECh and the SECURITY PROTOCOL SPECIFIC field indicates the RPMB region.
    • The security protocol field is set to ECh and the security protocol specific field indicates the RPMB area.
    • Device returns the RPMB data frame containing the Response Message Type = 0100h and the Result code.
    • The device returns a RPMB Data Frame with Response Message Type = 0100h and Result Code.
    • If programming of Authentication Key failed then returned result is “Write failure” (0005h). If some other error occured during Authentication Key programming then returned result is “General failure” (0001h).
    • If the verification key programming fails, the return result is "Write Failed" (0005h). If some other error occurs during the verification key programming, the returned result is "general failure" (0001h).
      Access to RPMB data area is not possible before the Authentication Key is programmed in the corresponding RPMB region. The state of the device can be checked by trying to write/read data to/from the RPMB data area: if the Authentication Key is not programmed then the Result field in the response message will be set to “Authentication Key not yet programmed” (0007h). The
      RPMB data area cannot be accessed until the authentication key is programmed into the corresponding RPMB area. The status of the device can be checked by attempting to write data to or read data from the RPMB data area: if the authentication key is not programmed, the result field in the response message will be set to "Authentication key not yet programmed" (0007h).
      insert image description here

3.2 Message example

3.2.1 Authentication Key Programming Request

The data of the message corresponds to the data starting from 196Byte
insert image description here

 d0  81  c5  44  b1  9d  6b  e6  c5  37  cb  17  c4  00  f8  f1  74  25  e4  ab  98  6d  1f  1d  db  b1  c0  69  1f  68  94  b5 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  01 

3.2.2 Result Read Request

The data of the message corresponds to the data starting from 196Byte
insert image description here

 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  05 

3.2.3 Result Read Response

The data of the message corresponds to the data starting from 196Byte
insert image description here

4 Read Counter Value

4.1 Read Counter Value

  • The Read Counter Value sequence is initiated by a SECURITY PROTOCOL OUT command.
  • The read counter value sequence is initiated by the safety protocol output command.
    • An initiator sends the SECURITY PROTOCOL OUT command with SECURITY PROTOCOL field set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field. The RPMB data frame includes the Request Message Type = 0002h and the Nonce.
    • The initiator sends the SECURITY PROTOCOL OUT command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field. RPMB data frame includes Request Message Type = 0002h and Nonce.
  • When a GOOD status in the status response is received, the write counter value is retrieved sending a SECURITY PROTOCOL IN command.
  • When a GOOD status is received in the status response, the write counter value is retrieved by sending the SECURITY PROTOCOL IN command.
    • An initiator sends the SECURITY PROTOCOL IN command with the SECURITY PROTOCOL field is set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field.
    • The initiator sends the SECURITY PROTOCOL IN command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field.
    • The device returns a RPMB data frame with Response Message Type = 0200h, a copy of the Nonce received in the request, the Write Counter value, the MAC and the Result.
    • The device returns a RPMB Data Frame with Response Message Type = 0200h, a copy of the Nonce received in the request, write counter value, MAC and result.
      If reading of the counter value fails then returned result is “Read failure” (0006h/0086h)
      .
      If some other error occurs then Result is “General failure”
      (0001h/0081h). If counter has expired also bit 7 is set to 1 in returned results
      .

      insert image description here

4.2 Example of Read Counter Value message

4.2.1 Write Counter Read Request

insert image description here

 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 ee  8f  e0  77  be  32  c7  69  24  c0  32  f2  da  a7  66  2c  00  00  00  00  00  00  00  00  00  00  00  02 

4.2.2 Write Counter Read Response

insert image description here

 d8  4a  3e  0a  7e  1e  a9  e7  cb  10  4b  03  b4  df  5d  79  80  e8  eb  c3  1f  a6  d0  e5  ec  7a  30  80  ad  f5  63  5d 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 ee  8f  e0  77  be  32  c7  69  24  c0  32  f2  da  a7  66  2c  00  00  00  b7  00  00  00  00  00  00  02  00 

5 Authenticated Data Write

5.1 Authenticated Data Write

  • The Authenticated Data Write sequence is initiated by a SECURITY PROTOCOL OUT command.
  • The authenticated data write sequence is initiated by the SECURITY PROTOCOL OUT command.
    • An initiator sends the SECURITY PROTOCOL OUT command with SECURITY PROTOCOL field set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field. The RPMB message is composed of one or more RPMB message data frames, each of which includes: Request Message Type = 0003h, Block Count, Address, Write Counter, Data and MAC.
    • The initiator sends the SECURITY PROTOCOL OUT command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field. RPMB message consists of one or more RPMB message data frames, and each RPMB message data frame includes: Request Message Type = 0003h, Block Count, Address, Write Counter, Data and MAC.
    • When the device receives the RPMB message, it first checks whether the write counter has expired. If the write counter is expired then the device sets the Result to “Write failure, write counter expired” (0085h). No data is written to the RPMB data area.
    • When a device receives an RPMB message, it first checks to see if the write counter has expired. If the write counter expires, the device sets the result to "Write failed, write counter expired" (0085h). No data is written to the RPMB data area.
    • Next the address is checked. If the Address value is equal to or greater than the size of target RPMB region which is defined as bRPMBRegion0Size – bRPMBRegion3Size parameter value in the RPMB Unit Descriptor, then the Result is set to “Address failure” (0004h). No data is written to the RPMB data area.
    • Next check the address. If the address value is equal to or greater than the size of the target RPMB region defined in the RPMB Cell Descriptor as the bRPMBRegion0Size – bRPMBRegion3Size parameter value, the result is set to "Address Failed" (0004h). No data is written to the RPMB data area.
    • If the Address value plus the Block Count value is greater than the size of target RPMB region which is defined as bRPMBRegion0Size – bRPMBRegion3Size parameter value, then the Result is set to “Address failure” (0004h). No data is written to the RPMB data area.
    • If the Block Count indicates a value greater than bRPMB_ReadWriteSize, then the authenticated data write operation fails and the Result is set to “General failure” (0001h).
    • If the block count indication value is greater than bRPMB_ReadWriteSize, the authenticated data write operation fails and the result is set to "generic failure" (0001h).
    • If the write counter was not expired then the device calculates the MAC of request type, block count, write counter, address and data, and compares this with the MAC in the request. If the two MAC’s are different, then the device sets the Result to ”Authentication failure” (0002h). No data is written to the RPMB data area.
    • If the write counter has not expired, the device calculates the MAC of the request type, block count, write counter, address, and data and compares it to the MAC in the request. If the two MACs are different, the device sets the result to " authentication failed" (0002h) . No data is written to the RPMB data area.
    • If the MAC in the request and the calculated MAC are equal then the device compares the write counter in the request with the write counter stored in the device. If the two counters are different then the device sets the Result to “Counter failure” (0003h). No data is written to the RPMB data area.
    • If the MAC in the request and the calculated MAC are equal, the device compares the write counter in the request with the write counter stored in the device . If the two counters differ, the device sets the result to "Counter Failed" (0003h). No data is written to the RPMB data area.
    • If the MAC and write counter comparisons are successful then the write request is considered to be authenticated. The data is written to the address indicated in the request.
    • If the comparison of the MAC and the write counter succeeds, the write request is considered authenticated. Data is written to the address specified in the request.
    • The write counter is incremented by one if the write operation is successfully executed.
    • If the write operation is successfully performed, the write counter is incremented by one.
    • If write fails then returned result is “Write failure” (0005h).
    • If the write fails, the return result is "write failed" (0005h).
    • If some other error occurs during the write procedure then returned result is “General failure” (0001h).
    • If other errors occur during writing, the return result is "General failure" (0001h).
    • In an authenticated data write request with Block Count greater than one
    • In authenticated data write requests with a block count greater than 1
      • the MAC is included only in the last RPMB message data frame. The MAC field is zero in all previous data frames. The device behavior is undefined if a MAC field is non-zero in any but the last RPMB message data frame.
      • The MAC is only included in the last RPMB message data frame . The MAC field in all previous data frames is zero . Device behavior is undefined if the MAC field is non-zero in any frame other than the last RPMB message data frame.
      • In each data frame, the write counter indicates the current counter value, the address is the start address of the full access (not address of the individual logical block) and the block count is the total count of the blocks (not the block numbers).
      • In each data frame, the write counter indicates the current counter value, the address is the starting address of the full access (not the address of a single logical block), and the block count is the total number of blocks (not the block number).
    • When the authenticated data write operation is completed, the device may return GOOD status in response to the SECURITY PROTOCOL OUT command regardless of whether the Authenticated data write was successful or not.
    • When the authentication data writing operation is completed, the device can return GOOD status in response to the SECURITY PROTOCOL OUT command regardless of whether the authentication data writing is successful or not.
  • The authenticated data write verification process starts by issuing a SECURITY PROTOCOL OUT command.
  • The authenticated data write verification process is started by issuing the SECURITY PROTOCOL OUT command.
    • An initiator sends a SECURITY PROTOCOL OUT command with SECURITY PROTOCOL field set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field. The RPMB data frame contains the Request Message Type = 0005h (Result read request). Note that any request other than the Result read request from any initiator will overwrite the Result register of the RPMB Region.
    • The initiator sends the SECURITY PROTOCOL OUT command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field. The RPMB data frame contains Request Message Type = 0005h (Result Read Request). Note that any request other than a result read request from any initiator will overwrite the result registers in the RPMB area.
    • The device returns GOOD status when the operation result is ready for retrieval.
    • The device returns a GOOD status when the results of the operation are available for retrieval.
  • An initiator retrieves the operation result by issuing a SECURITY PROTOCOL IN command.
  • The initiator retrieves the result of the operation by issuing the SECURITY PROTOCOL IN command.
    • The SECURITY PROTOCOL field is set to ECh and the SECURITY PROTOCOL SPECIFIC field indicates the RPMB region.
    • The security protocol field is set to ECh and the security protocol specific field indicates the RPMB area.
  • Device returns the RPMB data frame containing the Response Message Type = 0300h, the counter value (incremented if the write operation is successfully executed), the address received in the Authenticated data write request, the MAC and result of the authenticated data write operation.
  • Device returns RPMB Data Frame with Response Message Type = 0300h, counter value (incremented if write was successful), address received in Authenticated Data Write Request, MAC of Authenticated Data Write and the result.
    insert image description here

5.2 Example of Authenticated Data Write message

5.2.1 Authenticated Data Write Request

insert image description here

 f7  99  d2  87  e9  b6  ba  6e  b7  10  3a  24  05  a6  80  22  97  72  76  4c  d3  bf  f0  5b  b9  63  cf  03  fb  f2  c3  ad 
 86  da  70  1a  2c  a0  a6  2a  b1  34  1a  d9  9e  58  4e  53  09  22  1c  57  38  c4  62  60  2e  40  22  88  7a  76  73  e1 
 62  64  30  66  33  35  63  37  63  31  65  31  30  64  37  34  35  64  32  39  66  39  37  65  61  63  35  63  33  39  64  63 
 64  64  65  38  64  63  63  63  33  63  39  33  66  62  36  32  30  61  39  61  64  64  34  65  63  34  37  36  32  66  34  63 
 38  33  31  61  33  32  36  33  35  39  64  35  34  30  30  63  66  32  34  34  31  32  36  32  38  33  61  32  32  61  66  30 
 63  66  39  66  39  61  31  37  30  62  34  30  63  63  66  63  33  31  36  64  39  66  66  33  35  65  32  33  36  65  61  66 
 61  66  37  31  30  61  61  36  38  61  66  36  39  65  30  62  31  61  62  33  34  63  33  62  38  65  32  35  61  62  63  37 
 66  62  39  37  65  39  64  31  30  38  30  30  33  33  31  61  38  33  35  30  30  36  34  39  61  64  38  61  36  33  65  35 
 37  62  61  61  66  31  36  31  62  35  39  35  62  30  63  35  31  33  32  61  31  64  65  61  64  32  32  30  64  38  61  39 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  b7  00  00  00  01  00  00  00  03 

5.2.2 Result Read Request

insert image description here

 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  05 

5.2.3 Result Read Response

insert image description here

 46  11  20  35  25  c6  2a  07  c8  e4  56  1f  03  c6  93  f3  90  df  4d  19  cd  52  a6  3b  25  cc  2b  32  d8  43  ac  b3 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  b8  00  00  00  00  00  00  03  00 

6 Authenticated Data Read

6.1 Authenticated Data Read

  • The Authenticated Data Read sequence is initiated by a SECURITY PROTOCOL OUT command.
  • The authenticated data read sequence is initiated by the SECURITY PROTOCOL OUT command.
    • An initiator sends the SECURITY PROTOCOL OUT command with SECURITY PROTOCOL field set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field. The RPMB data frame includes the Request Message Type = 0004h, the nonce, the data address, and the block count.
    • The initiator sends the SECURITY PROTOCOL OUT command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field. RPMB data frame includes request message type = 0004h, nonce, data address and block count.
    • When the device receives this request it first checks the address. If the Address value is equal to or greater than the size of target RPMB region which is defined as bRPMBRegion0Size – bRPMBRegion3Size parameter value in the RPMB Unit Descriptor, then Result is set to “Address failure” (0004h/0084h). The data read is not valid.
    • When the device receives this request, it first checks the address. If the address value is equal to or greater than the size of the target RPMB region defined in the RPMB cell descriptor as the bRPMBRegion0Size – bRPMBRegion3Size parameter value, the result is set to "Address Fail" (0004h/0084h). The data read is invalid.
    • If the Address value plus the Block Count value is greater than the size of target RPMB region which is defined as bRPMBRegion0Size – bRPMBRegion3Size parameter value, then the Result is set to “Address failure” (0004h/0084h). No data is read from the RPMB data area.
    • If the address value plus the block count value is greater than the size of the target RPMB region (defined as the bRPMBRegion0Size – bRPMBRegion3Size parameter value), the result is set to "Address Failed" (0004h/0084h). No data is read from the RPMB data area.
    • After successful data fetch the MAC is calculated from response type, nonce, address, data and result. If the MAC calculation fails then returned result is “Authentication failure” (0002h/0082h).
    • After successfully fetching the data, the MAC will be calculated based on the response type, nonce, address, data and result. If the MAC calculation fails, the return result is "authentication failed" (0002h/0082h).
  • If the SECURITY PROTOCOL OUT command completes with GOOD status, data can be retrieved sending a SECURITY PROTOCOL IN command.
  • If the SECURITY PROTOCOL OUT command completes with a GOOD status, the data can be retrieved by sending the SECURITY PROTOCOL IN command.
    • An initiator sends the SECURITY PROTOCOL IN command with SECURITY PROTOCOL field set to ECh and indicating the RPMB region in the SECURITY PROTOCOL SPECIFIC field.
    • The initiator sends the SECURITY PROTOCOL IN command with the SECURITY PROTOCOL field set to ECh and indicates the RPMB area in the SECURITY PROTOCOL SPECIFIC field.
    • The device returns a RPMB message with Response Message Type = 0400h, the block count, a copy of the nonce received in the request, the address received in the Authenticated data read request, the data, the MAC and the result.
    • The device returns an RPMB message with Response Message Type = 0400h, block count, copy of the nonce received in the request, address, data, MAC and result received in the authenticated data read request.
    • In an authenticated data read response with Block Count greater than one,
    • In an authenticated data read response with a block count greater than 1,
      • the MAC is included only in the last RPMB message data frame. The MAC field is zero in all previous data frames.
      • The MAC is only included in the last RPMB message data frame. The MAC field in all previous data frames is zero.
      • In each data frame, the Nonce contains a copy of the received nonce, the address is the start address of the full access (not address of the individual logical block) and the block count is the total count of the blocks (not the sequence number of blocks).
      • In each data frame, the Nonce contains a copy of the received Nonce, the address is the starting address of the full access (not the address of a single logical block), and the block count is the total count of the block (not the sequence number of the block).
  • When the authenticated data read operation is completed, the device may return GOOD status in response to the SECURITY PROTOCOL IN command regardless of whether the Authenticated data read was successful or not.
  • When the authentication data read operation is completed, the device may return a GOOD status in response to the SECURITY PROTOCOL IN command regardless of whether the authentication data read was successful or not.
  • If data fetch from addressed location inside device fails then returned result is “Read failure” (0006h/0086h). If some other error occurs during the read procedure then returned result is “General failure” (0001h/0081h).
  • If data acquisition from the addressed location within the device fails, the return result is "read failed" (0006h/0086h). If other errors occur during reading, the return result is "General failure" (0001h/0081h).
    insert image description here

6.2 Example of Authenticated Data Read message

6.2.1 Authenticated Data Read Request

insert image description here

 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
 14  77  4e  6b  2c  a9  06  88  cf  71  bf  e0  7c  e4  c3  2d  00  00  00  00  00  00  00  01  00  00  00  04 

6.2.2 Authenticated Data Read Response

insert image description here

 c8  51  39  bd  63  54  8c  7c  e1  d5  cf  bf  7a  3d  1f  82  32  61  17  75  71  c2  f0  5a  fb  61  d7  90  b0  c3  76  fe 
 86  da  70  1a  2c  a0  a6  2a  b1  34  1a  d9  9e  58  4e  53  09  22  1c  57  38  c4  62  60  2e  40  22  88  7a  76  73  e1 
 62  64  30  66  33  35  63  37  63  31  65  31  30  64  37  34  35  64  32  39  66  39  37  65  61  63  35  63  33  39  64  63 
 64  64  65  38  64  63  63  63  33  63  39  33  66  62  36  32  30  61  39  61  64  64  34  65  63  34  37  36  32  66  34  63 
 38  33  31  61  33  32  36  33  35  39  64  35  34  30  30  63  66  32  34  34  31  32  36  32  38  33  61  32  32  61  66  30 
 63  66  39  66  39  61  31  37  30  62  34  30  63  63  66  63  33  31  36  64  39  66  66  33  35  65  32  33  36  65  61  66 
 61  66  37  31  30  61  61  36  38  61  66  36  39  65  30  62  31  61  62  33  34  63  33  62  38  65  32  35  61  62  63  37 
 66  62  39  37  65  39  64  31  30  38  30  30  33  33  31  61  38  33  35  30  30  36  34  39  61  64  38  61  36  33  65  35 
 37  62  61  61  66  31  36  31  62  35  39  35  62  30  63  35  31  33  32  61  31  64  65  61  64  32  32  30  64  38  61  39 
 14  77  4e  6b  2c  a9  06  88  cf  71  bf  e0  7c  e4  c3  2d  00  00  00  00  00  00  00  01  00  00  04  00 

Guess you like

Origin blog.csdn.net/u014100559/article/details/131691585