15#include "InternalCryptLib.h"
17#include <openssl/bn.h>
18#include <openssl/rsa.h>
19#include <openssl/objects.h>
37 return (VOID *)RSA_new ();
55 RSA_free ((RSA *)RsaContext);
83 IN OUT VOID *RsaContext,
102 if ((RsaContext ==
NULL) || (BnSize > INT_MAX)) {
118 RsaKey = (RSA *)RsaContext;
119 RSA_get0_key (RsaKey, (
const BIGNUM **)&BnN, (
const BIGNUM **)&BnE, (
const BIGNUM **)&BnD);
120 RSA_get0_factors (RsaKey, (
const BIGNUM **)&BnP, (
const BIGNUM **)&BnQ);
121 RSA_get0_crt_params (RsaKey, (
const BIGNUM **)&BnDp, (
const BIGNUM **)&BnDq, (
const BIGNUM **)&BnQInv);
153 BnN = BN_bin2bn (BigNumber, (UINT32)BnSize, BnN);
156 BnE = BN_bin2bn (BigNumber, (UINT32)BnSize, BnE);
159 BnD = BN_bin2bn (BigNumber, (UINT32)BnSize, BnD);
165 if (RSA_set0_key (RsaKey, BN_dup (BnN), BN_dup (BnE), BN_dup (BnD)) == 0) {
184 if ((BnP ==
NULL) || (BnQ ==
NULL)) {
190 BnP = BN_bin2bn (BigNumber, (UINT32)BnSize, BnP);
193 BnQ = BN_bin2bn (BigNumber, (UINT32)BnSize, BnQ);
199 if (RSA_set0_factors (RsaKey, BN_dup (BnP), BN_dup (BnQ)) == 0) {
220 if (BnQInv ==
NULL) {
224 if ((BnDp ==
NULL) || (BnDq ==
NULL) || (BnQInv ==
NULL)) {
230 BnDp = BN_bin2bn (BigNumber, (UINT32)BnSize, BnDp);
233 BnDq = BN_bin2bn (BigNumber, (UINT32)BnSize, BnDq);
236 BnQInv = BN_bin2bn (BigNumber, (UINT32)BnSize, BnQInv);
242 if (RSA_set0_crt_params (RsaKey, BN_dup (BnDp), BN_dup (BnDq), BN_dup (BnQInv)) == 0) {
290 if ((RsaContext ==
NULL) || (MessageHash ==
NULL) || (Signature ==
NULL)) {
294 if ((SigSize > INT_MAX) || (SigSize == 0)) {
304 DigestType = NID_md5;
308 DigestType = NID_sha1;
312 DigestType = NID_sha256;
316 DigestType = NID_sha384;
320 DigestType = NID_sha512;
327 SigBuf = (UINT8 *)Signature;
328 return (BOOLEAN)RSA_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 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)