From: Junichi Uekawa <dancer@netfort•gr.jp>
To: torvalds@osdl•org, git@vger•kernel.org
Subject: [PATCH] use gcrypt instead of libssl for hash
Date: Sun, 17 Apr 2005 19:52:53 +0900 [thread overview]
Message-ID: <87hdi5oet6.dancerj@netfort.gr.jp> (raw)
[-- Attachment #1: Type: text/plain, Size: 4691 bytes --]
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 <dancer@debian•org>
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 <sys/mman.h>
#include <netinet/in.h>
-#include <openssl/sha.h>
+#include <gcrypt.h>
#include <zlib.h>
/*
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/
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next reply other threads:[~2005-04-17 10:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-17 10:52 Junichi Uekawa [this message]
2005-04-17 17:52 ` [PATCH] use gcrypt instead of libssl for hash Linus Torvalds
2005-04-17 22:36 ` Junichi Uekawa
2005-04-18 3:58 ` Edgar Toernig
2005-04-21 19:48 ` Mozilla SHA1 implementation Linus Torvalds
2005-04-21 22:59 ` Edgar Toernig
2005-04-22 6:49 ` Paul Mackerras
2005-04-22 7:35 ` Paul Mackerras
2005-04-22 15:31 ` Linus Torvalds
2005-04-22 15:40 ` Linus Torvalds
2005-04-22 15:58 ` (anal) Q: Are there any coding styles or development guidelines? Klaus Robert Suetterlin
2005-04-22 17:50 ` Linus Torvalds
2005-04-22 20:29 ` Mozilla SHA1 implementation Daniel Barkalow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87hdi5oet6.dancerj@netfort.gr.jp \
--to=dancer@netfort$(echo .)gr.jp \
--cc=git@vger$(echo .)kernel.org \
--cc=torvalds@osdl$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox