]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Application/Cryptest/DhVerify.c
Update CryptoPkg for new ciphers (HMAC, Block Cipher, etc) supports.
[mirror_edk2.git] / CryptoPkg / Application / Cryptest / DhVerify.c
CommitLineData
a8c44645 1/** @file \r
2 Application for Diffie-Hellman Primitives Validation.\r
3\r
4Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "Cryptest.h"\r
16\r
17/**\r
18 Validate UEFI-OpenSSL DH Interfaces.\r
19\r
20 @retval EFI_SUCCESS Validation succeeded.\r
21 @retval EFI_ABORTED Validation failed.\r
22\r
23**/\r
24EFI_STATUS\r
25ValidateCryptDh (\r
26 VOID\r
27 )\r
28{\r
29 VOID *Dh1;\r
30 VOID *Dh2;\r
31 UINT8 Prime[64];\r
32 UINT8 PublicKey1[64];\r
33 UINTN PublicKey1Length;\r
34 UINT8 PublicKey2[64];\r
35 UINTN PublicKey2Length;\r
36 UINT8 Key1[64];\r
37 UINTN Key1Length;\r
38 UINT8 Key2[64];\r
39 UINTN Key2Length;\r
40 BOOLEAN Status;\r
41\r
42 Print (L"\nUEFI-OpenSSL DH Engine Testing:\n");\r
43\r
44 //\r
45 // Generate & Initialize DH Context\r
46 //\r
47 Print (L"- Context1 ... ");\r
48 Dh1 = DhNew ();\r
49 if (Dh1 == NULL) {\r
50 Print (L"[Fail]");\r
51 return EFI_ABORTED;\r
52 }\r
53\r
54 Print (L"Context2 ... ");\r
55 Dh2 = DhNew ();\r
56 if (Dh2 == NULL) {\r
57 Print (L"[Fail]");\r
58 return EFI_ABORTED;\r
59 }\r
60\r
61 Print (L"Parameter1 ... ");\r
62 Status = DhGenerateParameter (Dh1, 2, 64, Prime);\r
63 if (!Status) {\r
64 Print (L"[Fail]");\r
65 return EFI_ABORTED;\r
66 }\r
67\r
68 Print (L"Parameter2 ... ");\r
69 Status = DhSetParameter (Dh2, 2, 64, Prime);\r
70 if (!Status) {\r
71 Print (L"[Fail]");\r
72 return EFI_ABORTED;\r
73 }\r
74\r
75 Print (L"Generate key1 ... ");\r
76 Status = DhGenerateKey (Dh1, PublicKey1, &PublicKey1Length);\r
77 if (!Status) {\r
78 Print (L"[Fail]");\r
79 return EFI_ABORTED;\r
80 }\r
81\r
82 Print (L"Generate key2 ... ");\r
83 Status = DhGenerateKey (Dh2, PublicKey2, &PublicKey2Length);\r
84 if (!Status) {\r
85 Print (L"[Fail]");\r
86 return EFI_ABORTED;\r
87 }\r
88\r
89 Print (L"Compute key1 ... ");\r
90 Status = DhComputeKey (Dh1, PublicKey2, PublicKey2Length, Key1, &Key1Length);\r
91 if (!Status) {\r
92 Print (L"[Fail]");\r
93 return EFI_ABORTED;\r
94 }\r
95\r
96 Print (L"Compute key2 ... ");\r
97 Status = DhComputeKey (Dh2, PublicKey1, PublicKey1Length, Key2, &Key2Length);\r
98 if (!Status) {\r
99 Print (L"[Fail]");\r
100 return EFI_ABORTED;\r
101 }\r
102\r
103 Print (L"Compare Keys ... ");\r
104 if (Key1Length != Key2Length) {\r
105 Print (L"[Fail]");\r
106 return EFI_ABORTED;\r
107 }\r
108\r
109 if (CompareMem (Key1, Key2, Key1Length) != 0) {\r
110 Print (L"[Fail]");\r
111 return EFI_ABORTED;\r
112 }\r
113\r
114 Print (L"[Pass]\n");\r
115\r
116 return EFI_SUCCESS;\r
117}\r