17#include "InternalCryptLib.h"
19#include <mbedtls/rsa.h>
37 if (RsaContext ==
NULL) {
41 mbedtls_rsa_init (RsaContext);
42 if (mbedtls_rsa_set_padding (RsaContext, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE) != 0) {
61 mbedtls_rsa_free (RsaContext);
62 if (RsaContext !=
NULL) {
92 IN OUT VOID *RsaContext,
98 mbedtls_rsa_context *RsaKey;
105 if ((RsaContext ==
NULL) || (BnSize > INT_MAX)) {
109 mbedtls_mpi_init (&Value);
111 RsaKey = (mbedtls_rsa_context *)RsaContext;
114 if (BigNumber !=
NULL) {
115 Ret = mbedtls_mpi_read_binary (&Value, BigNumber, BnSize);
117 mbedtls_mpi_free (&Value);
124 Ret = mbedtls_rsa_import (
134 Ret = mbedtls_rsa_import (
144 Ret = mbedtls_rsa_import (
154 Ret = mbedtls_rsa_import (
164 Ret = mbedtls_rsa_import (
181 mbedtls_mpi_free (&Value);
215 mbedtls_md_type_t md_alg;
216 mbedtls_rsa_context *RsaKey;
218 if ((RsaContext ==
NULL) || (MessageHash ==
NULL) || (Signature ==
NULL)) {
222 if ((SigSize > INT_MAX) || (SigSize == 0)) {
226 RsaKey = (mbedtls_rsa_context *)RsaContext;
227 if (mbedtls_rsa_complete (RsaKey) != 0) {
232 #ifdef ENABLE_MD5_DEPRECATED_INTERFACES
234 md_alg = MBEDTLS_MD_MD5;
238 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
240 md_alg = MBEDTLS_MD_SHA1;
245 md_alg = MBEDTLS_MD_SHA256;
249 md_alg = MBEDTLS_MD_SHA384;
253 md_alg = MBEDTLS_MD_SHA512;
260 if (mbedtls_rsa_get_len (RsaContext) != SigSize) {
264 mbedtls_rsa_set_padding (RsaContext, MBEDTLS_RSA_PKCS_V15, md_alg);
266 Ret = mbedtls_rsa_pkcs1_verify (
@ RsaKeyDq
q's CRT exponent (== d mod (q - 1))
@ RsaKeyD
RSA Private exponent (d)
@ RsaKeyDp
p's CRT exponent (== d mod (p - 1))
@ RsaKeyP
RSA secret prime factor of Modulus (p)
@ RsaKeyN
RSA public Modulus (N)
@ RsaKeyQ
RSA secret prime factor of Modules (q)
@ RsaKeyQInv
The CRT coefficient (== 1/q mod p)
@ RsaKeyE
RSA Public exponent (e)
#define SHA512_DIGEST_SIZE
#define SHA256_DIGEST_SIZE
#define SHA384_DIGEST_SIZE
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI RsaNew(VOID)
BOOLEAN EFIAPI RsaSetKey(IN OUT VOID *RsaContext, IN RSA_KEY_TAG KeyTag, IN CONST UINT8 *BigNumber, IN UINTN BnSize)
VOID EFIAPI RsaFree(IN VOID *RsaContext)
BOOLEAN EFIAPI RsaPkcs1Verify(IN VOID *RsaContext, IN CONST UINT8 *MessageHash, IN UINTN HashSize, IN CONST UINT8 *Signature, IN UINTN SigSize)