From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junichi Uekawa Subject: [PATCH] use gcrypt instead of libssl for hash Date: Sun, 17 Apr 2005 19:52:53 +0900 Message-ID: <87hdi5oet6.dancerj@netfort.gr.jp> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/signed; boundary="pgp-sign-Multipart_Sun_Apr_17_19:52:49_2005-1"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit X-From: git-owner@vger.kernel.org Sun Apr 17 12:49:51 2005 Return-path: Received: from vger.kernel.org ([12.107.209.244]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DN7LS-0001B8-Rh for gcvg-git@gmane.org; Sun, 17 Apr 2005 12:49:43 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261299AbVDQKxT (ORCPT ); Sun, 17 Apr 2005 06:53:19 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261300AbVDQKxT (ORCPT ); Sun, 17 Apr 2005 06:53:19 -0400 Received: from 68.105.138.210.bn.2iij.net ([210.138.105.68]:45841 "HELO viper2.netfort.gr.jp") by vger.kernel.org with SMTP id S261299AbVDQKww (ORCPT ); Sun, 17 Apr 2005 06:52:52 -0400 Received: (qmail 4303 invoked from network); 17 Apr 2005 10:52:51 -0000 Received: from unknown (HELO atoron.dancer.pr.jp.netfort.gr.jp) (127.0.0.1) by viper2.netfort.gr.jp with SMTP; 17 Apr 2005 10:52:51 -0000 To: torvalds@osdl.org, git@vger.kernel.org User-Agent: Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/21.4 (i386-pc-linux-gnu) MULE/5.0 (SAKAKI) Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org --pgp-sign-Multipart_Sun_Apr_17_19:52:49_2005-1 Content-Type: text/plain; charset=US-ASCII Hi, This is the first time for me to send you a patch; be gentle. the following patch allows for use of gcrypt. libssl seems to have a restrictive licensing wrt GPL applications. This patch adds a requirement for libgcrypt11, and removes the requirement for libssl. I hope I have not overlooked anything. Signed-off-by: Junichi Uekawa Makefile: 770595e02be4a9a55ff98910c53617c3b0f1e145 --- Makefile +++ Makefile 2005-04-17 19:38:00.000000000 +0900 @@ -7,7 +7,7 @@ # BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely randomly # break unless your underlying filesystem supports those sub-second times # (my ext3 doesn't). -CFLAGS=-g -O3 -Wall +CFLAGS=-g -O3 -Wall $(shell libgcrypt-config --cflags) CC=gcc @@ -21,7 +21,7 @@ install: $(PROG) install $(PROG) $(HOME)/bin/ -LIBS= -lssl -lz +LIBS= $(shell libgcrypt-config --libs) -lz init-db: init-db.o cache.h: 5948db759b3f6fb5ade3b027f202330f71a8cb6a --- cache.h +++ cache.h 2005-04-17 19:25:40.000000000 +0900 @@ -12,7 +12,7 @@ #include #include -#include +#include #include /* read-cache.c: 740ffcce7026b268bd4dfe1d0a773ad7e3a24f96 --- read-cache.c +++ read-cache.c 2005-04-17 19:34:37.000000000 +0900 @@ -116,11 +116,14 @@ int check_sha1_signature(unsigned char *sha1, void *map, unsigned long size) { unsigned char real_sha1[20]; - SHA_CTX c; + gcry_md_hd_t c; - SHA1_Init(&c); - SHA1_Update(&c, map, size); - SHA1_Final(real_sha1, &c); + gcry_md_open(&c, GCRY_MD_SHA1, 0); + gcry_md_write(c, map, size); + gcry_md_final(c); + memcpy(real_sha1, gcry_md_read(c, 0), 20); + gcry_md_close(c); + return memcmp(sha1, real_sha1, 20) ? -1 : 0; } @@ -203,7 +206,7 @@ char *compressed; z_stream stream; unsigned char sha1[20]; - SHA_CTX c; + gcry_md_hd_t c; /* Set it up */ memset(&stream, 0, sizeof(stream)); @@ -222,9 +225,11 @@ size = stream.total_out; /* Sha1.. */ - SHA1_Init(&c); - SHA1_Update(&c, compressed, size); - SHA1_Final(sha1, &c); + gcry_md_open(&c, GCRY_MD_SHA1, 0); + gcry_md_write(c, compressed, size); + gcry_md_final(c); + memcpy(sha1, gcry_md_read(c, 0), 20); + gcry_md_close(c); if (write_sha1_buffer(sha1, compressed, size) < 0) return -1; @@ -425,17 +430,20 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size) { - SHA_CTX c; + gcry_md_hd_t c; unsigned char sha1[20]; if (hdr->hdr_signature != htonl(CACHE_SIGNATURE)) return error("bad signature"); if (hdr->hdr_version != htonl(1)) return error("bad version"); - SHA1_Init(&c); - SHA1_Update(&c, hdr, offsetof(struct cache_header, sha1)); - SHA1_Update(&c, hdr+1, size - sizeof(*hdr)); - SHA1_Final(sha1, &c); + gcry_md_open(&c, GCRY_MD_SHA1, 0); + gcry_md_write(c, hdr, offsetof(struct cache_header, sha1)); + gcry_md_write(c, hdr+1, size - sizeof(*hdr)); + gcry_md_final(c); + memcpy(sha1, gcry_md_read(c, 0), 20); + gcry_md_close(c); + if (memcmp(sha1, hdr->sha1, 20)) return error("bad header sha1"); return 0; @@ -498,7 +506,8 @@ int write_cache(int newfd, struct cache_entry **cache, int entries) { - SHA_CTX c; + gcry_md_hd_t c; + struct cache_header hdr; int i; @@ -506,14 +515,16 @@ hdr.hdr_version = htonl(1); hdr.hdr_entries = htonl(entries); - SHA1_Init(&c); - SHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1)); + gcry_md_open(&c, GCRY_MD_SHA1, 0); + gcry_md_write(c, &hdr, offsetof(struct cache_header, sha1)); for (i = 0; i < entries; i++) { struct cache_entry *ce = cache[i]; int size = ce_size(ce); - SHA1_Update(&c, ce, size); + gcry_md_write(c, ce, size); } - SHA1_Final(hdr.sha1, &c); + gcry_md_final(c); + memcpy(hdr.sha1, gcry_md_read(c, 0), 20); + gcry_md_close(c); if (write(newfd, &hdr, sizeof(hdr)) != sizeof(hdr)) return -1; update-cache.c: 5afecd1a4fd90d2505753ce2d5044d780fe69a7f --- update-cache.c +++ update-cache.c 2005-04-17 19:36:40.000000000 +0900 @@ -22,7 +22,7 @@ void *out = malloc(max_out_bytes); void *metadata = malloc(namelen + 200); void *in; - SHA_CTX c; + gcry_md_hd_t c; in = ""; if (size) @@ -54,9 +54,11 @@ deflateEnd(&stream); - SHA1_Init(&c); - SHA1_Update(&c, out, stream.total_out); - SHA1_Final(ce->sha1, &c); + gcry_md_open(&c, GCRY_MD_SHA1, 0); + gcry_md_write(c, out, stream.total_out); + gcry_md_final(c); + memcpy(ce->sha1, gcry_md_read(c, 0), 20); + gcry_md_close(c); return write_sha1_buffer(ce->sha1, out, stream.total_out); } write-tree.c: 34a351b20fb38ea588f34bd9634f101b9dc533cb regards, junichi -- Junichi Uekawa, Debian Developer 17D6 120E 4455 1832 9423 7447 3059 BF92 CD37 56F4 http://www.netfort.gr.jp/~dancer/ --pgp-sign-Multipart_Sun_Apr_17_19:52:49_2005-1 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQBCYkADMFm/ks03VvQRAp4QAJ9MinAmSPc/m9H4KuQJzkoHZrAaywCfU8MD +N5Rn72ynaxGGHH8ynz2G6I= =boGt -----END PGP SIGNATURE----- --pgp-sign-Multipart_Sun_Apr_17_19:52:49_2005-1--