]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Bn/CryptBnNull.c
2 Big number API implementation based on OpenSSL
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseCryptLib.h>
10 #include <Library/DebugLib.h>
13 Allocate new Big Number.
15 @retval New BigNum opaque structure or NULL on failure.
28 Allocate new Big Number and assign the provided value to it.
30 @param[in] Buf Big endian encoded buffer.
31 @param[in] Len Buffer length.
33 @retval New BigNum opaque structure or NULL on failure.
47 Convert the absolute value of Bn into big-endian form and store it at Buf.
48 The Buf array should have at least BigNumBytes() in it.
50 @param[in] Bn Big number to convert.
51 @param[out] Buf Output buffer.
53 @retval The length of the big-endian number placed at Buf or -1 on error.
69 @param[in] Bn Big number to free.
70 @param[in] Clear TRUE if the buffer should be cleared.
83 Calculate the sum of two Big Numbers.
84 Please note, all "out" Big number arguments should be properly initialized
85 by calling to BigNumInit() or BigNumFromBin() functions.
87 @param[in] BnA Big number.
88 @param[in] BnB Big number.
89 @param[out] BnRes The result of BnA + BnB.
91 @retval TRUE On success.
92 @retval FALSE Otherwise.
107 Subtract two Big Numbers.
108 Please note, all "out" Big number arguments should be properly initialized
109 by calling to BigNumInit() or BigNumFromBin() functions.
111 @param[in] BnA Big number.
112 @param[in] BnB Big number.
113 @param[out] BnRes The result of BnA - BnB.
115 @retval TRUE On success.
116 @retval FALSE Otherwise.
131 Calculate remainder: BnRes = BnA % BnB.
132 Please note, all "out" Big number arguments should be properly initialized
133 by calling to BigNumInit() or BigNumFromBin() functions.
135 @param[in] BnA Big number.
136 @param[in] BnB Big number.
137 @param[out] BnRes The result of BnA % BnB.
139 @retval TRUE On success.
140 @retval FALSE Otherwise.
155 Compute BnA to the BnP-th power modulo BnM.
156 Please note, all "out" Big number arguments should be properly initialized
157 by calling to BigNumInit() or BigNumFromBin() functions.
159 @param[in] BnA Big number.
160 @param[in] BnP Big number (power).
161 @param[in] BnM Big number (modulo).
162 @param[out] BnRes The result of (BnA ^ BnP) % BnM.
164 @retval TRUE On success.
165 @retval FALSE Otherwise.
181 Compute BnA inverse modulo BnM.
182 Please note, all "out" Big number arguments should be properly initialized
183 by calling to BigNumInit() or BigNumFromBin() functions.
185 @param[in] BnA Big number.
186 @param[in] BnM Big number (modulo).
187 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.
189 @retval TRUE On success.
190 @retval FALSE Otherwise.
205 Divide two Big Numbers.
206 Please note, all "out" Big number arguments should be properly initialized
207 by calling to BigNumInit() or BigNumFromBin() functions.
209 @param[in] BnA Big number.
210 @param[in] BnB Big number.
211 @param[out] BnRes The result, such that BnA / BnB.
213 @retval TRUE On success.
214 @retval FALSE Otherwise.
229 Multiply two Big Numbers modulo BnM.
230 Please note, all "out" Big number arguments should be properly initialized
231 by calling to BigNumInit() or BigNumFromBin() functions.
233 @param[in] BnA Big number.
234 @param[in] BnB Big number.
235 @param[in] BnM Big number (modulo).
236 @param[out] BnRes The result, such that (BnA * BnB) % BnM.
238 @retval TRUE On success.
239 @retval FALSE Otherwise.
255 Compare two Big Numbers.
257 @param[in] BnA Big number.
258 @param[in] BnB Big number.
260 @retval 0 BnA == BnB.
262 @retval -1 BnA < BnB.
276 Get number of bits in Bn.
278 @param[in] Bn Big number.
280 @retval Number of bits.
293 Get number of bytes in Bn.
295 @param[in] Bn Big number.
297 @retval Number of bytes.
310 Checks if Big Number equals to the given Num.
312 @param[in] Bn Big number.
313 @param[in] Num Number.
315 @retval TRUE iff Bn == Num.
316 @retval FALSE otherwise.
330 Checks if Big Number is odd.
332 @param[in] Bn Big number.
334 @retval TRUE Bn is odd (Bn % 2 == 1).
335 @retval FALSE otherwise.
350 @param[out] BnDst Destination.
351 @param[in] BnSrc Source.
353 @retval BnDst on success.
354 @retval NULL otherwise.
368 Get constant Big number with value of "1".
369 This may be used to save expensive allocations.
371 @retval Big Number with value of 1.
384 Shift right Big Number.
385 Please note, all "out" Big number arguments should be properly initialized
386 by calling to BigNumInit() or BigNumFromBin() functions.
388 @param[in] Bn Big number.
389 @param[in] N Number of bits to shift.
390 @param[out] BnRes The result.
392 @retval TRUE On success.
393 @retval FALSE Otherwise.
408 Mark Big Number for constant time computations.
409 This function should be called before any constant time computations are
410 performed on the given Big number.
412 @param[in] Bn Big number
424 Calculate square modulo.
425 Please note, all "out" Big number arguments should be properly initialized
426 by calling to BigNumInit() or BigNumFromBin() functions.
428 @param[in] BnA Big number.
429 @param[in] BnM Big number (modulo).
430 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.
432 @retval TRUE On success.
433 @retval FALSE Otherwise.
448 Create new Big Number computation context. This is an opaque structure
449 which should be passed to any function that requires it. The BN context is
450 needed to optimize calculations and expensive allocations.
452 @retval Big Number context struct or NULL on failure.
465 Free Big Number context that was allocated with BigNumNewContext().
467 @param[in] BnCtx Big number context to free.
479 Set Big Number to a given value.
481 @param[in] Bn Big number to set.
482 @param[in] Val Value to set.
484 @retval TRUE On success.
485 @retval FALSE Otherwise.
499 Add two Big Numbers modulo BnM.
501 @param[in] BnA Big number.
502 @param[in] BnB Big number.
503 @param[in] BnM Big number (modulo).
504 @param[out] BnRes The result, such that (BnA + BnB) % BnM.
506 @retval TRUE On success.
507 @retval FALSE Otherwise.