IN OUT UINTN *BnSize\r
)\r
{\r
- RSA *RsaKey;\r
- BIGNUM *BnKey;\r
- UINTN Size;\r
+ RSA *RsaKey;\r
+ BIGNUM *BnKey;\r
+ UINTN Size;\r
\r
//\r
// Check input parameters.\r
//\r
- if (RsaContext == NULL || BnSize == NULL) {\r
+ if ((RsaContext == NULL) || (BnSize == NULL)) {\r
return FALSE;\r
}\r
\r
- RsaKey = (RSA *) RsaContext;\r
+ RsaKey = (RSA *)RsaContext;\r
Size = *BnSize;\r
*BnSize = 0;\r
BnKey = NULL;\r
\r
switch (KeyTag) {\r
-\r
- //\r
- // RSA Public Modulus (N)\r
- //\r
- case RsaKeyN:\r
- RSA_get0_key (RsaKey, (const BIGNUM **)&BnKey, NULL, NULL);\r
- break;\r
-\r
- //\r
- // RSA Public Exponent (e)\r
- //\r
- case RsaKeyE:\r
- RSA_get0_key (RsaKey, NULL, (const BIGNUM **)&BnKey, NULL);\r
- break;\r
-\r
- //\r
- // RSA Private Exponent (d)\r
- //\r
- case RsaKeyD:\r
- RSA_get0_key (RsaKey, NULL, NULL, (const BIGNUM **)&BnKey);\r
- break;\r
-\r
- //\r
- // RSA Secret Prime Factor of Modulus (p)\r
- //\r
- case RsaKeyP:\r
- RSA_get0_factors (RsaKey, (const BIGNUM **)&BnKey, NULL);\r
- break;\r
-\r
- //\r
- // RSA Secret Prime Factor of Modules (q)\r
- //\r
- case RsaKeyQ:\r
- RSA_get0_factors (RsaKey, NULL, (const BIGNUM **)&BnKey);\r
- break;\r
-\r
- //\r
- // p's CRT Exponent (== d mod (p - 1))\r
- //\r
- case RsaKeyDp:\r
- RSA_get0_crt_params (RsaKey, (const BIGNUM **)&BnKey, NULL, NULL);\r
- break;\r
-\r
- //\r
- // q's CRT Exponent (== d mod (q - 1))\r
- //\r
- case RsaKeyDq:\r
- RSA_get0_crt_params (RsaKey, NULL, (const BIGNUM **)&BnKey, NULL);\r
- break;\r
-\r
- //\r
- // The CRT Coefficient (== 1/q mod p)\r
- //\r
- case RsaKeyQInv:\r
- RSA_get0_crt_params (RsaKey, NULL, NULL, (const BIGNUM **)&BnKey);\r
- break;\r
-\r
- default:\r
- return FALSE;\r
+ //\r
+ // RSA Public Modulus (N)\r
+ //\r
+ case RsaKeyN:\r
+ RSA_get0_key (RsaKey, (const BIGNUM **)&BnKey, NULL, NULL);\r
+ break;\r
+\r
+ //\r
+ // RSA Public Exponent (e)\r
+ //\r
+ case RsaKeyE:\r
+ RSA_get0_key (RsaKey, NULL, (const BIGNUM **)&BnKey, NULL);\r
+ break;\r
+\r
+ //\r
+ // RSA Private Exponent (d)\r
+ //\r
+ case RsaKeyD:\r
+ RSA_get0_key (RsaKey, NULL, NULL, (const BIGNUM **)&BnKey);\r
+ break;\r
+\r
+ //\r
+ // RSA Secret Prime Factor of Modulus (p)\r
+ //\r
+ case RsaKeyP:\r
+ RSA_get0_factors (RsaKey, (const BIGNUM **)&BnKey, NULL);\r
+ break;\r
+\r
+ //\r
+ // RSA Secret Prime Factor of Modules (q)\r
+ //\r
+ case RsaKeyQ:\r
+ RSA_get0_factors (RsaKey, NULL, (const BIGNUM **)&BnKey);\r
+ break;\r
+\r
+ //\r
+ // p's CRT Exponent (== d mod (p - 1))\r
+ //\r
+ case RsaKeyDp:\r
+ RSA_get0_crt_params (RsaKey, (const BIGNUM **)&BnKey, NULL, NULL);\r
+ break;\r
+\r
+ //\r
+ // q's CRT Exponent (== d mod (q - 1))\r
+ //\r
+ case RsaKeyDq:\r
+ RSA_get0_crt_params (RsaKey, NULL, (const BIGNUM **)&BnKey, NULL);\r
+ break;\r
+\r
+ //\r
+ // The CRT Coefficient (== 1/q mod p)\r
+ //\r
+ case RsaKeyQInv:\r
+ RSA_get0_crt_params (RsaKey, NULL, NULL, (const BIGNUM **)&BnKey);\r
+ break;\r
+\r
+ default:\r
+ return FALSE;\r
}\r
\r
if (BnKey == NULL) {\r
*BnSize = Size;\r
return TRUE;\r
}\r
- *BnSize = BN_bn2bin (BnKey, BigNumber) ;\r
+\r
+ *BnSize = BN_bn2bin (BnKey, BigNumber);\r
\r
return TRUE;\r
}\r
//\r
// Check input parameters.\r
//\r
- if (RsaContext == NULL || ModulusLength > INT_MAX || PublicExponentSize > INT_MAX) {\r
+ if ((RsaContext == NULL) || (ModulusLength > INT_MAX) || (PublicExponentSize > INT_MAX)) {\r
return FALSE;\r
}\r
\r
goto _Exit;\r
}\r
} else {\r
- if (BN_bin2bn (PublicExponent, (UINT32) PublicExponentSize, KeyE) == NULL) {\r
+ if (BN_bin2bn (PublicExponent, (UINT32)PublicExponentSize, KeyE) == NULL) {\r
goto _Exit;\r
}\r
}\r
\r
- if (RSA_generate_key_ex ((RSA *) RsaContext, (UINT32) ModulusLength, KeyE, NULL) == 1) {\r
- RetVal = TRUE;\r
+ if (RSA_generate_key_ex ((RSA *)RsaContext, (UINT32)ModulusLength, KeyE, NULL) == 1) {\r
+ RetVal = TRUE;\r
}\r
\r
_Exit:\r
return FALSE;\r
}\r
\r
- if (RSA_check_key ((RSA *) RsaContext) != 1) {\r
+ if (RSA_check_key ((RSA *)RsaContext) != 1) {\r
Reason = ERR_GET_REASON (ERR_peek_last_error ());\r
- if (Reason == RSA_R_P_NOT_PRIME ||\r
- Reason == RSA_R_Q_NOT_PRIME ||\r
- Reason == RSA_R_N_DOES_NOT_EQUAL_P_Q ||\r
- Reason == RSA_R_D_E_NOT_CONGRUENT_TO_1) {\r
+ if ((Reason == RSA_R_P_NOT_PRIME) ||\r
+ (Reason == RSA_R_Q_NOT_PRIME) ||\r
+ (Reason == RSA_R_N_DOES_NOT_EQUAL_P_Q) ||\r
+ (Reason == RSA_R_D_E_NOT_CONGRUENT_TO_1))\r
+ {\r
return FALSE;\r
}\r
}\r
IN OUT UINTN *SigSize\r
)\r
{\r
- RSA *Rsa;\r
- UINTN Size;\r
- INT32 DigestType;\r
+ RSA *Rsa;\r
+ UINTN Size;\r
+ INT32 DigestType;\r
\r
//\r
// Check input parameters.\r
//\r
- if (RsaContext == NULL || MessageHash == NULL) {\r
+ if ((RsaContext == NULL) || (MessageHash == NULL)) {\r
return FALSE;\r
}\r
\r
- Rsa = (RSA *) RsaContext;\r
+ Rsa = (RSA *)RsaContext;\r
Size = RSA_size (Rsa);\r
\r
if (*SigSize < Size) {\r
// Only MD5, SHA-1, SHA-256, SHA-384 or SHA-512 algorithm is supported.\r
//\r
switch (HashSize) {\r
- case MD5_DIGEST_SIZE:\r
- DigestType = NID_md5;\r
- break;\r
+ case MD5_DIGEST_SIZE:\r
+ DigestType = NID_md5;\r
+ break;\r
\r
- case SHA1_DIGEST_SIZE:\r
- DigestType = NID_sha1;\r
- break;\r
+ case SHA1_DIGEST_SIZE:\r
+ DigestType = NID_sha1;\r
+ break;\r
\r
- case SHA256_DIGEST_SIZE:\r
- DigestType = NID_sha256;\r
- break;\r
+ case SHA256_DIGEST_SIZE:\r
+ DigestType = NID_sha256;\r
+ break;\r
\r
- case SHA384_DIGEST_SIZE:\r
- DigestType = NID_sha384;\r
- break;\r
+ case SHA384_DIGEST_SIZE:\r
+ DigestType = NID_sha384;\r
+ break;\r
\r
- case SHA512_DIGEST_SIZE:\r
- DigestType = NID_sha512;\r
- break;\r
+ case SHA512_DIGEST_SIZE:\r
+ DigestType = NID_sha512;\r
+ break;\r
\r
- default:\r
- return FALSE;\r
+ default:\r
+ return FALSE;\r
}\r
\r
- return (BOOLEAN) RSA_sign (\r
- DigestType,\r
- MessageHash,\r
- (UINT32) HashSize,\r
- Signature,\r
- (UINT32 *) SigSize,\r
- (RSA *) RsaContext\r
- );\r
+ return (BOOLEAN)RSA_sign (\r
+ DigestType,\r
+ MessageHash,\r
+ (UINT32)HashSize,\r
+ Signature,\r
+ (UINT32 *)SigSize,\r
+ (RSA *)RsaContext\r
+ );\r
}\r