2 Application for Diffie-Hellman Primitives Validation.
4 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "TestBaseCryptLib.h"
17 UNIT_TEST_CONTEXT Context
22 return UNIT_TEST_ERROR_TEST_FAILED
;
27 return UNIT_TEST_ERROR_TEST_FAILED
;
30 return UNIT_TEST_PASSED
;
36 UNIT_TEST_CONTEXT Context
52 TestVerifyDhGenerateKey (
53 UNIT_TEST_CONTEXT Context
58 UINTN PublicKey1Length
;
60 UINTN PublicKey2Length
;
68 // Initialize Key Length
70 PublicKey1Length
= sizeof (PublicKey1
);
71 PublicKey2Length
= sizeof (PublicKey2
);
72 Key1Length
= sizeof (Key1
);
73 Key2Length
= sizeof (Key2
);
75 Status
= DhGenerateParameter (mDh1
, 2, 64, Prime
);
76 UT_ASSERT_TRUE (Status
);
78 Status
= DhSetParameter (mDh2
, 2, 64, Prime
);
79 UT_ASSERT_TRUE (Status
);
81 Status
= DhGenerateKey (mDh1
, PublicKey1
, &PublicKey1Length
);
82 UT_ASSERT_TRUE (Status
);
84 Status
= DhGenerateKey (mDh2
, PublicKey2
, &PublicKey2Length
);
85 UT_ASSERT_TRUE (Status
);
87 Status
= DhComputeKey (mDh1
, PublicKey2
, PublicKey2Length
, Key1
, &Key1Length
);
88 UT_ASSERT_TRUE (Status
);
90 Status
= DhComputeKey (mDh2
, PublicKey1
, PublicKey1Length
, Key2
, &Key2Length
);
91 UT_ASSERT_TRUE (Status
);
93 UT_ASSERT_EQUAL (Key1Length
, Key2Length
);
95 UT_ASSERT_MEM_EQUAL (Key1
, Key2
, Key1Length
);
97 return UNIT_TEST_PASSED
;
100 TEST_DESC mDhTest
[] = {
102 // -----Description--------------------------------Class---------------------Function----------------Pre-----------------Post------------Context
104 { "TestVerifyDhGenerateKey()", "CryptoPkg.BaseCryptLib.Dh", TestVerifyDhGenerateKey
, TestVerifyDhPreReq
, TestVerifyDhCleanUp
, NULL
},
107 UINTN mDhTestNum
= ARRAY_SIZE (mDhTest
);