TestRsaPreprocess: EDK-II codestyle cleanup
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#include <UserFile.h>
-#include <Base.h>
-
#include <Library/OcCryptoLib.h>
#include <Library/OcAppleKeysLib.h>
#include <BigNumLib.h>
-int verifyRsa (CONST OC_RSA_PUBLIC_KEY *PublicKey, char *Name)
+VOID
+VerifyRsa (
+ IN CONST OC_RSA_PUBLIC_KEY *PublicKey,
+ IN CONST CHAR8 *Name
+ )
{
OC_BN_WORD N0Inv;
- UINTN ModulusSize = PublicKey->Hdr.NumQwords * sizeof (UINT64);
+ UINTN ModulusSize;
+ OC_BN_WORD *RSqrMod;
+ OC_BN_WORD *Scratch;
+
+ ModulusSize = PublicKey->Hdr.NumQwords * sizeof (UINT64);
+ RSqrMod = AllocatePool (ModulusSize);
+ Scratch = AllocatePool (BIG_NUM_MONT_PARAMS_SCRATCH_SIZE (ModulusSize / OC_BN_WORD_SIZE));
- OC_BN_WORD *RSqrMod = malloc(ModulusSize);
- OC_BN_WORD *Scratch = malloc(
- BIG_NUM_MONT_PARAMS_SCRATCH_SIZE(ModulusSize / OC_BN_WORD_SIZE)
- );
if (RSqrMod == NULL || Scratch == NULL) {
- printf ("memory allocation error!\n");
- free(RSqrMod);
- free(Scratch);
- return -1;
+ DEBUG ((DEBUG_ERROR, "memory allocation error!\n"));
+ FreePool (RSqrMod);
+ FreePool (Scratch);
}
N0Inv = BigNumCalculateMontParams (
@@ -49,42 +47,47 @@ int verifyRsa (CONST OC_RSA_PUBLIC_KEY *PublicKey, char *Name)
Scratch
);
- printf (
- "%s: results: %d %d (%llX vs %llX)\n",
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: results: %d %d (%LX vs %LX)\n",
Name,
- memcmp (
+ CompareMem (
RSqrMod,
&PublicKey->Data[PublicKey->Hdr.NumQwords],
ModulusSize
),
N0Inv != PublicKey->Hdr.N0Inv,
- (unsigned long long) N0Inv,
- (unsigned long long) PublicKey->Hdr.N0Inv
- );
+ (UINT64) N0Inv,
+ (UINT64) PublicKey->Hdr.N0Inv
+ ));
- free(Scratch);
- free(RSqrMod);
- return 0;
+ FreePool (Scratch);
+ FreePool (RSqrMod);
}
-int main(int argc, char *argv[]) {
- unsigned int Index;
+int
+ENTRY_POINT (
+ int argc,
+ char *argv[]
+ )
+{
+ int Index;
OC_RSA_PUBLIC_KEY *PublicKey;
- uint32_t PkSize;
+ UINT32 PkSize;
- for (Index = 1; (int) Index < argc; ++Index) {
+ for (Index = 1; Index < argc; ++Index) {
PublicKey = (OC_RSA_PUBLIC_KEY *) UserReadFile (argv[Index], &PkSize);
if (PublicKey == NULL) {
- printf ("read error\n");
+ DEBUG ((DEBUG_ERROR, "read error\n"));
return -1;
}
- verifyRsa (PublicKey, argv[Index]);
- free (PublicKey);
+ VerifyRsa (PublicKey, argv[Index]);
+ FreePool (PublicKey);
}
- for (Index = 0; (unsigned long) Index < ARRAY_SIZE (PkDataBase); ++Index) {
- verifyRsa (PkDataBase[Index].PublicKey, "inbuilt");
+ for (Index = 0; (UINTN) Index < ARRAY_SIZE (PkDataBase); ++Index) {
+ VerifyRsa (PkDataBase[Index].PublicKey, "inbuilt");
}
return 0;
