+++ /dev/null
-/** @file\r
- Application for Diffie-Hellman Primitives Validation.\r
-\r
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "Cryptest.h"\r
-\r
-/**\r
- Validate UEFI-OpenSSL DH Interfaces.\r
-\r
- @retval EFI_SUCCESS Validation succeeded.\r
- @retval EFI_ABORTED Validation failed.\r
-\r
-**/\r
-EFI_STATUS\r
-ValidateCryptDh (\r
- VOID\r
- )\r
-{\r
- VOID *Dh1;\r
- VOID *Dh2;\r
- UINT8 Prime[64];\r
- UINT8 PublicKey1[64];\r
- UINTN PublicKey1Length;\r
- UINT8 PublicKey2[64];\r
- UINTN PublicKey2Length;\r
- UINT8 Key1[64];\r
- UINTN Key1Length;\r
- UINT8 Key2[64];\r
- UINTN Key2Length;\r
- BOOLEAN Status;\r
-\r
- Print (L"\nUEFI-OpenSSL DH Engine Testing:\n");\r
-\r
- //\r
- // Initialize Key Length\r
- //\r
- PublicKey1Length = sizeof (PublicKey1);\r
- PublicKey2Length = sizeof (PublicKey2);\r
- Key1Length = sizeof (Key1);\r
- Key2Length = sizeof (Key2);\r
-\r
- //\r
- // Generate & Initialize DH Context\r
- //\r
- Print (L"- Context1 ... ");\r
- Dh1 = DhNew ();\r
- if (Dh1 == NULL) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Context2 ... ");\r
- Dh2 = DhNew ();\r
- if (Dh2 == NULL) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Parameter1 ... ");\r
- Status = DhGenerateParameter (Dh1, 2, 64, Prime);\r
- if (!Status) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Parameter2 ... ");\r
- Status = DhSetParameter (Dh2, 2, 64, Prime);\r
- if (!Status) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Generate key1 ... ");\r
- Status = DhGenerateKey (Dh1, PublicKey1, &PublicKey1Length);\r
- if (!Status) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Generate key2 ... ");\r
- Status = DhGenerateKey (Dh2, PublicKey2, &PublicKey2Length);\r
- if (!Status) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Compute key1 ... ");\r
- Status = DhComputeKey (Dh1, PublicKey2, PublicKey2Length, Key1, &Key1Length);\r
- if (!Status) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Compute key2 ... ");\r
- Status = DhComputeKey (Dh2, PublicKey1, PublicKey1Length, Key2, &Key2Length);\r
- if (!Status) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"Compare Keys ... ");\r
- if (Key1Length != Key2Length) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- if (CompareMem (Key1, Key2, Key1Length) != 0) {\r
- Print (L"[Fail]");\r
- return EFI_ABORTED;\r
- }\r
-\r
- Print (L"[Pass]\n");\r
-\r
- return EFI_SUCCESS;\r
-}
\ No newline at end of file