Fix for 625439 - Don't call OpenSSL_add_all_algorithms() 1.1.x
authorstefan
Mon, 31 Jan 2011 11:51:56 -0500
branch1.1.x
changeset 386 ec7c68e670f34003deeb02000e0cd67270ee710e
parent 385 49d8193e96c7d683e26284e63f532391795250d8
child 387 87c7b996bb20278c915e3906788f021f89dd4701
push id216
push userstefan@arentz.ca
push dateMon, 31 Jan 2011 16:52:03 +0000
bugs625439
Fix for 625439 - Don't call OpenSSL_add_all_algorithms()
ExternalSources/ios-jpake/Sources/JPAKEParty.m
Sources/Utilities/NSData+SHA.m
Sources/Utilities/NSString+SHA.m
--- a/ExternalSources/ios-jpake/Sources/JPAKEParty.m
+++ b/ExternalSources/ios-jpake/Sources/JPAKEParty.m
@@ -32,16 +32,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <openssl/evp.h>
+#include <openssl/sha.h>
 #include <openssl/hmac.h>
 #import "JPAKEParty.h"
 
 /**
  * Convert an OpenSSL BIGNUM to a Cocoa NSString in hex form. The resulting string is
  * lowercase hex without 0x in front.
  */
 
@@ -99,21 +100,16 @@ static BIGNUM* HashPassword(NSString* pa
 			BN_bin2bn([passwordData bytes], [passwordData length], secret);
 		}
 	}
 	return secret;
 }
 
 @implementation JPAKEParty
 
-+ (void) initialize
-{
-	OpenSSL_add_all_digests(); // Is it ok if this gets called multiple times?
-}
-
 + (id) partyWithPassword: (NSString*) password modulusLength: (NSUInteger) modulusLength signerIdentity: (NSString*) signerIdentity peerIdentity: (NSString*) peerIdentity
 {
 	return [[[self alloc] initWithPassword: password modulusLength: modulusLength signerIdentity: signerIdentity peerIdentity: peerIdentity] autorelease];
 }
 
 - (id) initWithPassword: (NSString*) password modulusLength: (NSUInteger) modulusLength signerIdentity: (NSString*) signerIdentity peerIdentity: (NSString*) peerIdentity
 {
 	if ((self = [super init]) != nil)
@@ -280,17 +276,17 @@ static BIGNUM* HashPassword(NSString* pa
 	if (JPAKE_STEP2_process(_ctx, &step2))
 	{
 		const BIGNUM* key = JPAKE_get_shared_key(_ctx);
 		if (key != nil)
 		{
 			NSData* keyData = BIGNUM2NSData(key);
 			if (keyData != nil)
 			{
-				const EVP_MD* md = EVP_get_digestbyname("SHA256");
+				const EVP_MD* md = EVP_sha256();
 				if (md != NULL)
 				{
 					unsigned char hmac_value[EVP_MAX_MD_SIZE];
 					unsigned int hmac_length;
 					
 					unsigned char extraction_key[32];
 					memset(extraction_key, 0x00, sizeof extraction_key);
 				
--- a/Sources/Utilities/NSData+SHA.m
+++ b/Sources/Utilities/NSData+SHA.m
@@ -39,26 +39,21 @@
 #include <openssl/evp.h>
 #include <openssl/sha.h>
 #include <openssl/hmac.h>
 
 #import "NSData+SHA.h"
 
 @implementation NSData (SHA)
 
-+ (void) initialize
-{
-	OpenSSL_add_all_digests(); // Is it ok if this gets called multiple times?
-}
-
 - (NSData*) SHA160Hash
 {
 	NSData* result = nil;
 
-	const EVP_MD* md = EVP_get_digestbyname("SHA1");
+	const EVP_MD* md = EVP_sha1();
 	if (md != NULL)
 	{
 		unsigned char md_value[EVP_MAX_MD_SIZE];
 		unsigned int md_len;	
 		EVP_MD_CTX mdctx;
 
 		EVP_MD_CTX_init(&mdctx);
 		EVP_DigestInit_ex(&mdctx, md, NULL);
@@ -71,17 +66,17 @@
 	
 	return result;
 }
 
 - (NSData*) SHA256Hash
 {
 	NSData* result = nil;
 
-	const EVP_MD* md = EVP_get_digestbyname("SHA256");
+	const EVP_MD* md = EVP_sha256();
 	if (md != NULL)
 	{
 		unsigned char md_value[EVP_MAX_MD_SIZE];
 		unsigned int md_len;	
 		EVP_MD_CTX mdctx;
 
 		EVP_MD_CTX_init(&mdctx);
 		EVP_DigestInit_ex(&mdctx, md, NULL);
@@ -94,17 +89,17 @@
 	
 	return result;
 }
 
 - (NSData*) HMACSHA256WithKey: (NSData*) key
 {
 	NSData* result = nil;
 
-	const EVP_MD* evp_md = EVP_get_digestbyname("SHA256");
+	const EVP_MD* evp_md = EVP_sha256();
 	if (evp_md != NULL)
 	{
 		unsigned char hmac_value[EVP_MAX_MD_SIZE];
 		unsigned int hmac_length;
 	
 		if (HMAC(evp_md, [key bytes], [key length], [self bytes], [self length], hmac_value, &hmac_length) != NULL) {
 			result = [NSData dataWithBytes: hmac_value length: hmac_length];
 		}
--- a/Sources/Utilities/NSString+SHA.m
+++ b/Sources/Utilities/NSString+SHA.m
@@ -38,26 +38,21 @@
 
 #import "NSString+SHA.h"
 
 #include <openssl/evp.h>
 #include <openssl/hmac.h>
 
 @implementation NSString (SHA)
 
-+ (void) initialize
-{
-	OpenSSL_add_all_digests(); // Is it ok if this gets called multiple times?
-}
-
 - (NSData*) SHA256Hash
 {
 	NSData* result = nil;
 
-	const EVP_MD* md = EVP_get_digestbyname("SHA256");
+	const EVP_MD* md = EVP_sha256();
 	if (md != NULL)
 	{
 		unsigned char md_value[EVP_MAX_MD_SIZE];
 		unsigned int md_len;	
 		EVP_MD_CTX mdctx;
 
 		const char* s = [self UTF8String];
 
@@ -72,17 +67,17 @@
 	
 	return result;
 }
 
 - (NSData*) HMACSHA256WithKey: (NSData*) key
 {
 	NSData* result = nil;
 
-	const EVP_MD* evp_md = EVP_get_digestbyname("SHA256");
+	const EVP_MD* evp_md = EVP_sha256();
 	if (evp_md != NULL)
 	{
 		unsigned char hmac_value[EVP_MAX_MD_SIZE];
 		unsigned int hmac_length;
 	
 		const char* s = [self UTF8String];
 	
 		if (HMAC(evp_md, [key bytes], [key length], (const void*) s, strlen(s), hmac_value, &hmac_length) != NULL) {