Browse Source

Replaced references to an outdated openssl function.
Code now links against the default openssl setup on the test machine.
(This fn. could not be found in the current openssl library headers on the test machine.)

dettanym 4 years ago
parent
commit
ce0aa7252a
2 changed files with 8 additions and 34 deletions
  1. 2 13
      Makefile
  2. 6 21
      crypto.cpp

+ 2 - 13
Makefile

@@ -6,7 +6,6 @@ LD_FLAGS        = -Wall -shared -Wl,--no-undefined
 
 OBJECTS := systemMain.o MainLogic.o PostLA/PostLAMessaging.o LAInitiator/LA.o LAInitiator/Tramsforms.o ProtobufMessageRW.o  ProtobufLAMessages.pb.o crypto.o
 
-#SGX_SDK := /home/m2mazmud/sgx2.1_installation/sgxsdk
 SGX_SDK := /opt/intel/sgxsdk
 SGX_COMMON_CFLAGS := -m64
 SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
@@ -14,7 +13,6 @@ Trts_Library_Name := sgx_trts
 Service_Library_Name := sgx_tservice
 Crypto_Library_Name := sgx_tcrypto
 SGX_INCLUDE_PATHS := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/libcxx
-Openssl_Path := /home/m2mazmud/plain-openssl
 
 Uae_Library_Name := sgx_uae_service
 
@@ -45,17 +43,8 @@ ProtobufMessageRW.o: ProtobufMessageRW.cpp
 	g++ -I./include ${CXX_FLAGS} -c $^ -o $@
 
 crypto.o: crypto.cpp 
-	g++ -I${Openssl_Path}/include ${CXX_FLAGS} -c $^ -o $@
+	g++ ${CXX_FLAGS} -c $^ -o $@
 
 localattestation_decryption.so: systemMain.o MainLogic.o LAInitiator/LA.o LAInitiator/Tramsforms.o  ProtobufLAMessages.pb.o PostLA/PostLAMessaging.o PostLA/PostLAMessages.pb.o ProtobufMessageRW.o crypto.o
-#systemMain.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o PostLAMessages.pb.o crypto.o
-	${CXX} ${LD_FLAGS} systemMain.o MainLogic.o LAInitiator/LA.o LAInitiator/Tramsforms.o  ProtobufLAMessages.pb.o PostLA/PostLAMessaging.o PostLA/PostLAMessages.pb.o ProtobufMessageRW.o crypto.o  -lphpcpp -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc -lprotobuf -Wl,--rpath /home/m2mazmud/plain-openssl/lib    -L${Openssl_Path}/lib -lssl -lcrypto   -Wl,-Bsymbolic -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  -o $@
-#ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o 
-# -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc -lprotobuf -Wl,--rpath /home/m2mazmud/plain-openssl/lib   -L${Openssl_Path}/lib -lssl -lcrypto  -Wl,-Bsymbolic -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  -Wl,--verbose -lphpcpp -lprotobuf  -o $@
-#ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o 
-# -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc 
-# -lprotobuf
-# -L${Openssl_Path}/lib -lssl -lcrypto  
-# -lphpcpp 
+	${CXX} ${LD_FLAGS} -Wl,--verbose systemMain.o MainLogic.o LAInitiator/LA.o LAInitiator/Tramsforms.o  ProtobufLAMessages.pb.o PostLA/PostLAMessaging.o PostLA/PostLAMessages.pb.o ProtobufMessageRW.o crypto.o  -lphpcpp -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc -lprotobuf -lssl -lcrypto   -Wl,-Bsymbolic -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  -o $@
 # -Wl,-Bsymbolic -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  -Wl,--verbose -o $@
-#-Wl,--rpath /home/m2mazmud/plain-openssl/lib -o $@

+ 6 - 21
crypto.cpp

@@ -58,7 +58,6 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
 {
 	int len;
 	int ciphertext_len;
-	int reset_return;
 	if(ctx == NULL)
 	{
 		/* Create and initialise the context */
@@ -68,10 +67,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
 	/* Initialise the encryption operation. */
 	if(1 != EVP_CipherInit_ex(ctx, EVP_aes_128_gcm(), NULL, key, iv, enc))
 	{
-		reset_return = EVP_CIPHER_CTX_reset(ctx);
+		EVP_CIPHER_CTX_init(ctx);
 		ERR_print_errors_fp(stderr);
-		if(reset_return != 1)
-			return 0xf2;
 		return 0x2;
 	}
 	/* Provide the message to be encrypted, and obtain the encrypted output.
@@ -79,10 +76,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
 	 */
 	if(1 != EVP_CipherUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
 	{
-                reset_return = EVP_CIPHER_CTX_reset(ctx);
+                EVP_CIPHER_CTX_init(ctx);
                 ERR_print_errors_fp(stderr);
-	        if(1 != reset_return)
-			return 0xF3;
 		return 0x3;
 	}
 	ciphertext_len = len;
@@ -91,10 +86,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
         {
                 if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag))
                 {
-                       reset_return = EVP_CIPHER_CTX_reset(ctx);
+                       EVP_CIPHER_CTX_init(ctx);
                        ERR_print_errors_fp(stderr); fflush(stderr);
-                       if(1 != reset_return)
-                                return 0xF5;
                         return 0x5;
                 }
         }
@@ -106,10 +99,8 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
 	// TODO: ^^^ Why the heck does it not occur in GCM mode ?
 	if(1 != EVP_CipherFinal_ex(ctx, ciphertext + len, &len))
 	{
-		reset_return = EVP_CIPHER_CTX_reset(ctx);
+		EVP_CIPHER_CTX_init(ctx);
 		ERR_print_errors_fp(stderr); fflush(stderr);
-                if(1 != reset_return)
-                        return 0xF4;
                 return 0x4;
 	}
 	ciphertext_len += len;
@@ -119,20 +110,14 @@ int aes_gcm_128(int enc, unsigned char *key, unsigned char *iv, unsigned char* p
 	{
 		if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag))
 		{
-                	reset_return = EVP_CIPHER_CTX_reset(ctx);
+                	EVP_CIPHER_CTX_init(ctx);
                 	ERR_print_errors_fp(stderr); fflush(stderr);
-                	if(1 != reset_return)
-                        	return 0xF5;
 	                return 0x5;
 		}
 	}
 
 	/* Clean up */
-	if(1 != EVP_CIPHER_CTX_reset(ctx))
-	{
-		ERR_print_errors_fp(stderr); fflush(stderr);
-		return 0xF0;
-	}
+	EVP_CIPHER_CTX_init(ctx);
 
 	*op_ciphertext_len=ciphertext_len;
 	return 0;