1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-06 09:56:12 +02:00

fix openssl headers conflicting with custom SHA1 implementations

On ARM I have the following compilation errors:

    CC fast-import.o
In file included from cache.h:8,
                 from builtin.h:6,
                 from fast-import.c:142:
arm/sha1.h:14: error: conflicting types for 'SHA_CTX'
/usr/include/openssl/sha.h:105: error: previous declaration of 'SHA_CTX' was here
arm/sha1.h:16: error: conflicting types for 'SHA1_Init'
/usr/include/openssl/sha.h:115: error: previous declaration of 'SHA1_Init' was here
arm/sha1.h:17: error: conflicting types for 'SHA1_Update'
/usr/include/openssl/sha.h:116: error: previous declaration of 'SHA1_Update' was here
arm/sha1.h:18: error: conflicting types for 'SHA1_Final'
/usr/include/openssl/sha.h:117: error: previous declaration of 'SHA1_Final' was here
make: *** [fast-import.o] Error 1

This is because openssl header files are always included in
git-compat-util.h since commit 684ec6c63c whenever NO_OPENSSL is not
set, which somehow brings in <openssl/sha1.h> clashing with the custom
ARM version.  Compilation of git is probably broken on PPC too for the
same reason.

Turns out that the only file requiring openssl/ssl.h and openssl/err.h
is imap-send.c.  But only moving those problematic includes there
doesn't solve the issue as it also includes cache.h which brings in the
conflicting local SHA1 header file.

As suggested by Jeff King, the best solution is to rename our references
to SHA1 functions and structure to something git specific, and define those
according to the implementation used.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Nicolas Pitre 2008-10-01 14:05:20 -04:00 committed by Shawn O. Pearce
parent 120a385afb
commit 9126f0091f
24 changed files with 162 additions and 141 deletions

View File

@ -8,9 +8,9 @@
#include <string.h> #include <string.h>
#include "sha1.h" #include "sha1.h"
extern void sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W); extern void arm_sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
void SHA1_Init(SHA_CTX *c) void arm_SHA1_Init(arm_SHA_CTX *c)
{ {
c->len = 0; c->len = 0;
c->hash[0] = 0x67452301; c->hash[0] = 0x67452301;
@ -20,7 +20,7 @@ void SHA1_Init(SHA_CTX *c)
c->hash[4] = 0xc3d2e1f0; c->hash[4] = 0xc3d2e1f0;
} }
void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n) void arm_SHA1_Update(arm_SHA_CTX *c, const void *p, unsigned long n)
{ {
uint32_t workspace[80]; uint32_t workspace[80];
unsigned int partial; unsigned int partial;
@ -32,12 +32,12 @@ void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
if (partial) { if (partial) {
done = 64 - partial; done = 64 - partial;
memcpy(c->buffer + partial, p, done); memcpy(c->buffer + partial, p, done);
sha_transform(c->hash, c->buffer, workspace); arm_sha_transform(c->hash, c->buffer, workspace);
partial = 0; partial = 0;
} else } else
done = 0; done = 0;
while (n >= done + 64) { while (n >= done + 64) {
sha_transform(c->hash, p + done, workspace); arm_sha_transform(c->hash, p + done, workspace);
done += 64; done += 64;
} }
} else } else
@ -46,7 +46,7 @@ void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
memcpy(c->buffer + partial, p + done, n - done); memcpy(c->buffer + partial, p + done, n - done);
} }
void SHA1_Final(unsigned char *hash, SHA_CTX *c) void arm_SHA1_Final(unsigned char *hash, arm_SHA_CTX *c)
{ {
uint64_t bitlen; uint64_t bitlen;
uint32_t bitlen_hi, bitlen_lo; uint32_t bitlen_hi, bitlen_lo;
@ -57,7 +57,7 @@ void SHA1_Final(unsigned char *hash, SHA_CTX *c)
bitlen = c->len << 3; bitlen = c->len << 3;
offset = c->len & 0x3f; offset = c->len & 0x3f;
padlen = ((offset < 56) ? 56 : (64 + 56)) - offset; padlen = ((offset < 56) ? 56 : (64 + 56)) - offset;
SHA1_Update(c, padding, padlen); arm_SHA1_Update(c, padding, padlen);
bitlen_hi = bitlen >> 32; bitlen_hi = bitlen >> 32;
bitlen_lo = bitlen & 0xffffffff; bitlen_lo = bitlen & 0xffffffff;
@ -69,7 +69,7 @@ void SHA1_Final(unsigned char *hash, SHA_CTX *c)
bits[5] = bitlen_lo >> 16; bits[5] = bitlen_lo >> 16;
bits[6] = bitlen_lo >> 8; bits[6] = bitlen_lo >> 8;
bits[7] = bitlen_lo; bits[7] = bitlen_lo;
SHA1_Update(c, bits, 8); arm_SHA1_Update(c, bits, 8);
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
uint32_t v = c->hash[i]; uint32_t v = c->hash[i];

View File

@ -7,12 +7,17 @@
#include <stdint.h> #include <stdint.h>
typedef struct sha_context { typedef struct {
uint64_t len; uint64_t len;
uint32_t hash[5]; uint32_t hash[5];
unsigned char buffer[64]; unsigned char buffer[64];
} SHA_CTX; } arm_SHA_CTX;
void SHA1_Init(SHA_CTX *c); void arm_SHA1_Init(arm_SHA_CTX *c);
void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n); void arm_SHA1_Update(arm_SHA_CTX *c, const void *p, unsigned long n);
void SHA1_Final(unsigned char *hash, SHA_CTX *c); void arm_SHA1_Final(unsigned char *hash, arm_SHA_CTX *c);
#define git_SHA_CTX arm_SHA_CTX
#define git_SHA1_Init arm_SHA1_Init
#define git_SHA1_Update arm_SHA1_Update
#define git_SHA1_Final arm_SHA1_Final

View File

@ -10,7 +10,7 @@
*/ */
.text .text
.globl sha_transform .globl arm_sha_transform
/* /*
* void sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W); * void sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
@ -18,7 +18,7 @@
* note: the "data" pointer may be unaligned. * note: the "data" pointer may be unaligned.
*/ */
sha_transform: arm_sha_transform:
stmfd sp!, {r4 - r8, lr} stmfd sp!, {r4 - r8, lr}

View File

@ -19,7 +19,7 @@ static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict]
static unsigned char buffer[4096]; static unsigned char buffer[4096];
static unsigned int offset, len; static unsigned int offset, len;
static off_t consumed_bytes; static off_t consumed_bytes;
static SHA_CTX ctx; static git_SHA_CTX ctx;
/* /*
* When running under --strict mode, objects whose reachability are * When running under --strict mode, objects whose reachability are
@ -59,7 +59,7 @@ static void *fill(int min)
if (min > sizeof(buffer)) if (min > sizeof(buffer))
die("cannot fill %d bytes", min); die("cannot fill %d bytes", min);
if (offset) { if (offset) {
SHA1_Update(&ctx, buffer, offset); git_SHA1_Update(&ctx, buffer, offset);
memmove(buffer, buffer + offset, len); memmove(buffer, buffer + offset, len);
offset = 0; offset = 0;
} }
@ -539,10 +539,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
/* We don't take any non-flag arguments now.. Maybe some day */ /* We don't take any non-flag arguments now.. Maybe some day */
usage(unpack_usage); usage(unpack_usage);
} }
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
unpack_all(); unpack_all();
SHA1_Update(&ctx, buffer, offset); git_SHA1_Update(&ctx, buffer, offset);
SHA1_Final(sha1, &ctx); git_SHA1_Final(sha1, &ctx);
if (strict) if (strict)
write_rest(); write_rest();
if (hashcmp(fill(20), sha1)) if (hashcmp(fill(20), sha1))

View File

@ -6,8 +6,14 @@
#include "hash.h" #include "hash.h"
#include SHA1_HEADER #include SHA1_HEADER
#include <zlib.h> #ifndef git_SHA_CTX
#define git_SHA_CTX SHA_CTX
#define git_SHA1_Init SHA1_Init
#define git_SHA1_Update SHA1_Update
#define git_SHA1_Final SHA1_Final
#endif
#include <zlib.h>
#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200 #if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
#define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11) #define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
#endif #endif

View File

@ -36,11 +36,11 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
unsigned offset = f->offset; unsigned offset = f->offset;
if (offset) { if (offset) {
SHA1_Update(&f->ctx, f->buffer, offset); git_SHA1_Update(&f->ctx, f->buffer, offset);
sha1flush(f, f->buffer, offset); sha1flush(f, f->buffer, offset);
f->offset = 0; f->offset = 0;
} }
SHA1_Final(f->buffer, &f->ctx); git_SHA1_Final(f->buffer, &f->ctx);
if (result) if (result)
hashcpy(result, f->buffer); hashcpy(result, f->buffer);
if (flags & (CSUM_CLOSE | CSUM_FSYNC)) { if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
@ -82,7 +82,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count)
buf = (char *) buf + nr; buf = (char *) buf + nr;
left -= nr; left -= nr;
if (!left) { if (!left) {
SHA1_Update(&f->ctx, data, offset); git_SHA1_Update(&f->ctx, data, offset);
sha1flush(f, data, offset); sha1flush(f, data, offset);
offset = 0; offset = 0;
} }
@ -105,7 +105,7 @@ struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp
f->tp = tp; f->tp = tp;
f->name = name; f->name = name;
f->do_crc = 0; f->do_crc = 0;
SHA1_Init(&f->ctx); git_SHA1_Init(&f->ctx);
return f; return f;
} }

View File

@ -7,7 +7,7 @@ struct progress;
struct sha1file { struct sha1file {
int fd; int fd;
unsigned int offset; unsigned int offset;
SHA_CTX ctx; git_SHA_CTX ctx;
off_t total; off_t total;
struct progress *tp; struct progress *tp;
const char *name; const char *name;

12
diff.c
View File

@ -3087,7 +3087,7 @@ static void diff_summary(FILE *file, struct diff_filepair *p)
} }
struct patch_id_t { struct patch_id_t {
SHA_CTX *ctx; git_SHA_CTX *ctx;
int patchlen; int patchlen;
}; };
@ -3115,7 +3115,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
new_len = remove_space(line, len); new_len = remove_space(line, len);
SHA1_Update(data->ctx, line, new_len); git_SHA1_Update(data->ctx, line, new_len);
data->patchlen += new_len; data->patchlen += new_len;
} }
@ -3124,11 +3124,11 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
{ {
struct diff_queue_struct *q = &diff_queued_diff; struct diff_queue_struct *q = &diff_queued_diff;
int i; int i;
SHA_CTX ctx; git_SHA_CTX ctx;
struct patch_id_t data; struct patch_id_t data;
char buffer[PATH_MAX * 4 + 20]; char buffer[PATH_MAX * 4 + 20];
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
memset(&data, 0, sizeof(struct patch_id_t)); memset(&data, 0, sizeof(struct patch_id_t));
data.ctx = &ctx; data.ctx = &ctx;
@ -3190,7 +3190,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
len2, p->two->path, len2, p->two->path,
len1, p->one->path, len1, p->one->path,
len2, p->two->path); len2, p->two->path);
SHA1_Update(&ctx, buffer, len1); git_SHA1_Update(&ctx, buffer, len1);
xpp.flags = XDF_NEED_MINIMAL; xpp.flags = XDF_NEED_MINIMAL;
xecfg.ctxlen = 3; xecfg.ctxlen = 3;
@ -3199,7 +3199,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
&xpp, &xecfg, &ecb); &xpp, &xecfg, &ecb);
} }
SHA1_Final(sha1, &ctx); git_SHA1_Final(sha1, &ctx);
return 0; return 0;
} }

View File

@ -845,7 +845,7 @@ static int oecmp (const void *a_, const void *b_)
static char *create_index(void) static char *create_index(void)
{ {
static char tmpfile[PATH_MAX]; static char tmpfile[PATH_MAX];
SHA_CTX ctx; git_SHA_CTX ctx;
struct sha1file *f; struct sha1file *f;
struct object_entry **idx, **c, **last, *e; struct object_entry **idx, **c, **last, *e;
struct object_entry_pool *o; struct object_entry_pool *o;
@ -882,17 +882,17 @@ static char *create_index(void)
idx_fd = xmkstemp(tmpfile); idx_fd = xmkstemp(tmpfile);
f = sha1fd(idx_fd, tmpfile); f = sha1fd(idx_fd, tmpfile);
sha1write(f, array, 256 * sizeof(int)); sha1write(f, array, 256 * sizeof(int));
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
for (c = idx; c != last; c++) { for (c = idx; c != last; c++) {
uint32_t offset = htonl((*c)->offset); uint32_t offset = htonl((*c)->offset);
sha1write(f, &offset, 4); sha1write(f, &offset, 4);
sha1write(f, (*c)->sha1, sizeof((*c)->sha1)); sha1write(f, (*c)->sha1, sizeof((*c)->sha1));
SHA1_Update(&ctx, (*c)->sha1, 20); git_SHA1_Update(&ctx, (*c)->sha1, 20);
} }
sha1write(f, pack_data->sha1, sizeof(pack_data->sha1)); sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
sha1close(f, NULL, CSUM_FSYNC); sha1close(f, NULL, CSUM_FSYNC);
free(idx); free(idx);
SHA1_Final(pack_data->sha1, &ctx); git_SHA1_Final(pack_data->sha1, &ctx);
return tmpfile; return tmpfile;
} }
@ -1033,15 +1033,15 @@ static int store_object(
unsigned char hdr[96]; unsigned char hdr[96];
unsigned char sha1[20]; unsigned char sha1[20];
unsigned long hdrlen, deltalen; unsigned long hdrlen, deltalen;
SHA_CTX c; git_SHA_CTX c;
z_stream s; z_stream s;
hdrlen = sprintf((char*)hdr,"%s %lu", typename(type), hdrlen = sprintf((char*)hdr,"%s %lu", typename(type),
(unsigned long)dat->len) + 1; (unsigned long)dat->len) + 1;
SHA1_Init(&c); git_SHA1_Init(&c);
SHA1_Update(&c, hdr, hdrlen); git_SHA1_Update(&c, hdr, hdrlen);
SHA1_Update(&c, dat->buf, dat->len); git_SHA1_Update(&c, dat->buf, dat->len);
SHA1_Final(sha1, &c); git_SHA1_Final(sha1, &c);
if (sha1out) if (sha1out)
hashcpy(sha1out, sha1); hashcpy(sha1out, sha1);

View File

@ -126,7 +126,7 @@ struct transfer_request
char errorstr[CURL_ERROR_SIZE]; char errorstr[CURL_ERROR_SIZE];
long http_code; long http_code;
unsigned char real_sha1[20]; unsigned char real_sha1[20];
SHA_CTX c; git_SHA_CTX c;
z_stream stream; z_stream stream;
int zret; int zret;
int rename; int rename;
@ -209,7 +209,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
request->stream.next_out = expn; request->stream.next_out = expn;
request->stream.avail_out = sizeof(expn); request->stream.avail_out = sizeof(expn);
request->zret = inflate(&request->stream, Z_SYNC_FLUSH); request->zret = inflate(&request->stream, Z_SYNC_FLUSH);
SHA1_Update(&request->c, expn, git_SHA1_Update(&request->c, expn,
sizeof(expn) - request->stream.avail_out); sizeof(expn) - request->stream.avail_out);
} while (request->stream.avail_in && request->zret == Z_OK); } while (request->stream.avail_in && request->zret == Z_OK);
data_received++; data_received++;
@ -270,7 +270,7 @@ static void start_fetch_loose(struct transfer_request *request)
inflateInit(&request->stream); inflateInit(&request->stream);
SHA1_Init(&request->c); git_SHA1_Init(&request->c);
url = xmalloc(strlen(remote->url) + 50); url = xmalloc(strlen(remote->url) + 50);
request->url = xmalloc(strlen(remote->url) + 50); request->url = xmalloc(strlen(remote->url) + 50);
@ -310,7 +310,7 @@ static void start_fetch_loose(struct transfer_request *request)
if (prev_read == -1) { if (prev_read == -1) {
memset(&request->stream, 0, sizeof(request->stream)); memset(&request->stream, 0, sizeof(request->stream));
inflateInit(&request->stream); inflateInit(&request->stream);
SHA1_Init(&request->c); git_SHA1_Init(&request->c);
if (prev_posn>0) { if (prev_posn>0) {
prev_posn = 0; prev_posn = 0;
lseek(request->local_fileno, 0, SEEK_SET); lseek(request->local_fileno, 0, SEEK_SET);
@ -742,7 +742,7 @@ static void finish_request(struct transfer_request *request)
fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n"); fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
inflateEnd(&request->stream); inflateEnd(&request->stream);
SHA1_Final(request->real_sha1, &request->c); git_SHA1_Final(request->real_sha1, &request->c);
if (request->zret != Z_STREAM_END) { if (request->zret != Z_STREAM_END) {
unlink(request->tmpfile); unlink(request->tmpfile);
} else if (hashcmp(request->obj->sha1, request->real_sha1)) { } else if (hashcmp(request->obj->sha1, request->real_sha1)) {

View File

@ -36,7 +36,7 @@ struct object_request
char errorstr[CURL_ERROR_SIZE]; char errorstr[CURL_ERROR_SIZE];
long http_code; long http_code;
unsigned char real_sha1[20]; unsigned char real_sha1[20];
SHA_CTX c; git_SHA_CTX c;
z_stream stream; z_stream stream;
int zret; int zret;
int rename; int rename;
@ -83,7 +83,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
obj_req->stream.next_out = expn; obj_req->stream.next_out = expn;
obj_req->stream.avail_out = sizeof(expn); obj_req->stream.avail_out = sizeof(expn);
obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH); obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH);
SHA1_Update(&obj_req->c, expn, git_SHA1_Update(&obj_req->c, expn,
sizeof(expn) - obj_req->stream.avail_out); sizeof(expn) - obj_req->stream.avail_out);
} while (obj_req->stream.avail_in && obj_req->zret == Z_OK); } while (obj_req->stream.avail_in && obj_req->zret == Z_OK);
data_received++; data_received++;
@ -144,7 +144,7 @@ static void start_object_request(struct walker *walker,
inflateInit(&obj_req->stream); inflateInit(&obj_req->stream);
SHA1_Init(&obj_req->c); git_SHA1_Init(&obj_req->c);
url = xmalloc(strlen(obj_req->repo->base) + 51); url = xmalloc(strlen(obj_req->repo->base) + 51);
obj_req->url = xmalloc(strlen(obj_req->repo->base) + 51); obj_req->url = xmalloc(strlen(obj_req->repo->base) + 51);
@ -184,7 +184,7 @@ static void start_object_request(struct walker *walker,
if (prev_read == -1) { if (prev_read == -1) {
memset(&obj_req->stream, 0, sizeof(obj_req->stream)); memset(&obj_req->stream, 0, sizeof(obj_req->stream));
inflateInit(&obj_req->stream); inflateInit(&obj_req->stream);
SHA1_Init(&obj_req->c); git_SHA1_Init(&obj_req->c);
if (prev_posn>0) { if (prev_posn>0) {
prev_posn = 0; prev_posn = 0;
lseek(obj_req->local, 0, SEEK_SET); lseek(obj_req->local, 0, SEEK_SET);
@ -244,7 +244,7 @@ static void finish_object_request(struct object_request *obj_req)
} }
inflateEnd(&obj_req->stream); inflateEnd(&obj_req->stream);
SHA1_Final(obj_req->real_sha1, &obj_req->c); git_SHA1_Final(obj_req->real_sha1, &obj_req->c);
if (obj_req->zret != Z_STREAM_END) { if (obj_req->zret != Z_STREAM_END) {
unlink(obj_req->tmpfile); unlink(obj_req->tmpfile);
return; return;

View File

@ -67,7 +67,7 @@ static struct progress *progress;
static unsigned char input_buffer[4096]; static unsigned char input_buffer[4096];
static unsigned int input_offset, input_len; static unsigned int input_offset, input_len;
static off_t consumed_bytes; static off_t consumed_bytes;
static SHA_CTX input_ctx; static git_SHA_CTX input_ctx;
static uint32_t input_crc32; static uint32_t input_crc32;
static int input_fd, output_fd, pack_fd; static int input_fd, output_fd, pack_fd;
@ -119,7 +119,7 @@ static void flush(void)
if (input_offset) { if (input_offset) {
if (output_fd >= 0) if (output_fd >= 0)
write_or_die(output_fd, input_buffer, input_offset); write_or_die(output_fd, input_buffer, input_offset);
SHA1_Update(&input_ctx, input_buffer, input_offset); git_SHA1_Update(&input_ctx, input_buffer, input_offset);
memmove(input_buffer, input_buffer + input_offset, input_len); memmove(input_buffer, input_buffer + input_offset, input_len);
input_offset = 0; input_offset = 0;
} }
@ -188,7 +188,7 @@ static char *open_pack_file(char *pack_name)
output_fd = -1; output_fd = -1;
pack_fd = input_fd; pack_fd = input_fd;
} }
SHA1_Init(&input_ctx); git_SHA1_Init(&input_ctx);
return pack_name; return pack_name;
} }
@ -588,7 +588,7 @@ static void parse_pack_objects(unsigned char *sha1)
/* Check pack integrity */ /* Check pack integrity */
flush(); flush();
SHA1_Final(sha1, &input_ctx); git_SHA1_Final(sha1, &input_ctx);
if (hashcmp(fill(20), sha1)) if (hashcmp(fill(20), sha1))
die("pack is corrupted (SHA1 mismatch)"); die("pack is corrupted (SHA1 mismatch)");
use(20); use(20);

View File

@ -35,9 +35,9 @@
#include "sha1.h" #include "sha1.h"
static void shaHashBlock(SHA_CTX *ctx); static void shaHashBlock(moz_SHA_CTX *ctx);
void SHA1_Init(SHA_CTX *ctx) { void moz_SHA1_Init(moz_SHA_CTX *ctx) {
int i; int i;
ctx->lenW = 0; ctx->lenW = 0;
@ -56,7 +56,7 @@ void SHA1_Init(SHA_CTX *ctx) {
} }
void SHA1_Update(SHA_CTX *ctx, const void *_dataIn, int len) { void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {
const unsigned char *dataIn = _dataIn; const unsigned char *dataIn = _dataIn;
int i; int i;
@ -75,7 +75,7 @@ void SHA1_Update(SHA_CTX *ctx, const void *_dataIn, int len) {
} }
void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx) { void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {
unsigned char pad0x80 = 0x80; unsigned char pad0x80 = 0x80;
unsigned char pad0x00 = 0x00; unsigned char pad0x00 = 0x00;
unsigned char padlen[8]; unsigned char padlen[8];
@ -91,10 +91,10 @@ void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx) {
padlen[5] = (unsigned char)((ctx->sizeLo >> 16) & 255); padlen[5] = (unsigned char)((ctx->sizeLo >> 16) & 255);
padlen[6] = (unsigned char)((ctx->sizeLo >> 8) & 255); padlen[6] = (unsigned char)((ctx->sizeLo >> 8) & 255);
padlen[7] = (unsigned char)((ctx->sizeLo >> 0) & 255); padlen[7] = (unsigned char)((ctx->sizeLo >> 0) & 255);
SHA1_Update(ctx, &pad0x80, 1); moz_SHA1_Update(ctx, &pad0x80, 1);
while (ctx->lenW != 56) while (ctx->lenW != 56)
SHA1_Update(ctx, &pad0x00, 1); moz_SHA1_Update(ctx, &pad0x00, 1);
SHA1_Update(ctx, padlen, 8); moz_SHA1_Update(ctx, padlen, 8);
/* Output hash /* Output hash
*/ */
@ -106,13 +106,13 @@ void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx) {
/* /*
* Re-initialize the context (also zeroizes contents) * Re-initialize the context (also zeroizes contents)
*/ */
SHA1_Init(ctx); moz_SHA1_Init(ctx);
} }
#define SHA_ROT(X,n) (((X) << (n)) | ((X) >> (32-(n)))) #define SHA_ROT(X,n) (((X) << (n)) | ((X) >> (32-(n))))
static void shaHashBlock(SHA_CTX *ctx) { static void shaHashBlock(moz_SHA_CTX *ctx) {
int t; int t;
unsigned int A,B,C,D,E,TEMP; unsigned int A,B,C,D,E,TEMP;

View File

@ -38,8 +38,13 @@ typedef struct {
unsigned int W[80]; unsigned int W[80];
int lenW; int lenW;
unsigned int sizeHi,sizeLo; unsigned int sizeHi,sizeLo;
} SHA_CTX; } moz_SHA_CTX;
void SHA1_Init(SHA_CTX *ctx); void moz_SHA1_Init(moz_SHA_CTX *ctx);
void SHA1_Update(SHA_CTX *ctx, const void *dataIn, int len); void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int len);
void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx); void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx);
#define git_SHA_CTX moz_SHA_CTX
#define git_SHA1_Init moz_SHA1_Init
#define git_SHA1_Update moz_SHA1_Update
#define git_SHA1_Final moz_SHA1_Final

View File

@ -47,7 +47,7 @@ static int verify_packfile(struct packed_git *p,
{ {
off_t index_size = p->index_size; off_t index_size = p->index_size;
const unsigned char *index_base = p->index_data; const unsigned char *index_base = p->index_data;
SHA_CTX ctx; git_SHA_CTX ctx;
unsigned char sha1[20], *pack_sig; unsigned char sha1[20], *pack_sig;
off_t offset = 0, pack_sig_ofs = p->pack_size - 20; off_t offset = 0, pack_sig_ofs = p->pack_size - 20;
uint32_t nr_objects, i; uint32_t nr_objects, i;
@ -60,16 +60,16 @@ static int verify_packfile(struct packed_git *p,
* immediately. * immediately.
*/ */
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
while (offset < pack_sig_ofs) { while (offset < pack_sig_ofs) {
unsigned int remaining; unsigned int remaining;
unsigned char *in = use_pack(p, w_curs, offset, &remaining); unsigned char *in = use_pack(p, w_curs, offset, &remaining);
offset += remaining; offset += remaining;
if (offset > pack_sig_ofs) if (offset > pack_sig_ofs)
remaining -= (unsigned int)(offset - pack_sig_ofs); remaining -= (unsigned int)(offset - pack_sig_ofs);
SHA1_Update(&ctx, in, remaining); git_SHA1_Update(&ctx, in, remaining);
} }
SHA1_Final(sha1, &ctx); git_SHA1_Final(sha1, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
if (hashcmp(sha1, pack_sig)) if (hashcmp(sha1, pack_sig))
err = error("%s SHA1 checksum mismatch", err = error("%s SHA1 checksum mismatch",
@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p)
{ {
off_t index_size; off_t index_size;
const unsigned char *index_base; const unsigned char *index_base;
SHA_CTX ctx; git_SHA_CTX ctx;
unsigned char sha1[20]; unsigned char sha1[20];
int err = 0; int err = 0;
struct pack_window *w_curs = NULL; struct pack_window *w_curs = NULL;
@ -146,9 +146,9 @@ int verify_pack(struct packed_git *p)
index_base = p->index_data; index_base = p->index_data;
/* Verify SHA1 sum of the index file */ /* Verify SHA1 sum of the index file */
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20)); git_SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20));
SHA1_Final(sha1, &ctx); git_SHA1_Final(sha1, &ctx);
if (hashcmp(sha1, index_base + index_size - 20)) if (hashcmp(sha1, index_base + index_size - 20))
err = error("Packfile index for %s SHA1 mismatch", err = error("Packfile index for %s SHA1 mismatch",
p->pack_name); p->pack_name);

View File

@ -25,7 +25,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
off_t last_obj_offset = 0; off_t last_obj_offset = 0;
uint32_t array[256]; uint32_t array[256];
int i, fd; int i, fd;
SHA_CTX ctx; git_SHA_CTX ctx;
uint32_t index_version; uint32_t index_version;
if (nr_objects) { if (nr_objects) {
@ -86,7 +86,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
sha1write(f, array, 256 * 4); sha1write(f, array, 256 * 4);
/* compute the SHA1 hash of sorted object names. */ /* compute the SHA1 hash of sorted object names. */
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
/* /*
* Write the actual SHA1 entries.. * Write the actual SHA1 entries..
@ -99,7 +99,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
sha1write(f, &offset, 4); sha1write(f, &offset, 4);
} }
sha1write(f, obj->sha1, 20); sha1write(f, obj->sha1, 20);
SHA1_Update(&ctx, obj->sha1, 20); git_SHA1_Update(&ctx, obj->sha1, 20);
} }
if (index_version >= 2) { if (index_version >= 2) {
@ -140,7 +140,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
sha1write(f, sha1, 20); sha1write(f, sha1, 20);
sha1close(f, NULL, CSUM_FSYNC); sha1close(f, NULL, CSUM_FSYNC);
SHA1_Final(sha1, &ctx); git_SHA1_Final(sha1, &ctx);
return index_name; return index_name;
} }
@ -168,12 +168,12 @@ void fixup_pack_header_footer(int pack_fd,
off_t partial_pack_offset) off_t partial_pack_offset)
{ {
int aligned_sz, buf_sz = 8 * 1024; int aligned_sz, buf_sz = 8 * 1024;
SHA_CTX old_sha1_ctx, new_sha1_ctx; git_SHA_CTX old_sha1_ctx, new_sha1_ctx;
struct pack_header hdr; struct pack_header hdr;
char *buf; char *buf;
SHA1_Init(&old_sha1_ctx); git_SHA1_Init(&old_sha1_ctx);
SHA1_Init(&new_sha1_ctx); git_SHA1_Init(&new_sha1_ctx);
if (lseek(pack_fd, 0, SEEK_SET) != 0) if (lseek(pack_fd, 0, SEEK_SET) != 0)
die("Failed seeking to start of %s: %s", pack_name, strerror(errno)); die("Failed seeking to start of %s: %s", pack_name, strerror(errno));
@ -181,9 +181,9 @@ void fixup_pack_header_footer(int pack_fd,
die("Unable to reread header of %s: %s", pack_name, strerror(errno)); die("Unable to reread header of %s: %s", pack_name, strerror(errno));
if (lseek(pack_fd, 0, SEEK_SET) != 0) if (lseek(pack_fd, 0, SEEK_SET) != 0)
die("Failed seeking to start of %s: %s", pack_name, strerror(errno)); die("Failed seeking to start of %s: %s", pack_name, strerror(errno));
SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr)); git_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));
hdr.hdr_entries = htonl(object_count); hdr.hdr_entries = htonl(object_count);
SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr)); git_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));
write_or_die(pack_fd, &hdr, sizeof(hdr)); write_or_die(pack_fd, &hdr, sizeof(hdr));
partial_pack_offset -= sizeof(hdr); partial_pack_offset -= sizeof(hdr);
@ -198,7 +198,7 @@ void fixup_pack_header_footer(int pack_fd,
break; break;
if (n < 0) if (n < 0)
die("Failed to checksum %s: %s", pack_name, strerror(errno)); die("Failed to checksum %s: %s", pack_name, strerror(errno));
SHA1_Update(&new_sha1_ctx, buf, n); git_SHA1_Update(&new_sha1_ctx, buf, n);
aligned_sz -= n; aligned_sz -= n;
if (!aligned_sz) if (!aligned_sz)
@ -207,11 +207,11 @@ void fixup_pack_header_footer(int pack_fd,
if (!partial_pack_sha1) if (!partial_pack_sha1)
continue; continue;
SHA1_Update(&old_sha1_ctx, buf, n); git_SHA1_Update(&old_sha1_ctx, buf, n);
partial_pack_offset -= n; partial_pack_offset -= n;
if (partial_pack_offset == 0) { if (partial_pack_offset == 0) {
unsigned char sha1[20]; unsigned char sha1[20];
SHA1_Final(sha1, &old_sha1_ctx); git_SHA1_Final(sha1, &old_sha1_ctx);
if (hashcmp(sha1, partial_pack_sha1) != 0) if (hashcmp(sha1, partial_pack_sha1) != 0)
die("Unexpected checksum for %s " die("Unexpected checksum for %s "
"(disk corruption?)", pack_name); "(disk corruption?)", pack_name);
@ -220,7 +220,7 @@ void fixup_pack_header_footer(int pack_fd,
* pack, which also means making partial_pack_offset * pack, which also means making partial_pack_offset
* big enough not to matter anymore. * big enough not to matter anymore.
*/ */
SHA1_Init(&old_sha1_ctx); git_SHA1_Init(&old_sha1_ctx);
partial_pack_offset = ~partial_pack_offset; partial_pack_offset = ~partial_pack_offset;
partial_pack_offset -= MSB(partial_pack_offset, 1); partial_pack_offset -= MSB(partial_pack_offset, 1);
} }
@ -228,8 +228,8 @@ void fixup_pack_header_footer(int pack_fd,
free(buf); free(buf);
if (partial_pack_sha1) if (partial_pack_sha1)
SHA1_Final(partial_pack_sha1, &old_sha1_ctx); git_SHA1_Final(partial_pack_sha1, &old_sha1_ctx);
SHA1_Final(new_pack_sha1, &new_sha1_ctx); git_SHA1_Final(new_pack_sha1, &new_sha1_ctx);
write_or_die(pack_fd, new_pack_sha1, 20); write_or_die(pack_fd, new_pack_sha1, 20);
fsync_or_die(pack_fd, pack_name); fsync_or_die(pack_fd, pack_name);
} }

View File

@ -1,6 +1,6 @@
#include "cache.h" #include "cache.h"
static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c) static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c)
{ {
unsigned char result[20]; unsigned char result[20];
char name[50]; char name[50];
@ -8,10 +8,10 @@ static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c)
if (!patchlen) if (!patchlen)
return; return;
SHA1_Final(result, c); git_SHA1_Final(result, c);
memcpy(name, sha1_to_hex(id), 41); memcpy(name, sha1_to_hex(id), 41);
printf("%s %s\n", sha1_to_hex(result), name); printf("%s %s\n", sha1_to_hex(result), name);
SHA1_Init(c); git_SHA1_Init(c);
} }
static int remove_space(char *line) static int remove_space(char *line)
@ -31,10 +31,10 @@ static void generate_id_list(void)
{ {
static unsigned char sha1[20]; static unsigned char sha1[20];
static char line[1000]; static char line[1000];
SHA_CTX ctx; git_SHA_CTX ctx;
int patchlen = 0; int patchlen = 0;
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
while (fgets(line, sizeof(line), stdin) != NULL) { while (fgets(line, sizeof(line), stdin) != NULL) {
unsigned char n[20]; unsigned char n[20];
char *p = line; char *p = line;
@ -67,7 +67,7 @@ static void generate_id_list(void)
/* Compute the sha without whitespace */ /* Compute the sha without whitespace */
len = remove_space(line); len = remove_space(line);
patchlen += len; patchlen += len;
SHA1_Update(&ctx, line, len); git_SHA1_Update(&ctx, line, len);
} }
flush_current_id(patchlen, sha1, &ctx); flush_current_id(patchlen, sha1, &ctx);
} }

View File

@ -10,10 +10,10 @@
#include <string.h> #include <string.h>
#include "sha1.h" #include "sha1.h"
extern void sha1_core(uint32_t *hash, const unsigned char *p, extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,
unsigned int nblocks); unsigned int nblocks);
int SHA1_Init(SHA_CTX *c) int ppc_SHA1_Init(ppc_SHA_CTX *c)
{ {
c->hash[0] = 0x67452301; c->hash[0] = 0x67452301;
c->hash[1] = 0xEFCDAB89; c->hash[1] = 0xEFCDAB89;
@ -25,7 +25,7 @@ int SHA1_Init(SHA_CTX *c)
return 0; return 0;
} }
int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n) int ppc_SHA1_Update(ppc_SHA_CTX *c, const void *ptr, unsigned long n)
{ {
unsigned long nb; unsigned long nb;
const unsigned char *p = ptr; const unsigned char *p = ptr;
@ -38,12 +38,12 @@ int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n)
nb = n; nb = n;
memcpy(&c->buf.b[c->cnt], p, nb); memcpy(&c->buf.b[c->cnt], p, nb);
if ((c->cnt += nb) == 64) { if ((c->cnt += nb) == 64) {
sha1_core(c->hash, c->buf.b, 1); ppc_sha1_core(c->hash, c->buf.b, 1);
c->cnt = 0; c->cnt = 0;
} }
} else { } else {
nb = n >> 6; nb = n >> 6;
sha1_core(c->hash, p, nb); ppc_sha1_core(c->hash, p, nb);
nb <<= 6; nb <<= 6;
} }
n -= nb; n -= nb;
@ -52,7 +52,7 @@ int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n)
return 0; return 0;
} }
int SHA1_Final(unsigned char *hash, SHA_CTX *c) int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c)
{ {
unsigned int cnt = c->cnt; unsigned int cnt = c->cnt;
@ -60,13 +60,13 @@ int SHA1_Final(unsigned char *hash, SHA_CTX *c)
if (cnt > 56) { if (cnt > 56) {
if (cnt < 64) if (cnt < 64)
memset(&c->buf.b[cnt], 0, 64 - cnt); memset(&c->buf.b[cnt], 0, 64 - cnt);
sha1_core(c->hash, c->buf.b, 1); ppc_sha1_core(c->hash, c->buf.b, 1);
cnt = 0; cnt = 0;
} }
if (cnt < 56) if (cnt < 56)
memset(&c->buf.b[cnt], 0, 56 - cnt); memset(&c->buf.b[cnt], 0, 56 - cnt);
c->buf.l[7] = c->len; c->buf.l[7] = c->len;
sha1_core(c->hash, c->buf.b, 1); ppc_sha1_core(c->hash, c->buf.b, 1);
memcpy(hash, c->hash, 20); memcpy(hash, c->hash, 20);
return 0; return 0;
} }

View File

@ -5,7 +5,7 @@
*/ */
#include <stdint.h> #include <stdint.h>
typedef struct sha_context { typedef struct {
uint32_t hash[5]; uint32_t hash[5];
uint32_t cnt; uint32_t cnt;
uint64_t len; uint64_t len;
@ -13,8 +13,13 @@ typedef struct sha_context {
unsigned char b[64]; unsigned char b[64];
uint64_t l[8]; uint64_t l[8];
} buf; } buf;
} SHA_CTX; } ppc_SHA_CTX;
int SHA1_Init(SHA_CTX *c); int ppc_SHA1_Init(ppc_SHA_CTX *c);
int SHA1_Update(SHA_CTX *c, const void *p, unsigned long n); int ppc_SHA1_Update(ppc_SHA_CTX *c, const void *p, unsigned long n);
int SHA1_Final(unsigned char *hash, SHA_CTX *c); int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c);
#define git_SHA_CTX ppc_SHA_CTX
#define git_SHA1_Init ppc_SHA1_Init
#define git_SHA1_Update ppc_SHA1_Update
#define git_SHA1_Final ppc_SHA1_Final

View File

@ -162,8 +162,8 @@ add RE(t),RE(t),%r0; rotlwi RB(t),RB(t),30
STEPUP4(fn, (t)+12, (s)+12,); \ STEPUP4(fn, (t)+12, (s)+12,); \
STEPUP4(fn, (t)+16, (s)+16, loadk) STEPUP4(fn, (t)+16, (s)+16, loadk)
.globl sha1_core .globl ppc_sha1_core
sha1_core: ppc_sha1_core:
stwu %r1,-80(%r1) stwu %r1,-80(%r1)
stmw %r13,4(%r1) stmw %r13,4(%r1)

View File

@ -1072,16 +1072,16 @@ struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
static int verify_hdr(struct cache_header *hdr, unsigned long size) static int verify_hdr(struct cache_header *hdr, unsigned long size)
{ {
SHA_CTX c; git_SHA_CTX c;
unsigned char sha1[20]; unsigned char sha1[20];
if (hdr->hdr_signature != htonl(CACHE_SIGNATURE)) if (hdr->hdr_signature != htonl(CACHE_SIGNATURE))
return error("bad signature"); return error("bad signature");
if (hdr->hdr_version != htonl(2)) if (hdr->hdr_version != htonl(2))
return error("bad index version"); return error("bad index version");
SHA1_Init(&c); git_SHA1_Init(&c);
SHA1_Update(&c, hdr, size - 20); git_SHA1_Update(&c, hdr, size - 20);
SHA1_Final(sha1, &c); git_SHA1_Final(sha1, &c);
if (hashcmp(sha1, (unsigned char *)hdr + size - 20)) if (hashcmp(sha1, (unsigned char *)hdr + size - 20))
return error("bad index file sha1 signature"); return error("bad index file sha1 signature");
return 0; return 0;
@ -1278,11 +1278,11 @@ int unmerged_index(const struct index_state *istate)
static unsigned char write_buffer[WRITE_BUFFER_SIZE]; static unsigned char write_buffer[WRITE_BUFFER_SIZE];
static unsigned long write_buffer_len; static unsigned long write_buffer_len;
static int ce_write_flush(SHA_CTX *context, int fd) static int ce_write_flush(git_SHA_CTX *context, int fd)
{ {
unsigned int buffered = write_buffer_len; unsigned int buffered = write_buffer_len;
if (buffered) { if (buffered) {
SHA1_Update(context, write_buffer, buffered); git_SHA1_Update(context, write_buffer, buffered);
if (write_in_full(fd, write_buffer, buffered) != buffered) if (write_in_full(fd, write_buffer, buffered) != buffered)
return -1; return -1;
write_buffer_len = 0; write_buffer_len = 0;
@ -1290,7 +1290,7 @@ static int ce_write_flush(SHA_CTX *context, int fd)
return 0; return 0;
} }
static int ce_write(SHA_CTX *context, int fd, void *data, unsigned int len) static int ce_write(git_SHA_CTX *context, int fd, void *data, unsigned int len)
{ {
while (len) { while (len) {
unsigned int buffered = write_buffer_len; unsigned int buffered = write_buffer_len;
@ -1312,7 +1312,7 @@ static int ce_write(SHA_CTX *context, int fd, void *data, unsigned int len)
return 0; return 0;
} }
static int write_index_ext_header(SHA_CTX *context, int fd, static int write_index_ext_header(git_SHA_CTX *context, int fd,
unsigned int ext, unsigned int sz) unsigned int ext, unsigned int sz)
{ {
ext = htonl(ext); ext = htonl(ext);
@ -1321,13 +1321,13 @@ static int write_index_ext_header(SHA_CTX *context, int fd,
(ce_write(context, fd, &sz, 4) < 0)) ? -1 : 0; (ce_write(context, fd, &sz, 4) < 0)) ? -1 : 0;
} }
static int ce_flush(SHA_CTX *context, int fd) static int ce_flush(git_SHA_CTX *context, int fd)
{ {
unsigned int left = write_buffer_len; unsigned int left = write_buffer_len;
if (left) { if (left) {
write_buffer_len = 0; write_buffer_len = 0;
SHA1_Update(context, write_buffer, left); git_SHA1_Update(context, write_buffer, left);
} }
/* Flush first if not enough space for SHA1 signature */ /* Flush first if not enough space for SHA1 signature */
@ -1338,7 +1338,7 @@ static int ce_flush(SHA_CTX *context, int fd)
} }
/* Append the SHA1 signature at the end */ /* Append the SHA1 signature at the end */
SHA1_Final(write_buffer + left, context); git_SHA1_Final(write_buffer + left, context);
left += 20; left += 20;
return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0; return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0;
} }
@ -1392,7 +1392,7 @@ static void ce_smudge_racily_clean_entry(struct cache_entry *ce)
} }
} }
static int ce_write_entry(SHA_CTX *c, int fd, struct cache_entry *ce) static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
{ {
int size = ondisk_ce_size(ce); int size = ondisk_ce_size(ce);
struct ondisk_cache_entry *ondisk = xcalloc(1, size); struct ondisk_cache_entry *ondisk = xcalloc(1, size);
@ -1416,7 +1416,7 @@ static int ce_write_entry(SHA_CTX *c, int fd, struct cache_entry *ce)
int write_index(const struct index_state *istate, int newfd) int write_index(const struct index_state *istate, int newfd)
{ {
SHA_CTX c; git_SHA_CTX c;
struct cache_header hdr; struct cache_header hdr;
int i, err, removed; int i, err, removed;
struct cache_entry **cache = istate->cache; struct cache_entry **cache = istate->cache;
@ -1430,7 +1430,7 @@ int write_index(const struct index_state *istate, int newfd)
hdr.hdr_version = htonl(2); hdr.hdr_version = htonl(2);
hdr.hdr_entries = htonl(entries - removed); hdr.hdr_entries = htonl(entries - removed);
SHA1_Init(&c); git_SHA1_Init(&c);
if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0) if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
return -1; return -1;

View File

@ -73,7 +73,7 @@ static int write_rr(struct string_list *rr, int out_fd)
static int handle_file(const char *path, static int handle_file(const char *path,
unsigned char *sha1, const char *output) unsigned char *sha1, const char *output)
{ {
SHA_CTX ctx; git_SHA_CTX ctx;
char buf[1024]; char buf[1024];
int hunk_no = 0; int hunk_no = 0;
enum { enum {
@ -95,7 +95,7 @@ static int handle_file(const char *path,
} }
if (sha1) if (sha1)
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
strbuf_init(&one, 0); strbuf_init(&one, 0);
strbuf_init(&two, 0); strbuf_init(&two, 0);
@ -127,9 +127,9 @@ static int handle_file(const char *path,
fputs(">>>>>>>\n", out); fputs(">>>>>>>\n", out);
} }
if (sha1) { if (sha1) {
SHA1_Update(&ctx, one.buf ? one.buf : "", git_SHA1_Update(&ctx, one.buf ? one.buf : "",
one.len + 1); one.len + 1);
SHA1_Update(&ctx, two.buf ? two.buf : "", git_SHA1_Update(&ctx, two.buf ? two.buf : "",
two.len + 1); two.len + 1);
} }
strbuf_reset(&one); strbuf_reset(&one);
@ -154,7 +154,7 @@ static int handle_file(const char *path,
if (out) if (out)
fclose(out); fclose(out);
if (sha1) if (sha1)
SHA1_Final(sha1, &ctx); git_SHA1_Final(sha1, &ctx);
if (hunk != RR_CONTEXT) { if (hunk != RR_CONTEXT) {
if (output) if (output)
unlink(output); unlink(output);

View File

@ -2132,16 +2132,16 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,
const char *type, unsigned char *sha1, const char *type, unsigned char *sha1,
char *hdr, int *hdrlen) char *hdr, int *hdrlen)
{ {
SHA_CTX c; git_SHA_CTX c;
/* Generate the header */ /* Generate the header */
*hdrlen = sprintf(hdr, "%s %lu", type, len)+1; *hdrlen = sprintf(hdr, "%s %lu", type, len)+1;
/* Sha1.. */ /* Sha1.. */
SHA1_Init(&c); git_SHA1_Init(&c);
SHA1_Update(&c, hdr, *hdrlen); git_SHA1_Update(&c, hdr, *hdrlen);
SHA1_Update(&c, buf, len); git_SHA1_Update(&c, buf, len);
SHA1_Final(sha1, &c); git_SHA1_Final(sha1, &c);
} }
/* /*

View File

@ -2,7 +2,7 @@
int main(int ac, char **av) int main(int ac, char **av)
{ {
SHA_CTX ctx; git_SHA_CTX ctx;
unsigned char sha1[20]; unsigned char sha1[20];
unsigned bufsz = 8192; unsigned bufsz = 8192;
char *buffer; char *buffer;
@ -20,7 +20,7 @@ int main(int ac, char **av)
die("OOPS"); die("OOPS");
} }
SHA1_Init(&ctx); git_SHA1_Init(&ctx);
while (1) { while (1) {
ssize_t sz, this_sz; ssize_t sz, this_sz;
@ -39,9 +39,9 @@ int main(int ac, char **av)
} }
if (this_sz == 0) if (this_sz == 0)
break; break;
SHA1_Update(&ctx, buffer, this_sz); git_SHA1_Update(&ctx, buffer, this_sz);
} }
SHA1_Final(sha1, &ctx); git_SHA1_Final(sha1, &ctx);
puts(sha1_to_hex(sha1)); puts(sha1_to_hex(sha1));
exit(0); exit(0);
} }