OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
RsaPreprocess.c
Go to the documentation of this file.
1
15#include <UserFile.h>
16
17#include <Library/OcCryptoLib.h>
19
20#include <BigNumLib.h>
21
22VOID
24 IN CONST OC_RSA_PUBLIC_KEY *PublicKey,
25 IN CONST CHAR8 *Name
26 )
27{
28 OC_BN_WORD N0Inv;
29 UINTN ModulusSize;
30 OC_BN_WORD *RSqrMod;
31 OC_BN_WORD *Scratch;
32
33 ModulusSize = PublicKey->Hdr.NumQwords * sizeof (UINT64);
34 RSqrMod = AllocatePool (ModulusSize);
35 Scratch = AllocatePool (BIG_NUM_MONT_PARAMS_SCRATCH_SIZE (ModulusSize / OC_BN_WORD_SIZE));
36
37 if ((RSqrMod == NULL) || (Scratch == NULL)) {
38 DEBUG ((DEBUG_ERROR, "memory allocation error!\n"));
39 FreePool (RSqrMod);
40 FreePool (Scratch);
41 }
42
44 RSqrMod,
45 ModulusSize / OC_BN_WORD_SIZE,
46 (CONST OC_BN_WORD *)PublicKey->Data,
47 Scratch
48 );
49
50 DEBUG ((
51 DEBUG_ERROR,
52 "%a: results: %d %d (%LX vs %LX)\n",
53 Name,
55 RSqrMod,
56 &PublicKey->Data[PublicKey->Hdr.NumQwords],
57 ModulusSize
58 ),
59 N0Inv != PublicKey->Hdr.N0Inv,
60 (UINT64)N0Inv,
61 (UINT64)PublicKey->Hdr.N0Inv
62 ));
63
64 FreePool (Scratch);
65 FreePool (RSqrMod);
66}
67
68int
70 int argc,
71 char *argv[]
72 )
73{
74 int Index;
75 OC_RSA_PUBLIC_KEY *PublicKey;
76 UINT32 PkSize;
77
78 for (Index = 1; Index < argc; ++Index) {
79 PublicKey = (OC_RSA_PUBLIC_KEY *)UserReadFile (argv[Index], &PkSize);
80 if (PublicKey == NULL) {
81 DEBUG ((DEBUG_ERROR, "read error\n"));
82 return -1;
83 }
84
85 VerifyRsa (PublicKey, argv[Index]);
86 FreePool (PublicKey);
87 }
88
89 for (Index = 0; (UINTN)Index < ARRAY_SIZE (PkDataBase); ++Index) {
90 VerifyRsa (PkDataBase[Index].PublicKey, "inbuilt");
91 }
92
93 return 0;
94}
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
UINTN OC_BN_WORD
Definition BigNumLib.h:26
OC_BN_WORD BigNumCalculateMontParams(IN OUT OC_BN_WORD *RSqrMod, IN OC_BN_NUM_WORDS NumWords, IN CONST OC_BN_WORD *N, IN OC_BN_WORD *Scratch)
#define OC_BN_WORD_SIZE
Definition BigNumLib.h:30
#define BIG_NUM_MONT_PARAMS_SCRATCH_SIZE(NumWords)
Definition BigNumLib.h:136
CONST APPLE_PK_ENTRY PkDataBase[NUM_OF_PK]
VOID VerifyRsa(IN CONST OC_RSA_PUBLIC_KEY *PublicKey, IN CONST CHAR8 *Name)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINT8 * UserReadFile(IN CONST CHAR8 *FileName, OUT UINT32 *Size)
Definition UserFile.c:62
int ENTRY_POINT(void)