]>
Commit | Line | Data |
---|---|---|
2ac68e8b | 1 | /** @file\r |
a8c44645 | 2 | Application for Diffie-Hellman Primitives Validation.\r |
3 | \r | |
2ac68e8b | 4 | Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r |
a8c44645 | 5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT 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 | |
24 | EFI_STATUS\r | |
25 | ValidateCryptDh (\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 | |
2ac68e8b QL |
44 | //\r |
45 | // Initialize Key Length\r | |
46 | //\r | |
47 | PublicKey1Length = sizeof (PublicKey1);\r | |
48 | PublicKey2Length = sizeof (PublicKey2);\r | |
49 | Key1Length = sizeof (Key1);\r | |
50 | Key2Length = sizeof (Key2);\r | |
51 | \r | |
a8c44645 | 52 | //\r |
53 | // Generate & Initialize DH Context\r | |
54 | //\r | |
55 | Print (L"- Context1 ... ");\r | |
56 | Dh1 = DhNew ();\r | |
57 | if (Dh1 == NULL) {\r | |
58 | Print (L"[Fail]");\r | |
59 | return EFI_ABORTED;\r | |
60 | }\r | |
61 | \r | |
62 | Print (L"Context2 ... ");\r | |
63 | Dh2 = DhNew ();\r | |
64 | if (Dh2 == NULL) {\r | |
65 | Print (L"[Fail]");\r | |
66 | return EFI_ABORTED;\r | |
67 | }\r | |
68 | \r | |
69 | Print (L"Parameter1 ... ");\r | |
70 | Status = DhGenerateParameter (Dh1, 2, 64, Prime);\r | |
71 | if (!Status) {\r | |
72 | Print (L"[Fail]");\r | |
73 | return EFI_ABORTED;\r | |
74 | }\r | |
75 | \r | |
76 | Print (L"Parameter2 ... ");\r | |
77 | Status = DhSetParameter (Dh2, 2, 64, Prime);\r | |
78 | if (!Status) {\r | |
79 | Print (L"[Fail]");\r | |
80 | return EFI_ABORTED;\r | |
81 | }\r | |
82 | \r | |
83 | Print (L"Generate key1 ... ");\r | |
84 | Status = DhGenerateKey (Dh1, PublicKey1, &PublicKey1Length);\r | |
85 | if (!Status) {\r | |
86 | Print (L"[Fail]");\r | |
87 | return EFI_ABORTED;\r | |
88 | }\r | |
89 | \r | |
90 | Print (L"Generate key2 ... ");\r | |
91 | Status = DhGenerateKey (Dh2, PublicKey2, &PublicKey2Length);\r | |
92 | if (!Status) {\r | |
93 | Print (L"[Fail]");\r | |
94 | return EFI_ABORTED;\r | |
95 | }\r | |
96 | \r | |
97 | Print (L"Compute key1 ... ");\r | |
98 | Status = DhComputeKey (Dh1, PublicKey2, PublicKey2Length, Key1, &Key1Length);\r | |
99 | if (!Status) {\r | |
100 | Print (L"[Fail]");\r | |
101 | return EFI_ABORTED;\r | |
102 | }\r | |
103 | \r | |
104 | Print (L"Compute key2 ... ");\r | |
105 | Status = DhComputeKey (Dh2, PublicKey1, PublicKey1Length, Key2, &Key2Length);\r | |
106 | if (!Status) {\r | |
107 | Print (L"[Fail]");\r | |
108 | return EFI_ABORTED;\r | |
109 | }\r | |
110 | \r | |
111 | Print (L"Compare Keys ... ");\r | |
112 | if (Key1Length != Key2Length) {\r | |
113 | Print (L"[Fail]");\r | |
114 | return EFI_ABORTED;\r | |
115 | }\r | |
116 | \r | |
117 | if (CompareMem (Key1, Key2, Key1Length) != 0) {\r | |
118 | Print (L"[Fail]");\r | |
119 | return EFI_ABORTED;\r | |
120 | }\r | |
121 | \r | |
122 | Print (L"[Pass]\n");\r | |
123 | \r | |
124 | return EFI_SUCCESS;\r | |
2ac68e8b | 125 | } |