14#define MAX_TEST_DATA_SIZE 512
15#define BYTES_OF_OPERATION_A 60
16#define BITS_OF_OPERATION_A 480
19 0x00, 0x00, 0x00, 0x00, 0x93, 0x61, 0x7a, 0xba, 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
20 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
21 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
22 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e, 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
26 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad,
27 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
28 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
29 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23, 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7
33 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed
37 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63
41 0x48, 0xbe, 0xcb, 0xd5, 0x36, 0x2e, 0x93, 0x0b, 0x51, 0x45, 0x9c, 0x7d, 0xe7, 0xfe, 0x47, 0xaa,
42 0xc5, 0xd3, 0x4b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, 0xA5, 0xB9, 0x05, 0x7F,
74 0xC1, 0x82, 0xEC, 0x23, 0x44, 0x23, 0xC8, 0xA2, 0x42, 0xB3, 0x43, 0xB8, 0x7C, 0xD6, 0xB1, 0xCF
79 0x3a, 0xeb, 0xc5, 0x98, 0x9c, 0x22, 0xd6, 0x76, 0x7d, 0x1c, 0xc6, 0xd6, 0xbb, 0x1b, 0xed, 0xfd,
80 0x0f, 0x34, 0xbf, 0xe0, 0x2b, 0x4a, 0x26, 0xc3, 0xc0, 0xd9, 0x57, 0xc7, 0x11, 0xc0, 0xd6, 0x35
85 0x39, 0xf8, 0x74, 0xa0, 0xe8, 0x02, 0x8b, 0xf2, 0x22, 0x62, 0x82, 0x4c, 0xe0, 0xed, 0x63, 0x48,
86 0xb9, 0xa2, 0xaa, 0xbc, 0xba, 0xb1, 0xd3, 0x6a, 0x02, 0xfd, 0xf3, 0x0e, 0x3a, 0x19, 0x39, 0x37
91 0x93, 0x61, 0x7a, 0xba, 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
92 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, 0x0a, 0x9e, 0xee, 0xe6,0x4b, 0x55, 0xd3, 0x9a,
93 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, 0x36, 0xba, 0x3c, 0x23,0xa3, 0xfe, 0xeb, 0xbd
115 CONST VOID *Expected,
134 UINTN BnTestBufferSize;
135 UINT8 BnTestBuffer[MAX_TEST_DATA_SIZE];
138 if (BnTestBufferSize == BufferSize) {
139 if (
CompareMem (Buffer, BnTestBuffer, BnTestBufferSize) == 0) {
161 if ( (BnContext->BnCTX ==
NULL)
162 || (BnContext->BnA ==
NULL)
163 || (BnContext->BnB ==
NULL)
164 || (BnContext->BnC ==
NULL)
165 || (BnContext->BnD ==
NULL)
168 return UNIT_TEST_ERROR_TEST_FAILED;
171 return UNIT_TEST_PASSED;
203 BnContext->BnA =
BigNumFromBin (BnOperationA,
sizeof (BnOperationA));
204 BnContext->BnB =
BigNumFromBin (BnOperationB,
sizeof (BnOperationB));
206 BigNumAdd (BnContext->BnA, BnContext->BnB, BnContext->BnC);
207 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultSum, sizeof (BnResultSum)));
209 BigNumSub (BnContext->BnC, BnContext->BnA, BnContext->BnD);
212 BnContext->BnD =
BigNumFromBin (BnOperationMod,
sizeof (BnOperationMod));
213 BigNumAddMod (BnContext->BnA, BnContext->BnB, BnContext->BnD, BnContext->BnC);
214 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultSumMod, sizeof (BnResultSumMod)));
216 BigNumMulMod (BnContext->BnA, BnContext->BnB, BnContext->BnD, BnContext->BnC);
217 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultMulMod, sizeof (BnResultMulMod)));
219 BigNumDiv (BnContext->BnA, BnContext->BnD, BnContext->BnC);
220 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultDiv, sizeof (BnResultDiv)));
222 BigNumMod (BnContext->BnA, BnContext->BnD, BnContext->BnC);
223 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultMod, sizeof (BnResultMod)));
226 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultInverseMod, sizeof (BnResultInverseMod)));
228 BnContext->BnB =
BigNumFromBin (BnOperationExp,
sizeof (BnOperationExp));
229 BigNumExpMod (BnContext->BnA, BnContext->BnB, BnContext->BnD, BnContext->BnC);
230 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultExpMod, sizeof (BnResultExpMod)));
233 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultRShift, sizeof (BnResultRShift)));
236 UT_ASSERT_TRUE (EqualBn2Bin (BnContext->BnC, BnResultUIntSet, sizeof (BnResultUIntSet)));
251 return UNIT_TEST_ERROR_TEST_FAILED;
256 return UNIT_TEST_PASSED;
263 {
"TestVerifyBn()",
"CryptoPkg.BaseCryptLib.BigNumber", TestVerifyBn, TestVerifyBnPreReq, TestVerifyBnCleanUp, &mBnContext },
BOOLEAN EFIAPI BigNumExpMod(IN CONST VOID *BnA, IN CONST VOID *BnP, IN CONST VOID *BnM, OUT VOID *BnRes)
BOOLEAN EFIAPI BigNumMulMod(IN CONST VOID *BnA, IN CONST VOID *BnB, IN CONST VOID *BnM, OUT VOID *BnRes)
BOOLEAN EFIAPI BigNumInverseMod(IN CONST VOID *BnA, IN CONST VOID *BnM, OUT VOID *BnRes)
VOID *EFIAPI BigNumFromBin(IN CONST UINT8 *Buf, IN UINTN Len)
BOOLEAN EFIAPI BigNumDiv(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
UINTN EFIAPI BigNumBits(IN CONST VOID *Bn)
VOID *EFIAPI BigNumNewContext(VOID)
VOID EFIAPI BigNumFree(IN VOID *Bn, IN BOOLEAN Clear)
BOOLEAN EFIAPI BigNumIsWord(IN CONST VOID *Bn, IN UINTN Num)
INTN EFIAPI BigNumCmp(IN CONST VOID *BnA, IN CONST VOID *BnB)
BOOLEAN EFIAPI BigNumAdd(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
VOID EFIAPI BigNumConstTime(IN VOID *Bn)
CONST VOID *EFIAPI BigNumValueOne(VOID)
BOOLEAN EFIAPI BigNumSetUint(IN VOID *Bn, IN UINTN Val)
VOID EFIAPI BigNumContextFree(IN VOID *BnCtx)
BOOLEAN EFIAPI BigNumIsOdd(IN CONST VOID *Bn)
BOOLEAN EFIAPI BigNumSub(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
BOOLEAN EFIAPI BigNumAddMod(IN CONST VOID *BnA, IN CONST VOID *BnB, IN CONST VOID *BnM, OUT VOID *BnRes)
BOOLEAN EFIAPI BigNumMod(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
VOID *EFIAPI BigNumInit(VOID)
BOOLEAN EFIAPI BigNumRShift(IN CONST VOID *Bn, IN UINTN N, OUT VOID *BnRes)
UINTN EFIAPI BigNumBytes(IN CONST VOID *Bn)
INTN EFIAPI BigNumToBin(IN CONST VOID *Bn, OUT UINT8 *Buf)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define ARRAY_SIZE(Array)
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define UT_ASSERT_TRUE(Expression)
#define UT_ASSERT_EQUAL(ValueA, ValueB)
#define UT_ASSERT_FALSE(Expression)