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