TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptBn.c
1
8#include "InternalCryptLib.h"
9#include <openssl/bn.h>
10
16VOID *
17EFIAPI
19 VOID
20 )
21{
22 return BN_new ();
23}
24
33VOID *
34EFIAPI
36 IN CONST UINT8 *Buf,
37 IN UINTN Len
38 )
39{
40 return BN_bin2bn (Buf, (INT32)Len, NULL);
41}
42
52INTN
53EFIAPI
55 IN CONST VOID *Bn,
56 OUT UINT8 *Buf
57 )
58{
59 return BN_bn2bin (Bn, Buf);
60}
61
68VOID
69EFIAPI
71 IN VOID *Bn,
72 IN BOOLEAN Clear
73 )
74{
75 if (Clear) {
76 BN_clear_free (Bn);
77 } else {
78 BN_free (Bn);
79 }
80}
81
94BOOLEAN
95EFIAPI
97 IN CONST VOID *BnA,
98 IN CONST VOID *BnB,
99 OUT VOID *BnRes
100 )
101{
102 return (BOOLEAN)BN_add (BnRes, BnA, BnB);
103}
104
117BOOLEAN
118EFIAPI
120 IN CONST VOID *BnA,
121 IN CONST VOID *BnB,
122 OUT VOID *BnRes
123 )
124{
125 return (BOOLEAN)BN_sub (BnRes, BnA, BnB);
126}
127
140BOOLEAN
141EFIAPI
143 IN CONST VOID *BnA,
144 IN CONST VOID *BnB,
145 OUT VOID *BnRes
146 )
147{
148 BOOLEAN RetVal;
149 BN_CTX *Ctx;
150
151 Ctx = BN_CTX_new ();
152 if (Ctx == NULL) {
153 return FALSE;
154 }
155
156 RetVal = (BOOLEAN)BN_mod (BnRes, BnA, BnB, Ctx);
157 BN_CTX_free (Ctx);
158
159 return RetVal;
160}
161
175BOOLEAN
176EFIAPI
178 IN CONST VOID *BnA,
179 IN CONST VOID *BnP,
180 IN CONST VOID *BnM,
181 OUT VOID *BnRes
182 )
183{
184 BOOLEAN RetVal;
185 BN_CTX *Ctx;
186
187 Ctx = BN_CTX_new ();
188 if (Ctx == NULL) {
189 return FALSE;
190 }
191
192 RetVal = (BOOLEAN)BN_mod_exp (BnRes, BnA, BnP, BnM, Ctx);
193
194 BN_CTX_free (Ctx);
195 return RetVal;
196}
197
210BOOLEAN
211EFIAPI
213 IN CONST VOID *BnA,
214 IN CONST VOID *BnM,
215 OUT VOID *BnRes
216 )
217{
218 BOOLEAN RetVal;
219 BN_CTX *Ctx;
220
221 Ctx = BN_CTX_new ();
222 if (Ctx == NULL) {
223 return FALSE;
224 }
225
226 RetVal = FALSE;
227 if (BN_mod_inverse (BnRes, BnA, BnM, Ctx) != NULL) {
228 RetVal = TRUE;
229 }
230
231 BN_CTX_free (Ctx);
232 return RetVal;
233}
234
247BOOLEAN
248EFIAPI
250 IN CONST VOID *BnA,
251 IN CONST VOID *BnB,
252 OUT VOID *BnRes
253 )
254{
255 BOOLEAN RetVal;
256 BN_CTX *Ctx;
257
258 Ctx = BN_CTX_new ();
259 if (Ctx == NULL) {
260 return FALSE;
261 }
262
263 RetVal = (BOOLEAN)BN_div (BnRes, NULL, BnA, BnB, Ctx);
264 BN_CTX_free (Ctx);
265
266 return RetVal;
267}
268
282BOOLEAN
283EFIAPI
285 IN CONST VOID *BnA,
286 IN CONST VOID *BnB,
287 IN CONST VOID *BnM,
288 OUT VOID *BnRes
289 )
290{
291 BOOLEAN RetVal;
292 BN_CTX *Ctx;
293
294 Ctx = BN_CTX_new ();
295 if (Ctx == NULL) {
296 return FALSE;
297 }
298
299 RetVal = (BOOLEAN)BN_mod_mul (BnRes, BnA, BnB, BnM, Ctx);
300 BN_CTX_free (Ctx);
301
302 return RetVal;
303}
304
315INTN
316EFIAPI
318 IN CONST VOID *BnA,
319 IN CONST VOID *BnB
320 )
321{
322 return BN_cmp (BnA, BnB);
323}
324
332UINTN
333EFIAPI
335 IN CONST VOID *Bn
336 )
337{
338 return BN_num_bits (Bn);
339}
340
348UINTN
349EFIAPI
351 IN CONST VOID *Bn
352 )
353{
354 return BN_num_bytes (Bn);
355}
356
366BOOLEAN
367EFIAPI
369 IN CONST VOID *Bn,
370 IN UINTN Num
371 )
372{
373 return (BOOLEAN)BN_is_word (Bn, Num);
374}
375
384BOOLEAN
385EFIAPI
387 IN CONST VOID *Bn
388 )
389{
390 return (BOOLEAN)BN_is_odd (Bn);
391}
392
402VOID *
403EFIAPI
405 OUT VOID *BnDst,
406 IN CONST VOID *BnSrc
407 )
408{
409 return BN_copy (BnDst, BnSrc);
410}
411
418CONST VOID *
419EFIAPI
421 VOID
422 )
423{
424 return BN_value_one ();
425}
426
439BOOLEAN
440EFIAPI
442 IN CONST VOID *Bn,
443 IN UINTN N,
444 OUT VOID *BnRes
445 )
446{
447 return (BOOLEAN)BN_rshift (BnRes, Bn, (INT32)N);
448}
449
457VOID
458EFIAPI
460 IN VOID *Bn
461 )
462{
463 BN_set_flags (Bn, BN_FLG_CONSTTIME);
464}
465
478BOOLEAN
479EFIAPI
481 IN CONST VOID *BnA,
482 IN CONST VOID *BnM,
483 OUT VOID *BnRes
484 )
485{
486 BOOLEAN RetVal;
487 BN_CTX *Ctx;
488
489 Ctx = BN_CTX_new ();
490 if (Ctx == NULL) {
491 return FALSE;
492 }
493
494 RetVal = (BOOLEAN)BN_mod_sqr (BnRes, BnA, BnM, Ctx);
495 BN_CTX_free (Ctx);
496
497 return RetVal;
498}
499
507VOID *
508EFIAPI
510 VOID
511 )
512{
513 return BN_CTX_new ();
514}
515
521VOID
522EFIAPI
524 IN VOID *BnCtx
525 )
526{
527 BN_CTX_free (BnCtx);
528}
529
539BOOLEAN
540EFIAPI
542 IN VOID *Bn,
543 IN UINTN Val
544 )
545{
546 return (BOOLEAN)BN_set_word (Bn, Val);
547}
548
560BOOLEAN
561EFIAPI
563 IN CONST VOID *BnA,
564 IN CONST VOID *BnB,
565 IN CONST VOID *BnM,
566 OUT VOID *BnRes
567 )
568{
569 BOOLEAN RetVal;
570 BN_CTX *Ctx;
571
572 Ctx = BN_CTX_new ();
573 if (Ctx == NULL) {
574 return FALSE;
575 }
576
577 RetVal = (BOOLEAN)BN_mod_add (BnRes, BnA, BnB, BnM, Ctx);
578 BN_CTX_free (Ctx);
579
580 return RetVal;
581}
UINT64 UINTN
INT64 INTN
BOOLEAN EFIAPI BigNumExpMod(IN CONST VOID *BnA, IN CONST VOID *BnP, IN CONST VOID *BnM, OUT VOID *BnRes)
Definition: CryptBn.c:177
BOOLEAN EFIAPI BigNumMulMod(IN CONST VOID *BnA, IN CONST VOID *BnB, IN CONST VOID *BnM, OUT VOID *BnRes)
Definition: CryptBn.c:284
BOOLEAN EFIAPI BigNumInverseMod(IN CONST VOID *BnA, IN CONST VOID *BnM, OUT VOID *BnRes)
Definition: CryptBn.c:212
VOID *EFIAPI BigNumFromBin(IN CONST UINT8 *Buf, IN UINTN Len)
Definition: CryptBn.c:35
BOOLEAN EFIAPI BigNumDiv(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
Definition: CryptBn.c:249
BOOLEAN EFIAPI BigNumSqrMod(IN CONST VOID *BnA, IN CONST VOID *BnM, OUT VOID *BnRes)
Definition: CryptBn.c:480
UINTN EFIAPI BigNumBits(IN CONST VOID *Bn)
Definition: CryptBn.c:334
VOID *EFIAPI BigNumNewContext(VOID)
Definition: CryptBn.c:509
VOID EFIAPI BigNumFree(IN VOID *Bn, IN BOOLEAN Clear)
Definition: CryptBn.c:70
BOOLEAN EFIAPI BigNumIsWord(IN CONST VOID *Bn, IN UINTN Num)
Definition: CryptBn.c:368
INTN EFIAPI BigNumCmp(IN CONST VOID *BnA, IN CONST VOID *BnB)
Definition: CryptBn.c:317
BOOLEAN EFIAPI BigNumAdd(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
Definition: CryptBn.c:96
VOID EFIAPI BigNumConstTime(IN VOID *Bn)
Definition: CryptBn.c:459
CONST VOID *EFIAPI BigNumValueOne(VOID)
Definition: CryptBn.c:420
BOOLEAN EFIAPI BigNumSetUint(IN VOID *Bn, IN UINTN Val)
Definition: CryptBn.c:541
VOID EFIAPI BigNumContextFree(IN VOID *BnCtx)
Definition: CryptBn.c:523
BOOLEAN EFIAPI BigNumIsOdd(IN CONST VOID *Bn)
Definition: CryptBn.c:386
BOOLEAN EFIAPI BigNumSub(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
Definition: CryptBn.c:119
VOID *EFIAPI BigNumCopy(OUT VOID *BnDst, IN CONST VOID *BnSrc)
Definition: CryptBn.c:404
BOOLEAN EFIAPI BigNumAddMod(IN CONST VOID *BnA, IN CONST VOID *BnB, IN CONST VOID *BnM, OUT VOID *BnRes)
Definition: CryptBn.c:562
BOOLEAN EFIAPI BigNumMod(IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
Definition: CryptBn.c:142
VOID *EFIAPI BigNumInit(VOID)
Definition: CryptBn.c:18
BOOLEAN EFIAPI BigNumRShift(IN CONST VOID *Bn, IN UINTN N, OUT VOID *BnRes)
Definition: CryptBn.c:441
UINTN EFIAPI BigNumBytes(IN CONST VOID *Bn)
Definition: CryptBn.c:350
INTN EFIAPI BigNumToBin(IN CONST VOID *Bn, OUT UINT8 *Buf)
Definition: CryptBn.c:54
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284