Revision
855
Author
wsiegrist@apple.com
Date
2010-08-06 09:39:37 -0700 (Fri, 06 Aug 2010)

Log Message

Replace OpenSSL with CommonCrypto in register plugin

Modified Paths

Diff

Modified: branches/PR-8279204/darwinxref/plugins/register.c (854 => 855)


--- branches/PR-8279204/darwinxref/plugins/register.c	2010-08-06 16:28:26 UTC (rev 854)
+++ branches/PR-8279204/darwinxref/plugins/register.c	2010-08-06 16:39:37 UTC (rev 855)
@@ -43,7 +43,8 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
-#include <openssl/evp.h>
+#include <stdlib.h>
+#include <CommonCrypto/CommonDigest.h>
 #include "sqlite3.h"
 
 extern char** environ;
@@ -129,22 +130,13 @@
 }
 
 static char* calculate_digest(int fd) {
-	unsigned char digstr[EVP_MAX_MD_SIZE];
-	memset(digstr, 0, sizeof(digstr));
+	unsigned char md[20];
+	CC_SHA1_CTX c;
+	CC_SHA1_Init(&c);
 	
-	EVP_MD_CTX ctx;
-	static const EVP_MD* md;
+	memset(md, 0, 20);
 	
-	if (md == NULL) {
-		EVP_MD_CTX_init(&ctx);
-		OpenSSL_add_all_digests();
-		md = EVP_get_digestbyname("sha1");
-		if (md == NULL) return NULL;
-	}
-
-	EVP_DigestInit(&ctx, md);
-
-	unsigned int len;
+	ssize_t len;
 	const unsigned int blocklen = 8192;
 	static unsigned char* block = NULL;
 	if (block == NULL) {
@@ -155,11 +147,11 @@
 		if (len == 0) { close(fd); break; }
 		if ((len < 0) && (errno == EINTR)) continue;
 		if (len < 0) { close(fd); return NULL; }
-		EVP_DigestUpdate(&ctx, block, len);
+		CC_SHA1_Update(&c, block, (size_t)len);
 	}
-
-	EVP_DigestFinal(&ctx, digstr, &len);
-	return format_digest(digstr);
+	
+	CC_SHA1_Final(md, &c);
+	return format_digest(md);
 }
 
 static char* calculate_unprebound_digest(const char* filename);