[Ttssh2-commit] [6562] HMAC_CTX 構造体をポインタ化した。

svnno****@sourc***** svnno****@sourc*****
2017年 1月 7日 (土) 19:41:31 JST


Revision: 6562
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6562
Author:   yutakapon
Date:     2017-01-07 19:41:31 +0900 (Sat, 07 Jan 2017)
Log Message:
-----------
HMAC_CTX 構造体をポインタ化した。
HMAC_cleanup()の呼び出しを削除した。

Modified Paths:
--------------
    branches/openssl_1_1_0/ttssh2/ttxssh/crypt.c

-------------- next part --------------
Modified: branches/openssl_1_1_0/ttssh2/ttxssh/crypt.c
===================================================================
--- branches/openssl_1_1_0/ttssh2/ttxssh/crypt.c	2017-01-06 15:03:57 UTC (rev 6561)
+++ branches/openssl_1_1_0/ttssh2/ttxssh/crypt.c	2017-01-07 10:41:31 UTC (rev 6562)
@@ -1040,7 +1040,7 @@
 BOOL CRYPT_verify_receiver_MAC(PTInstVar pvar, uint32 sequence_number,
 	char FAR * data, int len, char FAR * MAC)
 {
-	HMAC_CTX c;
+	HMAC_CTX *c = NULL;
 	unsigned char m[EVP_MAX_MD_SIZE];
 	unsigned char b[4];
 	struct Mac *mac;
@@ -1062,12 +1062,16 @@
 		goto error;
 	}
 
-	HMAC_Init(&c, mac->key, mac->key_len, mac->md);
+	c = HMAC_CTX_new();
+	if (c == NULL)
+		goto error;
+
+	HMAC_Init(c, mac->key, mac->key_len, mac->md);
 	set_uint32_MSBfirst(b, sequence_number);
-	HMAC_Update(&c, b, sizeof(b));
-	HMAC_Update(&c, data, len);
-	HMAC_Final(&c, m, NULL);
-	HMAC_cleanup(&c);
+	HMAC_Update(c, b, sizeof(b));
+	HMAC_Update(c, data, len);
+	HMAC_Final(c, m, NULL);
+	//HMAC_cleanup()\x82\xCDOpenSSL 1.1.0\x82ō폜\x82\xB3\x82ꂽ\x81B
 
 	if (memcmp(m, MAC, mac->mac_len)) {
 		logprintf(pvar, LOG_LEVEL_VERBOSE, "HMAC key is not matched(seq %lu len %d)", sequence_number, len);
@@ -1076,9 +1080,14 @@
 		goto error;
 	}
 
+	HMAC_CTX_free(c);
+
 	return TRUE;
 
 error:
+	if (c) 
+		HMAC_CTX_free(c);
+
 	return FALSE;
 }
 
@@ -1101,7 +1110,7 @@
 BOOL CRYPT_build_sender_MAC(PTInstVar pvar, uint32 sequence_number,
                             char FAR * data, int len, char FAR * MAC)
 {
-	HMAC_CTX c;
+	HMAC_CTX *c = NULL;
 	static u_char m[EVP_MAX_MD_SIZE];
 	u_char b[4];
 	struct Mac *mac;
@@ -1111,17 +1120,23 @@
 		if (mac == NULL || mac->enabled == 0) 
 			return FALSE;
 
-		HMAC_Init(&c, mac->key, mac->key_len, mac->md);
+		c = HMAC_CTX_new();
+		if (c == NULL)
+			return FALSE;
+
+		HMAC_Init(c, mac->key, mac->key_len, mac->md);
 		set_uint32_MSBfirst(b, sequence_number);
-		HMAC_Update(&c, b, sizeof(b));
-		HMAC_Update(&c, data, len);
-		HMAC_Final(&c, m, NULL);
-		HMAC_cleanup(&c);
+		HMAC_Update(c, b, sizeof(b));
+		HMAC_Update(c, data, len);
+		HMAC_Final(c, m, NULL);
+		//HMAC_cleanup()\x82\xCDOpenSSL 1.1.0\x82ō폜\x82\xB3\x82ꂽ\x81B
 
 		// 20\x83o\x83C\x83g\x95\xAA\x82\xBE\x82\xAF\x83R\x83s\x81[
 		memcpy(MAC, m, pvar->ssh2_keys[MODE_OUT].mac.mac_len);
 	//	memcpy(MAC, m, sizeof(m));
 
+		HMAC_CTX_free(c);
+
 		return TRUE;
 	}
 



Ttssh2-commit メーリングリストの案内