Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Fix _plaintext is too small, and fix dependency in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoneChen authored and syan10 committed Jun 7, 2023
1 parent 190b9a5 commit 7a54667
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions core/Enclave/self_test/rsa_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,17 @@ static bool rsa_decryption_with_pkcs_oaep(map<string, string> test_vector)
BN_bin2bn(&*dmq1, VECTOR_LENGTH("dmq1"), NULL),
BN_bin2bn(&*iqmp, VECTOR_LENGTH("iqmp"), NULL));

uint8_t _plaintext[VECTOR_LENGTH("plaintext")] = {0};
int rsa_size = RSA_size(key);
if (rsa_size <= 42) {
RSA_free(key);
return false;
}
uint32_t plaintext_len =
std::max(VECTOR_LENGTH("plaintext"), (uint32_t)rsa_size - 42);
uint8_t _plaintext[plaintext_len];
memset(_plaintext, 0, plaintext_len);

RSA_private_decrypt(RSA_size(key), &*ciphertext, _plaintext, key, 4);
RSA_private_decrypt(rsa_size, &*ciphertext, _plaintext, key, 4);

RSA_free(key);

Expand Down
6 changes: 4 additions & 2 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,17 @@ $(App_Test_Name): $(App_Cpp_Objects) $(App_Test_Cpp_Objects) App/enclave_hsm_u.o

######## Enclave Objects ########

Enclave/enclave_hsm_t.c: $(SGX_EDGER8R) Enclave/enclave_hsm.edl
Enclave/enclave_hsm_t.h: $(SGX_EDGER8R) Enclave/enclave_hsm.edl
@cd Enclave && $(SGX_EDGER8R) --trusted ../Enclave/enclave_hsm.edl --search-path ../Enclave --search-path ../Enclave/self_test --search-path $(SGX_SDK)/include --search-path $(OPENSSL_PATH)/include
@echo "GEN => $@"

Enclave/enclave_hsm_t.c: Enclave/enclave_hsm_t.h

Enclave/enclave_hsm_t.o: Enclave/enclave_hsm_t.c
@$(CXX) $(Enclave_C_Flags) -c $< -o $@
@echo "CXX <= $<"

Enclave/%.o: Enclave/%.cpp
Enclave/%.o: Enclave/%.cpp Enclave/enclave_hsm_t.h
@$(CXX) $(Enclave_Cpp_Flags) -c $< -o $@
@echo "CXX <= $<"

Expand Down
2 changes: 1 addition & 1 deletion dkeyserver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ App/enclave_u.o: App/enclave_u.c
@$(CXX) $(SGX_COMMON_CFLAGS) $(App_C_Flags) -c $< -o $@
@echo "CXX <= $<"

App/%.o: App/%.cpp App/auto_version.h
App/%.o: App/%.cpp App/auto_version.h App/enclave_u.h
@$(CXX) $(SGX_COMMON_CXXFLAGS) $(App_Cpp_Flags) -c $< -o $@
@echo "CXX <= $<"

Expand Down

0 comments on commit 7a54667

Please sign in to comment.