OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
RsaDigitalSign.c File Reference
#include "BigNumLib.h"

Go to the source code of this file.

Functions

STATIC BOOLEAN InternalRsaModulusSizeIsAllowed (IN OC_BN_SIZE ModulusSize)
 
STATIC BOOLEAN InternalSigHashTypeIsAllowed (IN OC_SIG_HASH_TYPE Type)
 
INTN SigVerifyShaHashBySize (IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Hash, IN UINTN HashSize)
 
STATIC BOOLEAN RsaVerifySigHashFromProcessed (IN CONST OC_BN_WORD *N, IN OC_BN_NUM_WORDS NumWords, IN OC_BN_WORD N0Inv, IN CONST OC_BN_WORD *RSqrMod, IN UINT32 Exponent, IN CONST UINT8 *Signature, IN UINTN SignatureSize, IN CONST UINT8 *Hash, IN UINTN HashSize, IN OC_SIG_HASH_TYPE Algorithm, IN OC_BN_WORD *Scratch)
 
STATIC BOOLEAN RsaVerifySigDataFromProcessed (IN CONST OC_BN_WORD *N, IN OC_BN_NUM_WORDS NumWords, IN OC_BN_WORD N0Inv, IN CONST OC_BN_WORD *RSqrMod, IN UINT32 Exponent, IN CONST UINT8 *Signature, IN UINTN SignatureSize, IN CONST UINT8 *Data, IN UINTN DataSize, IN OC_SIG_HASH_TYPE Algorithm, IN OC_BN_WORD *Scratch)
 
BOOLEAN RsaVerifySigDataFromData (IN CONST UINT8 *Modulus, IN UINTN ModulusSize, IN UINT32 Exponent, IN CONST UINT8 *Signature, IN UINTN SignatureSize, IN CONST UINT8 *Data, IN UINTN DataSize, IN OC_SIG_HASH_TYPE Algorithm)
 
BOOLEAN RsaVerifySigHashFromKey (IN CONST OC_RSA_PUBLIC_KEY *Key, IN CONST UINT8 *Signature, IN UINTN SignatureSize, IN CONST UINT8 *Hash, IN UINTN HashSize, IN OC_SIG_HASH_TYPE Algorithm, IN VOID *Scratch)
 
BOOLEAN RsaVerifySigHashFromKeyDynalloc (IN CONST OC_RSA_PUBLIC_KEY *Key, IN CONST UINT8 *Signature, IN UINTN SignatureSize, IN CONST UINT8 *Hash, IN UINTN HashSize, IN OC_SIG_HASH_TYPE Algorithm)
 
BOOLEAN RsaVerifySigDataFromKey (IN CONST OC_RSA_PUBLIC_KEY *Key, IN CONST UINT8 *Signature, IN UINTN SignatureSize, IN CONST UINT8 *Data, IN UINTN DataSize, IN OC_SIG_HASH_TYPE Algorithm, IN VOID *Scratch)
 
BOOLEAN RsaVerifySigDataFromKeyDynalloc (IN CONST OC_RSA_PUBLIC_KEY *Key, IN CONST UINT8 *Signature, IN UINTN SignatureSize, IN CONST UINT8 *Data, IN UINTN DataSize, IN OC_SIG_HASH_TYPE Algorithm)
 

Detailed Description

This library performs RSA-based cryptography operations.

SECURITY: Currently, no security measures have been taken. This code is vulnerable to both timing and side channel attacks for value leakage. However, its current purpose is the verification of public binaries with public certificates, for which this is perfectly acceptable, especially in regards to performance.

Copyright (C) 2019, Download-Fritz. All rights reserved.

This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Definition in file RsaDigitalSign.c.

Function Documentation

◆ InternalRsaModulusSizeIsAllowed()

STATIC BOOLEAN InternalRsaModulusSizeIsAllowed ( IN OC_BN_SIZE ModulusSize)

Returns whether the RSA modulus size is allowed.

Parameters
[in]ModulusSizeThe size, in bytes, of the RSA modulus.

Definition at line 57 of file RsaDigitalSign.c.

◆ InternalSigHashTypeIsAllowed()

STATIC BOOLEAN InternalSigHashTypeIsAllowed ( IN OC_SIG_HASH_TYPE Type)

Returns whether the signature hashing algorithm is allowed.

Parameters
[in]TypeThe signature hashing algorithm type.

Definition at line 79 of file RsaDigitalSign.c.

◆ RsaVerifySigDataFromData()

BOOLEAN RsaVerifySigDataFromData ( IN CONST UINT8 * Modulus,
IN UINTN ModulusSize,
IN UINT32 Exponent,
IN CONST UINT8 * Signature,
IN UINTN SignatureSize,
IN CONST UINT8 * Data,
IN UINTN DataSize,
IN OC_SIG_HASH_TYPE Algorithm )

Verify RSA PKCS1.5 signed data against its signature. The modulus' size must be a multiple of the configured BIGNUM word size. This will be true for any conventional RSA, which use two's potencies.

Parameters
[in]ModulusThe RSA modulus byte array.
[in]ModulusSizeThe size, in bytes, of Modulus.
[in]ExponentThe RSA exponent.
[in]SignatureThe RSA signature to be verified.
[in]SignatureSizeSize, in bytes, of Signature.
[in]DataThe signed data to verify.
[in]DataSizeSize, in bytes, of Data.
[in]AlgorithmThe RSA algorithm used.
Returns
Whether the signature has been successfully verified as valid.

Definition at line 488 of file RsaDigitalSign.c.

◆ RsaVerifySigDataFromKey()

BOOLEAN RsaVerifySigDataFromKey ( IN CONST OC_RSA_PUBLIC_KEY * Key,
IN CONST UINT8 * Signature,
IN UINTN SignatureSize,
IN CONST UINT8 * Data,
IN UINTN DataSize,
IN OC_SIG_HASH_TYPE Algorithm,
IN VOID * Scratch )

Verify RSA PKCS1.5 signed data against its signature. The modulus' size must be a multiple of the configured BIGNUM word size. This will be true for any conventional RSA, which use two's potencies. The exponent is always 65537 as per the format specification.

Parameters
[in]KeyThe RSA Public Key.
[in]SignatureThe RSA signature to be verified.
[in]SignatureSizeSize, in bytes, of Signature.
[in]DataThe signed data to verify.
[in]DataSizeSize, in bytes, of Data.
[in]AlgorithmThe RSA algorithm used.
[in]ScratchScratch buffer 3xModulo.
Returns
Whether the signature has been successfully verified as valid.

Definition at line 673 of file RsaDigitalSign.c.

◆ RsaVerifySigDataFromKeyDynalloc()

BOOLEAN RsaVerifySigDataFromKeyDynalloc ( IN CONST OC_RSA_PUBLIC_KEY * Key,
IN CONST UINT8 * Signature,
IN UINTN SignatureSize,
IN CONST UINT8 * Data,
IN UINTN DataSize,
IN OC_SIG_HASH_TYPE Algorithm )

Verify RSA PKCS1.5 signed data against its signature. The modulus' size must be a multiple of the configured BIGNUM word size. This will be true for any conventional RSA, which use two's potencies. The exponent is always 65537 as per the format specification.

Parameters
[in]KeyThe RSA Public Key.
[in]SignatureThe RSA signature to be verified.
[in]SignatureSizeSize, in bytes, of Signature.
[in]DataThe signed data to verify.
[in]DataSizeSize, in bytes, of Data.
[in]AlgorithmThe RSA algorithm used.
Returns
Whether the signature has been successfully verified as valid.

Definition at line 715 of file RsaDigitalSign.c.

◆ RsaVerifySigDataFromProcessed()

STATIC BOOLEAN RsaVerifySigDataFromProcessed ( IN CONST OC_BN_WORD * N,
IN OC_BN_NUM_WORDS NumWords,
IN OC_BN_WORD N0Inv,
IN CONST OC_BN_WORD * RSqrMod,
IN UINT32 Exponent,
IN CONST UINT8 * Signature,
IN UINTN SignatureSize,
IN CONST UINT8 * Data,
IN UINTN DataSize,
IN OC_SIG_HASH_TYPE Algorithm,
IN OC_BN_WORD * Scratch )

Verify RSA PKCS1.5 signed data against its signature. The modulus' size must be a multiple of the configured BIGNUM word size. This will be true for any conventional RSA, which use two's potencies.

Parameters
[in]NThe RSA modulus.
[in]NumWordsThe number of Words of N and RSqrMod.
[in]N0InvThe Montgomery Inverse of N.
[in]RSqrModMontgomery's R^2 mod N.
[in]ExponentThe RSA exponent.
[in]SignatureThe RSA signature to be verified.
[in]SignatureSizeSize, in bytes, of Signature.
[in]DataThe signed data to verify.
[in]DataSizeSize, in bytes, of Data.
[in]AlgorithmThe RSA algorithm used.
[in]ScratchScratch buffer 3xModulo.
Returns
Whether the signature has been successfully verified as valid.

Definition at line 401 of file RsaDigitalSign.c.

◆ RsaVerifySigHashFromKey()

BOOLEAN RsaVerifySigHashFromKey ( IN CONST OC_RSA_PUBLIC_KEY * Key,
IN CONST UINT8 * Signature,
IN UINTN SignatureSize,
IN CONST UINT8 * Hash,
IN UINTN HashSize,
IN OC_SIG_HASH_TYPE Algorithm,
IN VOID * Scratch )

Verify a RSA PKCS1.5 signature against an expected hash. The exponent is always 65537 as per the format specification.

Parameters
[in]KeyThe RSA Public Key.
[in]SignatureThe RSA signature to be verified.
[in]SignatureSizeSize, in bytes, of Signature.
[in]HashThe Hash digest of the signed data.
[in]HashSizeSize, in bytes, of Hash.
[in]AlgorithmThe RSA algorithm used.
[in]ScratchScratch buffer 3xModulo.
Returns
Whether the signature has been successfully verified as valid.

Definition at line 589 of file RsaDigitalSign.c.

◆ RsaVerifySigHashFromKeyDynalloc()

BOOLEAN RsaVerifySigHashFromKeyDynalloc ( IN CONST OC_RSA_PUBLIC_KEY * Key,
IN CONST UINT8 * Signature,
IN UINTN SignatureSize,
IN CONST UINT8 * Hash,
IN UINTN HashSize,
IN OC_SIG_HASH_TYPE Algorithm )

Verify a RSA PKCS1.5 signature against an expected hash. The exponent is always 65537 as per the format specification.

Parameters
[in]KeyThe RSA Public Key.
[in]SignatureThe RSA signature to be verified.
[in]SignatureSizeSize, in bytes, of Signature.
[in]HashThe Hash digest of the signed data.
[in]HashSizeSize, in bytes, of Hash.
[in]AlgorithmThe RSA algorithm used.
Returns
Whether the signature has been successfully verified as valid.

Definition at line 631 of file RsaDigitalSign.c.

◆ RsaVerifySigHashFromProcessed()

STATIC BOOLEAN RsaVerifySigHashFromProcessed ( IN CONST OC_BN_WORD * N,
IN OC_BN_NUM_WORDS NumWords,
IN OC_BN_WORD N0Inv,
IN CONST OC_BN_WORD * RSqrMod,
IN UINT32 Exponent,
IN CONST UINT8 * Signature,
IN UINTN SignatureSize,
IN CONST UINT8 * Hash,
IN UINTN HashSize,
IN OC_SIG_HASH_TYPE Algorithm,
IN OC_BN_WORD * Scratch )

Verify a RSA PKCS1.5 signature against an expected hash.

Parameters
[in]NThe RSA modulus.
[in]N0InvThe Montgomery Inverse of N.
[in]RSqrModMontgomery's R^2 mod N.
[in]NumWordsThe number of Words of N and RSqrMod.
[in]ExponentThe RSA exponent.
[in]SignatureThe RSA signature to be verified.
[in]SignatureSizeSize, in bytes, of Signature.
[in]HashThe Hash digest of the signed data.
[in]HashSizeSize, in bytes, of Hash.
[in]AlgorithmThe RSA algorithm used.
[in]ScratchScratch buffer 3xModulo.
Returns
Whether the signature has been successfully verified as valid.

Definition at line 164 of file RsaDigitalSign.c.

◆ SigVerifyShaHashBySize()

INTN SigVerifyShaHashBySize ( IN CONST VOID * Data,
IN UINTN DataSize,
IN CONST UINT8 * Hash,
IN UINTN HashSize )

Verifies Data against Hash with the appropiate SHA2 algorithm for HashSize.

Parameters
[in]DataThe data to verify the hash of.
[in]DataSizeThe, in bytes, of Data.
[in]HashThe reference hash to verify against.
[in]HashSizeThe size, in bytes, of Hash.
Returns
0 All HashSize bytes of the two buffers are identical.
Return values
Non-zeroIf HashSize is not a valid SHA2 digest size, -1. Otherwise, the first mismatched byte in Data's hash subtracted from the first mismatched byte in Hash.

Definition at line 87 of file RsaDigitalSign.c.