TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptRsaExt.c File Reference
#include "InternalCryptLib.h"
#include <mbedtls/rsa.h>

Go to the source code of this file.

Functions

BOOLEAN EFIAPI RsaGetKey (IN OUT VOID *RsaContext, IN RSA_KEY_TAG KeyTag, OUT UINT8 *BigNumber, IN OUT UINTN *BnSize)
 
BOOLEAN EFIAPI RsaGenerateKey (IN OUT VOID *RsaContext, IN UINTN ModulusLength, IN CONST UINT8 *PublicExponent, IN UINTN PublicExponentSize)
 
BOOLEAN EFIAPI RsaCheckKey (IN VOID *RsaContext)
 
BOOLEAN EFIAPI RsaPkcs1Sign (IN VOID *RsaContext, IN CONST UINT8 *MessageHash, IN UINTN HashSize, OUT UINT8 *Signature, IN OUT UINTN *SigSize)
 

Detailed Description

RSA Asymmetric Cipher Wrapper Implementation over MbedTLS.

This file implements following APIs which provide more capabilities for RSA: 1) RsaGetKey 2) RsaGenerateKey 3) RsaCheckKey 4) RsaPkcs1Sign

RFC 8017 - PKCS #1: RSA Cryptography Specifications Version 2.2

Copyright (c) 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CryptRsaExt.c.

Function Documentation

◆ RsaCheckKey()

BOOLEAN EFIAPI RsaCheckKey ( IN VOID *  RsaContext)

Validates key components of RSA context. NOTE: This function performs integrity checks on all the RSA key material, so the RSA key structure must contain all the private key data.

This function validates key components of RSA context in following aspects:

  • Whether p is a prime
  • Whether q is a prime
  • Whether n = p * q
  • Whether d*e = 1 mod lcm(p-1,q-1)

If RsaContext is NULL, then return FALSE.

Parameters
[in]RsaContextPointer to RSA context to check.
Return values
TRUERSA key components are valid.
FALSERSA key components are not valid.

Definition at line 236 of file CryptRsaExt.c.

◆ RsaGenerateKey()

BOOLEAN EFIAPI RsaGenerateKey ( IN OUT VOID *  RsaContext,
IN UINTN  ModulusLength,
IN CONST UINT8 *  PublicExponent,
IN UINTN  PublicExponentSize 
)

Generates RSA key components.

This function generates RSA key components. It takes RSA public exponent Pe and length in bits of RSA modulus N as input, and generates all key components. If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.

Before this function can be invoked, pseudorandom number generator must be correctly initialized by RandomSeed().

If RsaContext is NULL, then return FALSE.

Parameters
[in,out]RsaContextPointer to RSA context being set.
[in]ModulusLengthLength of RSA modulus N in bits.
[in]PublicExponentPointer to RSA public exponent.
[in]PublicExponentSizeSize of RSA public exponent buffer in bytes.
Return values
TRUERSA key component was generated successfully.
FALSEInvalid RSA key component tag.

Definition at line 157 of file CryptRsaExt.c.

◆ RsaGetKey()

BOOLEAN EFIAPI RsaGetKey ( IN OUT VOID *  RsaContext,
IN RSA_KEY_TAG  KeyTag,
OUT UINT8 *  BigNumber,
IN OUT UINTN BnSize 
)

Gets the tag-designated RSA key component from the established RSA context.

This function retrieves the tag-designated RSA key component from the established RSA context as a non-negative integer (octet string format represented in RSA PKCS#1). If specified key component has not been set or has been cleared, then returned BnSize is set to 0. If the BigNumber buffer is too small to hold the contents of the key, FALSE is returned and BnSize is set to the required buffer size to obtain the key.

If RsaContext is NULL, then return FALSE. If BnSize is NULL, then return FALSE. If BnSize is large enough but BigNumber is NULL, then return FALSE.

Parameters
[in,out]RsaContextPointer to RSA context being set.
[in]KeyTagTag of RSA key component being set.
[out]BigNumberPointer to octet integer buffer.
[in,out]BnSizeOn input, the size of big number buffer in bytes. On output, the size of data returned in big number buffer in bytes.
Return values
TRUERSA key component was retrieved successfully.
FALSEInvalid RSA key component tag.
FALSEBnSize is too small.

Definition at line 48 of file CryptRsaExt.c.

◆ RsaPkcs1Sign()

BOOLEAN EFIAPI RsaPkcs1Sign ( IN VOID *  RsaContext,
IN CONST UINT8 *  MessageHash,
IN UINTN  HashSize,
OUT UINT8 *  Signature,
IN OUT UINTN SigSize 
)

Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.

This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in RSA PKCS#1. If the Signature buffer is too small to hold the contents of signature, FALSE is returned and SigSize is set to the required buffer size to obtain the signature.

If RsaContext is NULL, then return FALSE. If MessageHash is NULL, then return FALSE. If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-384 or SHA-512 digest, then return FALSE. If SigSize is large enough but Signature is NULL, then return FALSE.

Parameters
[in]RsaContextPointer to RSA context for signature generation.
[in]MessageHashPointer to octet message hash to be signed.
[in]HashSizeSize of the message hash in bytes.
[out]SignaturePointer to buffer to receive RSA PKCS1-v1_5 signature.
[in,out]SigSizeOn input, the size of Signature buffer in bytes. On output, the size of data returned in Signature buffer in bytes.
Return values
TRUESignature successfully generated in PKCS1-v1_5.
FALSESignature generation failed.
FALSESigSize is too small.

Definition at line 281 of file CryptRsaExt.c.