17#include "InternalCryptLib.h"
18#include <mbedtls/rsa.h>
49 IN OUT VOID *RsaContext,
55 mbedtls_rsa_context *RsaKey;
63 if ((RsaContext ==
NULL) || (*BnSize > INT_MAX)) {
70 mbedtls_mpi_init (&Value);
74 RsaKey = (mbedtls_rsa_context *)RsaContext;
104 if (mbedtls_mpi_size (&Value) == 0) {
111 Size = mbedtls_mpi_size (&Value);
112 if (*BnSize < Size) {
118 if (BigNumber ==
NULL) {
124 if ((BigNumber !=
NULL) && (Ret == 0)) {
125 Ret = mbedtls_mpi_write_binary (&Value, BigNumber, Size);
130 mbedtls_mpi_free (&Value);
158 IN OUT VOID *RsaContext,
160 IN CONST UINT8 *PublicExponent,
165 mbedtls_rsa_context *Rsa;
171 if ((RsaContext ==
NULL) || (ModulusLength > INT_MAX) || (PublicExponentSize > INT_MAX)) {
175 Rsa = (mbedtls_rsa_context *)RsaContext;
177 if (PublicExponent ==
NULL) {
180 if (PublicExponentSize == 0) {
184 switch (PublicExponentSize) {
186 Pe = PublicExponent[0];
189 Pe = PublicExponent[0] << 8 | PublicExponent[1];
192 Pe = PublicExponent[0] << 16 | PublicExponent[1] << 8 |
196 Pe = PublicExponent[0] << 24 | PublicExponent[1] << 16 |
197 PublicExponent[2] << 8 | PublicExponent[3];
204 Ret = mbedtls_rsa_gen_key (
208 (UINT32)ModulusLength,
240 if (RsaContext ==
NULL) {
246 Ret = mbedtls_rsa_complete (RsaContext);
248 Ret = mbedtls_rsa_check_privkey (RsaContext);
285 OUT UINT8 *Signature,
290 mbedtls_md_type_t MdAlg;
292 if ((RsaContext ==
NULL) || (MessageHash ==
NULL)) {
296 if (mbedtls_rsa_complete ((mbedtls_rsa_context *)RsaContext) != 0) {
301 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
303 MdAlg = MBEDTLS_MD_SHA1;
308 MdAlg = MBEDTLS_MD_SHA256;
312 MdAlg = MBEDTLS_MD_SHA384;
316 MdAlg = MBEDTLS_MD_SHA512;
323 if (mbedtls_rsa_get_len (RsaContext) > *SigSize) {
324 *SigSize = mbedtls_rsa_get_len (RsaContext);
328 if (Signature ==
NULL) {
332 Ret = mbedtls_rsa_set_padding (RsaContext, MBEDTLS_RSA_PKCS_V15, MdAlg);
337 Ret = mbedtls_rsa_pkcs1_sign (
350 *SigSize = mbedtls_rsa_get_len (RsaContext);
@ 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
INT32 MbedtlsRand(VOID *RngState, UINT8 *Output, UINTN Len)
BOOLEAN EFIAPI RsaCheckKey(IN VOID *RsaContext)
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 RsaPkcs1Sign(IN VOID *RsaContext, IN CONST UINT8 *MessageHash, IN UINTN HashSize, OUT UINT8 *Signature, IN OUT UINTN *SigSize)