1 Star 0 Fork 81

fuowang/openjdk-1.8.0

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
add-kaeEngine-to-rsa.patch 4.49 KB
一键复制 编辑 原始数据 按行查看 历史
Noah 提交于 2021-05-19 09:44 . I3RX5F: Add kaeEngine to rsa
commit ab97dd8f89c5a3ce17b9d90bc8ae2e407c450012
Author: Noah <hedongbo@huawei.com>
Date: Wed May 19 09:38:34 2021 +0800
I3RWVC: Add kaeEngine to rsa
diff --git a/jdk/src/solaris/native/org/openeuler/security/openssl/kae_cipher_rsa.c b/jdk/src/solaris/native/org/openeuler/security/openssl/kae_cipher_rsa.c
index 3fbacf77..cbab7bdb 100644
--- a/jdk/src/solaris/native/org/openeuler/security/openssl/kae_cipher_rsa.c
+++ b/jdk/src/solaris/native/org/openeuler/security/openssl/kae_cipher_rsa.c
@@ -28,6 +28,8 @@
#include "kae_exception.h"
#include "org_openeuler_security_openssl_KAERSACipher.h"
+static ENGINE* kaeEngine = NULL;
+
typedef int RSACryptOperation(int, const unsigned char*, unsigned char*, RSA*, int);
typedef int EvpPkeyCryptOperation(EVP_PKEY_CTX*, unsigned char*, size_t*, const unsigned char*, size_t);
@@ -171,12 +173,13 @@ static int RSACryptOAEPPadding(JNIEnv* env, jlong keyAddress, jint inLen, jbyteA
// outLen type should be size_t
// EVP_PKEY_encrypt takes the outLen address as a parameter, and the parameter type is size_t*
size_t outLen = 0;
+ kaeEngine = (kaeEngine == NULL) ? GetKaeEngine() : kaeEngine;
EVP_PKEY* pkey = (EVP_PKEY*) keyAddress;
// new ctx
// rsa encrypt/decrypt init
- if ((pkeyCtx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL || cryptInitOperation(pkeyCtx) <= 0) {
+ if ((pkeyCtx = EVP_PKEY_CTX_new(pkey, kaeEngine)) == NULL || cryptInitOperation(pkeyCtx) <= 0) {
KAE_ThrowFromOpenssl(env, pkeyCtx == NULL ? "EVP_PKEY_CTX_new" : cryptInitName, KAE_ThrowInvalidKeyException);
goto cleanup;
}
@@ -192,8 +195,7 @@ static int RSACryptOAEPPadding(JNIEnv* env, jlong keyAddress, jint inLen, jbyteA
* set rsa mgf1 md
* set rsa oaep md
*/
- if(!SetRSAPadding(env, pkeyCtx, paddingType) ||
- !SetRSAMgf1Md(env, pkeyCtx, mgf1MdAlgoUTF) ||
+ if(!SetRSAPadding(env, pkeyCtx, paddingType) || !SetRSAMgf1Md(env, pkeyCtx, mgf1MdAlgoUTF) ||
!SetRSAOaepMd(env, pkeyCtx, oaepMdAlgoUTF)) {
goto cleanup;
}
@@ -267,6 +269,7 @@ JNIEXPORT jlong JNICALL Java_org_openeuler_security_openssl_KAERSACipher_nativeC
BIGNUM* bnIQMP = NULL;
RSA* rsa = NULL;
EVP_PKEY* pkey = NULL;
+ kaeEngine = (kaeEngine == NULL) ? GetKaeEngine() : kaeEngine;
// convert to big num
if ((bnN = KAE_GetBigNumFromByteArray(env, n)) == NULL ||
@@ -288,9 +291,9 @@ JNIEXPORT jlong JNICALL Java_org_openeuler_security_openssl_KAERSACipher_nativeC
}
// new rsa
- rsa = RSA_new();
+ rsa = RSA_new_method(kaeEngine);
if (rsa == NULL) {
- KAE_ThrowFromOpenssl(env, "RSA_new", KAE_ThrowRuntimeException);
+ KAE_ThrowFromOpenssl(env, "RSA_new_method", KAE_ThrowRuntimeException);
goto cleanup;
}
@@ -328,6 +331,7 @@ JNIEXPORT jlong JNICALL Java_org_openeuler_security_openssl_KAERSACipher_nativeC
BIGNUM* bnE = NULL;
RSA* rsa = NULL;
EVP_PKEY* pkey = NULL;
+ kaeEngine = (kaeEngine == NULL) ? GetKaeEngine() : kaeEngine;
// get public key param n
bnN = KAE_GetBigNumFromByteArray(env, n);
@@ -341,10 +345,10 @@ JNIEXPORT jlong JNICALL Java_org_openeuler_security_openssl_KAERSACipher_nativeC
goto cleanup;
}
- // new RSA
- rsa = RSA_new();
+ // new rsa
+ rsa = RSA_new_method(kaeEngine);
if (rsa == NULL) {
- KAE_ThrowFromOpenssl(env, "RSA_new", KAE_ThrowRuntimeException);
+ KAE_ThrowFromOpenssl(env, "RSA_new_method", KAE_ThrowRuntimeException);
goto cleanup;
}
diff --git a/jdk/src/solaris/native/org/openeuler/security/openssl/kae_keypairgenerator_rsa.c b/jdk/src/solaris/native/org/openeuler/security/openssl/kae_keypairgenerator_rsa.c
index ddbc2958..de724593 100644
--- a/jdk/src/solaris/native/org/openeuler/security/openssl/kae_keypairgenerator_rsa.c
+++ b/jdk/src/solaris/native/org/openeuler/security/openssl/kae_keypairgenerator_rsa.c
@@ -65,10 +65,12 @@ static const BIGNUM* (* GetRSAParamFunctionList[])(const RSA*) = {
* step 3.Generate rsa key, and all key information is stored in RSA
*/
static RSA* NewRSA(JNIEnv* env, jint keySize, jbyteArray publicExponent) {
- // RSA_new
- RSA* rsa = RSA_new();
+ static ENGINE* kaeEngine = NULL;
+ kaeEngine = (kaeEngine == NULL) ? GetKaeEngine() : kaeEngine;
+ // new rsa
+ RSA* rsa = RSA_new_method(kaeEngine);
if (rsa == NULL) {
- KAE_ThrowFromOpenssl(env, "RSA_new", KAE_ThrowRuntimeException);
+ KAE_ThrowFromOpenssl(env, "RSA_new_method", KAE_ThrowRuntimeException);
return NULL;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fuowang/openjdk-1.8.0.git
git@gitee.com:fuowang/openjdk-1.8.0.git
fuowang
openjdk-1.8.0
openjdk-1.8.0
master

搜索帮助