20 TPMI_DH_OBJECT ObjectHandle;
46 IN TPMI_DH_OBJECT ObjectHandle,
55 UINT32 SendBufferSize;
56 UINT32 RecvBufferSize;
61 UINT16 QualifiedNameSize;
66 SendBuffer.Header.tag =
SwapBytes16 (TPM_ST_NO_SESSIONS);
67 SendBuffer.Header.commandCode =
SwapBytes32 (TPM_CC_ReadPublic);
69 SendBuffer.ObjectHandle =
SwapBytes32 (ObjectHandle);
71 SendBufferSize = (UINT32)
sizeof (SendBuffer);
72 SendBuffer.Header.paramSize =
SwapBytes32 (SendBufferSize);
77 RecvBufferSize =
sizeof (RecvBuffer);
78 Status =
Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
79 if (EFI_ERROR (Status)) {
84 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - RecvBufferSize Error - %x\n", RecvBufferSize));
85 return EFI_DEVICE_ERROR;
88 ResponseCode =
SwapBytes32 (RecvBuffer.Header.responseCode);
89 if (ResponseCode != TPM_RC_SUCCESS) {
90 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - responseCode - %x\n",
SwapBytes32 (RecvBuffer.Header.responseCode)));
93 switch (ResponseCode) {
99 return EFI_INVALID_PARAMETER;
101 return EFI_DEVICE_ERROR;
107 OutPublicSize =
SwapBytes16 (RecvBuffer.OutPublic.size);
109 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - OutPublicSize error %x\n", OutPublicSize));
110 return EFI_DEVICE_ERROR;
116 sizeof (UINT16) + OutPublicSize)
120 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - NameSize error %x\n", NameSize));
121 return EFI_DEVICE_ERROR;
127 sizeof (UINT16) + OutPublicSize +
128 sizeof (UINT16) + NameSize)
131 if (QualifiedNameSize >
sizeof (
TPMU_NAME)) {
132 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - QualifiedNameSize error %x\n", QualifiedNameSize));
133 return EFI_DEVICE_ERROR;
136 if (RecvBufferSize !=
sizeof (
TPM2_RESPONSE_HEADER) +
sizeof (UINT16) + OutPublicSize +
sizeof (UINT16) + NameSize +
sizeof (UINT16) + QualifiedNameSize) {
137 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - RecvBufferSize %x Error - OutPublicSize %x, NameSize %x, QualifiedNameSize %x\n", RecvBufferSize, OutPublicSize, NameSize, QualifiedNameSize));
138 return EFI_DEVICE_ERROR;
144 Buffer = (UINT8 *)&RecvBuffer.OutPublic;
145 CopyMem (OutPublic, &RecvBuffer.OutPublic, sizeof (UINT16) + OutPublicSize);
146 OutPublic->size = OutPublicSize;
147 OutPublic->publicArea.type =
SwapBytes16 (OutPublic->publicArea.type);
148 OutPublic->publicArea.nameAlg =
SwapBytes16 (OutPublic->publicArea.nameAlg);
150 Buffer = (UINT8 *)&RecvBuffer.OutPublic.publicArea.authPolicy;
152 Buffer +=
sizeof (UINT16);
153 if (OutPublic->publicArea.authPolicy.size > sizeof (
TPMU_HA)) {
154 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - authPolicy.size error %x\n", OutPublic->publicArea.authPolicy.size));
155 return EFI_DEVICE_ERROR;
158 CopyMem (OutPublic->publicArea.authPolicy.buffer, Buffer, OutPublic->publicArea.authPolicy.size);
159 Buffer += OutPublic->publicArea.authPolicy.size;
162 switch (OutPublic->publicArea.type) {
163 case TPM_ALG_KEYEDHASH:
165 Buffer +=
sizeof (UINT16);
166 switch (OutPublic->publicArea.parameters.keyedHashDetail.scheme.scheme) {
168 OutPublic->publicArea.parameters.keyedHashDetail.scheme.details.hmac.hashAlg =
SwapBytes16 (
ReadUnaligned16 ((UINT16 *)Buffer));
169 Buffer +=
sizeof (UINT16);
172 OutPublic->publicArea.parameters.keyedHashDetail.scheme.details.xor.hashAlg =
SwapBytes16 (
ReadUnaligned16 ((UINT16 *)Buffer));
173 Buffer +=
sizeof (UINT16);
175 Buffer +=
sizeof (UINT16);
178 return EFI_UNSUPPORTED;
182 case TPM_ALG_SYMCIPHER:
184 Buffer +=
sizeof (UINT16);
185 switch (OutPublic->publicArea.parameters.symDetail.algorithm) {
188 Buffer +=
sizeof (UINT16);
190 Buffer +=
sizeof (UINT16);
194 Buffer +=
sizeof (UINT16);
196 Buffer +=
sizeof (UINT16);
200 Buffer +=
sizeof (UINT16);
205 return EFI_UNSUPPORTED;
211 Buffer +=
sizeof (UINT16);
212 switch (OutPublic->publicArea.parameters.rsaDetail.symmetric.algorithm) {
215 Buffer +=
sizeof (UINT16);
217 Buffer +=
sizeof (UINT16);
221 Buffer +=
sizeof (UINT16);
223 Buffer +=
sizeof (UINT16);
228 return EFI_UNSUPPORTED;
232 Buffer +=
sizeof (UINT16);
233 switch (OutPublic->publicArea.parameters.rsaDetail.scheme.scheme) {
236 Buffer +=
sizeof (UINT16);
240 Buffer +=
sizeof (UINT16);
246 Buffer +=
sizeof (UINT16);
251 return EFI_UNSUPPORTED;
255 Buffer +=
sizeof (UINT16);
257 Buffer +=
sizeof (UINT32);
261 Buffer +=
sizeof (UINT16);
262 switch (OutPublic->publicArea.parameters.eccDetail.symmetric.algorithm) {
265 Buffer +=
sizeof (UINT16);
267 Buffer +=
sizeof (UINT16);
271 Buffer +=
sizeof (UINT16);
273 Buffer +=
sizeof (UINT16);
278 return EFI_UNSUPPORTED;
282 Buffer +=
sizeof (UINT16);
283 switch (OutPublic->publicArea.parameters.eccDetail.scheme.scheme) {
286 Buffer +=
sizeof (UINT16);
290 Buffer +=
sizeof (UINT16);
292 case TPM_ALG_ECSCHNORR:
293 OutPublic->publicArea.parameters.eccDetail.scheme.details.ecSchnorr.hashAlg =
SwapBytes16 (
ReadUnaligned16 ((UINT16 *)Buffer));
294 Buffer +=
sizeof (UINT16);
301 return EFI_UNSUPPORTED;
305 Buffer +=
sizeof (UINT16);
307 Buffer +=
sizeof (UINT16);
308 switch (OutPublic->publicArea.parameters.eccDetail.kdf.scheme) {
311 Buffer +=
sizeof (UINT16);
313 case TPM_ALG_KDF1_SP800_108:
314 OutPublic->publicArea.parameters.eccDetail.kdf.details.kdf1_sp800_108.hashAlg =
SwapBytes16 (
ReadUnaligned16 ((UINT16 *)Buffer));
315 Buffer +=
sizeof (UINT16);
317 case TPM_ALG_KDF1_SP800_56a:
318 OutPublic->publicArea.parameters.eccDetail.kdf.details.kdf1_SP800_56a.hashAlg =
SwapBytes16 (
ReadUnaligned16 ((UINT16 *)Buffer));
319 Buffer +=
sizeof (UINT16);
323 Buffer +=
sizeof (UINT16);
328 return EFI_UNSUPPORTED;
333 return EFI_UNSUPPORTED;
337 switch (OutPublic->publicArea.type) {
338 case TPM_ALG_KEYEDHASH:
340 Buffer +=
sizeof (UINT16);
341 if (OutPublic->publicArea.unique.keyedHash.size > sizeof (
TPMU_HA)) {
342 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - keyedHash.size error %x\n", OutPublic->publicArea.unique.keyedHash.size));
343 return EFI_DEVICE_ERROR;
346 CopyMem (OutPublic->publicArea.unique.keyedHash.buffer, Buffer, OutPublic->publicArea.unique.keyedHash.size);
347 Buffer += OutPublic->publicArea.unique.keyedHash.size;
349 case TPM_ALG_SYMCIPHER:
351 Buffer +=
sizeof (UINT16);
352 if (OutPublic->publicArea.unique.sym.size > sizeof (
TPMU_HA)) {
353 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - sym.size error %x\n", OutPublic->publicArea.unique.sym.size));
354 return EFI_DEVICE_ERROR;
357 CopyMem (OutPublic->publicArea.unique.sym.buffer, Buffer, OutPublic->publicArea.unique.sym.size);
358 Buffer += OutPublic->publicArea.unique.sym.size;
362 Buffer +=
sizeof (UINT16);
363 if (OutPublic->publicArea.unique.rsa.size > MAX_RSA_KEY_BYTES) {
364 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - rsa.size error %x\n", OutPublic->publicArea.unique.rsa.size));
365 return EFI_DEVICE_ERROR;
368 CopyMem (OutPublic->publicArea.unique.rsa.buffer, Buffer, OutPublic->publicArea.unique.rsa.size);
369 Buffer += OutPublic->publicArea.unique.rsa.size;
373 Buffer +=
sizeof (UINT16);
374 if (OutPublic->publicArea.unique.ecc.x.size > MAX_ECC_KEY_BYTES) {
375 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - ecc.x.size error %x\n", OutPublic->publicArea.unique.ecc.x.size));
376 return EFI_DEVICE_ERROR;
379 CopyMem (OutPublic->publicArea.unique.ecc.x.buffer, Buffer, OutPublic->publicArea.unique.ecc.x.size);
380 Buffer += OutPublic->publicArea.unique.ecc.x.size;
382 Buffer +=
sizeof (UINT16);
383 if (OutPublic->publicArea.unique.ecc.y.size > MAX_ECC_KEY_BYTES) {
384 DEBUG ((DEBUG_ERROR,
"Tpm2ReadPublic - ecc.y.size error %x\n", OutPublic->publicArea.unique.ecc.y.size));
385 return EFI_DEVICE_ERROR;
388 CopyMem (OutPublic->publicArea.unique.ecc.y.buffer, Buffer, OutPublic->publicArea.unique.ecc.y.size);
389 Buffer += OutPublic->publicArea.unique.ecc.y.size;
392 return EFI_UNSUPPORTED;
395 CopyMem (Name->name, (UINT8 *)&RecvBuffer + sizeof (
TPM2_RESPONSE_HEADER) +
sizeof (UINT16) + OutPublicSize +
sizeof (UINT16), NameSize);
396 Name->size = NameSize;
398 CopyMem (QualifiedName->name, (UINT8 *)&RecvBuffer + sizeof (
TPM2_RESPONSE_HEADER) +
sizeof (UINT16) + OutPublicSize +
sizeof (UINT16) + NameSize +
sizeof (UINT16), QualifiedNameSize);
399 QualifiedName->size = QualifiedNameSize;
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT16 EFIAPI ReadUnaligned16(IN CONST UINT16 *Buffer)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define DEBUG(Expression)
#define TPM_ALG_RSA
The RSA algorithm.
#define TPM_ALG_XOR
XOR using the rolling nonces.
#define TPM_ALG_MGF1
The XOR algorithm using MGF1 to create a string the size of the encrypted block.
#define TPM_ALG_HMAC
The RFC 2104 HMAC algorithm.
EFI_STATUS EFIAPI Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
EFI_STATUS EFIAPI Tpm2ReadPublic(IN TPMI_DH_OBJECT ObjectHandle, OUT TPM2B_PUBLIC *OutPublic, OUT TPM2B_NAME *Name, OUT TPM2B_NAME *QualifiedName)