15#include "InternalCryptLib.h"
17#include <openssl/bn.h>
18#include <openssl/rsa.h>
19#include <openssl/err.h>
20#include <openssl/objects.h>
51 IN OUT VOID *RsaContext,
64 if ((RsaContext ==
NULL) || (BnSize ==
NULL)) {
68 RsaKey = (RSA *)RsaContext;
78 RSA_get0_key (RsaKey, (
const BIGNUM **)&BnKey,
NULL,
NULL);
85 RSA_get0_key (RsaKey,
NULL, (
const BIGNUM **)&BnKey,
NULL);
92 RSA_get0_key (RsaKey,
NULL,
NULL, (
const BIGNUM **)&BnKey);
99 RSA_get0_factors (RsaKey, (
const BIGNUM **)&BnKey,
NULL);
106 RSA_get0_factors (RsaKey,
NULL, (
const BIGNUM **)&BnKey);
113 RSA_get0_crt_params (RsaKey, (
const BIGNUM **)&BnKey,
NULL,
NULL);
120 RSA_get0_crt_params (RsaKey,
NULL, (
const BIGNUM **)&BnKey,
NULL);
127 RSA_get0_crt_params (RsaKey,
NULL,
NULL, (
const BIGNUM **)&BnKey);
139 Size = BN_num_bytes (BnKey);
141 if (*BnSize < Size) {
146 if (BigNumber ==
NULL) {
151 *BnSize = BN_bn2bin (BnKey, BigNumber);
180 IN OUT VOID *RsaContext,
182 IN CONST UINT8 *PublicExponent,
192 if ((RsaContext ==
NULL) || (ModulusLength > INT_MAX) || (PublicExponentSize > INT_MAX)) {
203 if (PublicExponent ==
NULL) {
204 if (BN_set_word (KeyE, 0x10001) == 0) {
208 if (BN_bin2bn (PublicExponent, (UINT32)PublicExponentSize, KeyE) ==
NULL) {
213 if (RSA_generate_key_ex ((RSA *)RsaContext, (UINT32)ModulusLength, KeyE,
NULL) == 1) {
252 if (RsaContext ==
NULL) {
256 if (RSA_check_key ((RSA *)RsaContext) != 1) {
257 Reason = ERR_GET_REASON (ERR_peek_last_error ());
258 if ((Reason == RSA_R_P_NOT_PRIME) ||
259 (Reason == RSA_R_Q_NOT_PRIME) ||
260 (Reason == RSA_R_N_DOES_NOT_EQUAL_P_Q) ||
261 (Reason == RSA_R_D_E_NOT_CONGRUENT_TO_1))
301 OUT UINT8 *Signature,
312 if ((RsaContext ==
NULL) || (MessageHash ==
NULL)) {
316 Rsa = (RSA *)RsaContext;
317 Size = RSA_size (Rsa);
319 if (*SigSize < Size) {
324 if (Signature ==
NULL) {
334 DigestType = NID_md5;
338 DigestType = NID_sha1;
342 DigestType = NID_sha256;
346 DigestType = NID_sha384;
350 DigestType = NID_sha512;
357 return (BOOLEAN)RSA_sign (
@ 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
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)