@matheusbsbs / matheus-bagliano / commits / 9126f0091f
Fork 0

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>

Nicolas Pitre committed Oct 1, 2008 at 14:05 UTC 9126f0091f271f090cc030a788219574ab0fea97
24 files changed +162 -141
arm/sha1.c
+8 -8
@@ -8,9 +8,9 @@
8 #include <string.h>
9 #include "sha1.h"
10
11 -extern void sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
11 +extern void arm_sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
12
13 -void SHA1_Init(SHA_CTX *c)
13 +void arm_SHA1_Init(arm_SHA_CTX *c)
14 {
15 c->len = 0;
16 c->hash[0] = 0x67452301;
@@ -20,7 +20,7 @@ void SHA1_Init(SHA_CTX *c)
20 c->hash[4] = 0xc3d2e1f0;
21 }
22
23 -void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
23 +void arm_SHA1_Update(arm_SHA_CTX *c, const void *p, unsigned long n)
24 {
25 uint32_t workspace[80];
26 unsigned int partial;
@@ -32,12 +32,12 @@ void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
32 if (partial) {
33 done = 64 - partial;
34 memcpy(c->buffer + partial, p, done);
35 - sha_transform(c->hash, c->buffer, workspace);
35 + arm_sha_transform(c->hash, c->buffer, workspace);
36 partial = 0;
37 } else
38 done = 0;
39 while (n >= done + 64) {
40 - sha_transform(c->hash, p + done, workspace);
40 + arm_sha_transform(c->hash, p + done, workspace);
41 done += 64;
42 }
43 } else
@@ -46,7 +46,7 @@ void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
46 memcpy(c->buffer + partial, p + done, n - done);
47 }
48
49 -void SHA1_Final(unsigned char *hash, SHA_CTX *c)
49 +void arm_SHA1_Final(unsigned char *hash, arm_SHA_CTX *c)
50 {
51 uint64_t bitlen;
52 uint32_t bitlen_hi, bitlen_lo;
@@ -57,7 +57,7 @@ void SHA1_Final(unsigned char *hash, SHA_CTX *c)
57 bitlen = c->len << 3;
58 offset = c->len & 0x3f;
59 padlen = ((offset < 56) ? 56 : (64 + 56)) - offset;
60 - SHA1_Update(c, padding, padlen);
60 + arm_SHA1_Update(c, padding, padlen);
61
62 bitlen_hi = bitlen >> 32;
63 bitlen_lo = bitlen & 0xffffffff;
@@ -69,7 +69,7 @@ void SHA1_Final(unsigned char *hash, SHA_CTX *c)
69 bits[5] = bitlen_lo >> 16;
70 bits[6] = bitlen_lo >> 8;
71 bits[7] = bitlen_lo;
72 - SHA1_Update(c, bits, 8);
72 + arm_SHA1_Update(c, bits, 8);
73
74 for (i = 0; i < 5; i++) {
75 uint32_t v = c->hash[i];
arm/sha1.h
+10 -5
@@ -7,12 +7,17 @@
7
8 #include <stdint.h>
9
10 -typedef struct sha_context {
10 +typedef struct {
11 uint64_t len;
12 uint32_t hash[5];
13 unsigned char buffer[64];
14 -} SHA_CTX;
14 +} arm_SHA_CTX;
15
16 -void SHA1_Init(SHA_CTX *c);
17 -void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n);
18 -void SHA1_Final(unsigned char *hash, SHA_CTX *c);
16 +void arm_SHA1_Init(arm_SHA_CTX *c);
17 +void arm_SHA1_Update(arm_SHA_CTX *c, const void *p, unsigned long n);
18 +void arm_SHA1_Final(unsigned char *hash, arm_SHA_CTX *c);
19 +
20 +#define git_SHA_CTX arm_SHA_CTX
21 +#define git_SHA1_Init arm_SHA1_Init
22 +#define git_SHA1_Update arm_SHA1_Update
23 +#define git_SHA1_Final arm_SHA1_Final
arm/sha1_arm.S
+2 -2
@@ -10,7 +10,7 @@
10 */
11
12 .text
13 - .globl sha_transform
13 + .globl arm_sha_transform
14
15 /*
16 * void sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
@@ -18,7 +18,7 @@
18 * note: the "data" pointer may be unaligned.
19 */
20
21 -sha_transform:
21 +arm_sha_transform:
22
23 stmfd sp!, {r4 - r8, lr}
24
builtin-unpack-objects.c
+5 -5
@@ -19,7 +19,7 @@ static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict]
19 static unsigned char buffer[4096];
20 static unsigned int offset, len;
21 static off_t consumed_bytes;
22 -static SHA_CTX ctx;
22 +static git_SHA_CTX ctx;
23
24 /*
25 * When running under --strict mode, objects whose reachability are
@@ -59,7 +59,7 @@ static void *fill(int min)
59 if (min > sizeof(buffer))
60 die("cannot fill %d bytes", min);
61 if (offset) {
62 - SHA1_Update(&ctx, buffer, offset);
62 + git_SHA1_Update(&ctx, buffer, offset);
63 memmove(buffer, buffer + offset, len);
64 offset = 0;
65 }
@@ -539,10 +539,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
539 /* We don't take any non-flag arguments now.. Maybe some day */
540 usage(unpack_usage);
541 }
542 - SHA1_Init(&ctx);
542 + git_SHA1_Init(&ctx);
543 unpack_all();
544 - SHA1_Update(&ctx, buffer, offset);
545 - SHA1_Final(sha1, &ctx);
544 + git_SHA1_Update(&ctx, buffer, offset);
545 + git_SHA1_Final(sha1, &ctx);
546 if (strict)
547 write_rest();
548 if (hashcmp(fill(20), sha1))
cache.h
+7 -1
@@ -6,8 +6,14 @@
6 #include "hash.h"
7
8 #include SHA1_HEADER
9 -#include <zlib.h>
9 +#ifndef git_SHA_CTX
10 +#define git_SHA_CTX SHA_CTX
11 +#define git_SHA1_Init SHA1_Init
12 +#define git_SHA1_Update SHA1_Update
13 +#define git_SHA1_Final SHA1_Final
14 +#endif
15
16 +#include <zlib.h>
17 #if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
18 #define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
19 #endif
csum-file.c
+4 -4
@@ -36,11 +36,11 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
36 unsigned offset = f->offset;
37
38 if (offset) {
39 - SHA1_Update(&f->ctx, f->buffer, offset);
39 + git_SHA1_Update(&f->ctx, f->buffer, offset);
40 sha1flush(f, f->buffer, offset);
41 f->offset = 0;
42 }
43 - SHA1_Final(f->buffer, &f->ctx);
43 + git_SHA1_Final(f->buffer, &f->ctx);
44 if (result)
45 hashcpy(result, f->buffer);
46 if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
@@ -82,7 +82,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count)
82 buf = (char *) buf + nr;
83 left -= nr;
84 if (!left) {
85 - SHA1_Update(&f->ctx, data, offset);
85 + git_SHA1_Update(&f->ctx, data, offset);
86 sha1flush(f, data, offset);
87 offset = 0;
88 }
@@ -105,7 +105,7 @@ struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp
105 f->tp = tp;
106 f->name = name;
107 f->do_crc = 0;
108 - SHA1_Init(&f->ctx);
108 + git_SHA1_Init(&f->ctx);
109 return f;
110 }
111
csum-file.h
+1 -1
@@ -7,7 +7,7 @@ struct progress;
7 struct sha1file {
8 int fd;
9 unsigned int offset;
10 - SHA_CTX ctx;
10 + git_SHA_CTX ctx;
11 off_t total;
12 struct progress *tp;
13 const char *name;
diff.c
+6 -6
@@ -3087,7 +3087,7 @@ static void diff_summary(FILE *file, struct diff_filepair *p)
3087 }
3088
3089 struct patch_id_t {
3090 - SHA_CTX *ctx;
3090 + git_SHA_CTX *ctx;
3091 int patchlen;
3092 };
3093
@@ -3115,7 +3115,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
3115
3116 new_len = remove_space(line, len);
3117
3118 - SHA1_Update(data->ctx, line, new_len);
3118 + git_SHA1_Update(data->ctx, line, new_len);
3119 data->patchlen += new_len;
3120 }
3121
@@ -3124,11 +3124,11 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
3124 {
3125 struct diff_queue_struct *q = &diff_queued_diff;
3126 int i;
3127 - SHA_CTX ctx;
3127 + git_SHA_CTX ctx;
3128 struct patch_id_t data;
3129 char buffer[PATH_MAX * 4 + 20];
3130
3131 - SHA1_Init(&ctx);
3131 + git_SHA1_Init(&ctx);
3132 memset(&data, 0, sizeof(struct patch_id_t));
3133 data.ctx = &ctx;
3134
@@ -3190,7 +3190,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
3190 len2, p->two->path,
3191 len1, p->one->path,
3192 len2, p->two->path);
3193 - SHA1_Update(&ctx, buffer, len1);
3193 + git_SHA1_Update(&ctx, buffer, len1);
3194
3195 xpp.flags = XDF_NEED_MINIMAL;
3196 xecfg.ctxlen = 3;
@@ -3199,7 +3199,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
3199 &xpp, &xecfg, &ecb);
3200 }
3201
3202 - SHA1_Final(sha1, &ctx);
3202 + git_SHA1_Final(sha1, &ctx);
3203 return 0;
3204 }
3205
fast-import.c
+9 -9
@@ -845,7 +845,7 @@ static int oecmp (const void *a_, const void *b_)
845 static char *create_index(void)
846 {
847 static char tmpfile[PATH_MAX];
848 - SHA_CTX ctx;
848 + git_SHA_CTX ctx;
849 struct sha1file *f;
850 struct object_entry **idx, **c, **last, *e;
851 struct object_entry_pool *o;
@@ -882,17 +882,17 @@ static char *create_index(void)
882 idx_fd = xmkstemp(tmpfile);
883 f = sha1fd(idx_fd, tmpfile);
884 sha1write(f, array, 256 * sizeof(int));
885 - SHA1_Init(&ctx);
885 + git_SHA1_Init(&ctx);
886 for (c = idx; c != last; c++) {
887 uint32_t offset = htonl((*c)->offset);
888 sha1write(f, &offset, 4);
889 sha1write(f, (*c)->sha1, sizeof((*c)->sha1));
890 - SHA1_Update(&ctx, (*c)->sha1, 20);
890 + git_SHA1_Update(&ctx, (*c)->sha1, 20);
891 }
892 sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
893 sha1close(f, NULL, CSUM_FSYNC);
894 free(idx);
895 - SHA1_Final(pack_data->sha1, &ctx);
895 + git_SHA1_Final(pack_data->sha1, &ctx);
896 return tmpfile;
897 }
898
@@ -1033,15 +1033,15 @@ static int store_object(
1033 unsigned char hdr[96];
1034 unsigned char sha1[20];
1035 unsigned long hdrlen, deltalen;
1036 - SHA_CTX c;
1036 + git_SHA_CTX c;
1037 z_stream s;
1038
1039 hdrlen = sprintf((char*)hdr,"%s %lu", typename(type),
1040 (unsigned long)dat->len) + 1;
1041 - SHA1_Init(&c);
1042 - SHA1_Update(&c, hdr, hdrlen);
1043 - SHA1_Update(&c, dat->buf, dat->len);
1044 - SHA1_Final(sha1, &c);
1041 + git_SHA1_Init(&c);
1042 + git_SHA1_Update(&c, hdr, hdrlen);
1043 + git_SHA1_Update(&c, dat->buf, dat->len);
1044 + git_SHA1_Final(sha1, &c);
1045 if (sha1out)
1046 hashcpy(sha1out, sha1);
1047
http-push.c
+5 -5
@@ -126,7 +126,7 @@ struct transfer_request
126 char errorstr[CURL_ERROR_SIZE];
127 long http_code;
128 unsigned char real_sha1[20];
129 - SHA_CTX c;
129 + git_SHA_CTX c;
130 z_stream stream;
131 int zret;
132 int rename;
@@ -209,7 +209,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
209 request->stream.next_out = expn;
210 request->stream.avail_out = sizeof(expn);
211 request->zret = inflate(&request->stream, Z_SYNC_FLUSH);
212 - SHA1_Update(&request->c, expn,
212 + git_SHA1_Update(&request->c, expn,
213 sizeof(expn) - request->stream.avail_out);
214 } while (request->stream.avail_in && request->zret == Z_OK);
215 data_received++;
@@ -270,7 +270,7 @@ static void start_fetch_loose(struct transfer_request *request)
270
271 inflateInit(&request->stream);
272
273 - SHA1_Init(&request->c);
273 + git_SHA1_Init(&request->c);
274
275 url = xmalloc(strlen(remote->url) + 50);
276 request->url = xmalloc(strlen(remote->url) + 50);
@@ -310,7 +310,7 @@ static void start_fetch_loose(struct transfer_request *request)
310 if (prev_read == -1) {
311 memset(&request->stream, 0, sizeof(request->stream));
312 inflateInit(&request->stream);
313 - SHA1_Init(&request->c);
313 + git_SHA1_Init(&request->c);
314 if (prev_posn>0) {
315 prev_posn = 0;
316 lseek(request->local_fileno, 0, SEEK_SET);
@@ -742,7 +742,7 @@ static void finish_request(struct transfer_request *request)
742 fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
743
744 inflateEnd(&request->stream);
745 - SHA1_Final(request->real_sha1, &request->c);
745 + git_SHA1_Final(request->real_sha1, &request->c);
746 if (request->zret != Z_STREAM_END) {
747 unlink(request->tmpfile);
748 } else if (hashcmp(request->obj->sha1, request->real_sha1)) {
http-walker.c
+5 -5
@@ -36,7 +36,7 @@ struct object_request
36 char errorstr[CURL_ERROR_SIZE];
37 long http_code;
38 unsigned char real_sha1[20];
39 - SHA_CTX c;
39 + git_SHA_CTX c;
40 z_stream stream;
41 int zret;
42 int rename;
@@ -83,7 +83,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
83 obj_req->stream.next_out = expn;
84 obj_req->stream.avail_out = sizeof(expn);
85 obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH);
86 - SHA1_Update(&obj_req->c, expn,
86 + git_SHA1_Update(&obj_req->c, expn,
87 sizeof(expn) - obj_req->stream.avail_out);
88 } while (obj_req->stream.avail_in && obj_req->zret == Z_OK);
89 data_received++;
@@ -144,7 +144,7 @@ static void start_object_request(struct walker *walker,
144
145 inflateInit(&obj_req->stream);
146
147 - SHA1_Init(&obj_req->c);
147 + git_SHA1_Init(&obj_req->c);
148
149 url = xmalloc(strlen(obj_req->repo->base) + 51);
150 obj_req->url = xmalloc(strlen(obj_req->repo->base) + 51);
@@ -184,7 +184,7 @@ static void start_object_request(struct walker *walker,
184 if (prev_read == -1) {
185 memset(&obj_req->stream, 0, sizeof(obj_req->stream));
186 inflateInit(&obj_req->stream);
187 - SHA1_Init(&obj_req->c);
187 + git_SHA1_Init(&obj_req->c);
188 if (prev_posn>0) {
189 prev_posn = 0;
190 lseek(obj_req->local, 0, SEEK_SET);
@@ -244,7 +244,7 @@ static void finish_object_request(struct object_request *obj_req)
244 }
245
246 inflateEnd(&obj_req->stream);
247 - SHA1_Final(obj_req->real_sha1, &obj_req->c);
247 + git_SHA1_Final(obj_req->real_sha1, &obj_req->c);
248 if (obj_req->zret != Z_STREAM_END) {
249 unlink(obj_req->tmpfile);
250 return;
index-pack.c
+4 -4
@@ -67,7 +67,7 @@ static struct progress *progress;
67 static unsigned char input_buffer[4096];
68 static unsigned int input_offset, input_len;
69 static off_t consumed_bytes;
70 -static SHA_CTX input_ctx;
70 +static git_SHA_CTX input_ctx;
71 static uint32_t input_crc32;
72 static int input_fd, output_fd, pack_fd;
73
@@ -119,7 +119,7 @@ static void flush(void)
119 if (input_offset) {
120 if (output_fd >= 0)
121 write_or_die(output_fd, input_buffer, input_offset);
122 - SHA1_Update(&input_ctx, input_buffer, input_offset);
122 + git_SHA1_Update(&input_ctx, input_buffer, input_offset);
123 memmove(input_buffer, input_buffer + input_offset, input_len);
124 input_offset = 0;
125 }
@@ -188,7 +188,7 @@ static char *open_pack_file(char *pack_name)
188 output_fd = -1;
189 pack_fd = input_fd;
190 }
191 - SHA1_Init(&input_ctx);
191 + git_SHA1_Init(&input_ctx);
192 return pack_name;
193 }
194
@@ -588,7 +588,7 @@ static void parse_pack_objects(unsigned char *sha1)
588
589 /* Check pack integrity */
590 flush();
591 - SHA1_Final(sha1, &input_ctx);
591 + git_SHA1_Final(sha1, &input_ctx);
592 if (hashcmp(fill(20), sha1))
593 die("pack is corrupted (SHA1 mismatch)");
594 use(20);
mozilla-sha1/sha1.c
+9 -9
@@ -35,9 +35,9 @@
35
36 #include "sha1.h"
37
38 -static void shaHashBlock(SHA_CTX *ctx);
38 +static void shaHashBlock(moz_SHA_CTX *ctx);
39
40 -void SHA1_Init(SHA_CTX *ctx) {
40 +void moz_SHA1_Init(moz_SHA_CTX *ctx) {
41 int i;
42
43 ctx->lenW = 0;
@@ -56,7 +56,7 @@ void SHA1_Init(SHA_CTX *ctx) {
56 }
57
58
59 -void SHA1_Update(SHA_CTX *ctx, const void *_dataIn, int len) {
59 +void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {
60 const unsigned char *dataIn = _dataIn;
61 int i;
62
@@ -75,7 +75,7 @@ void SHA1_Update(SHA_CTX *ctx, const void *_dataIn, int len) {
75 }
76
77
78 -void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx) {
78 +void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {
79 unsigned char pad0x80 = 0x80;
80 unsigned char pad0x00 = 0x00;
81 unsigned char padlen[8];
@@ -91,10 +91,10 @@ void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx) {
91 padlen[5] = (unsigned char)((ctx->sizeLo >> 16) & 255);
92 padlen[6] = (unsigned char)((ctx->sizeLo >> 8) & 255);
93 padlen[7] = (unsigned char)((ctx->sizeLo >> 0) & 255);
94 - SHA1_Update(ctx, &pad0x80, 1);
94 + moz_SHA1_Update(ctx, &pad0x80, 1);
95 while (ctx->lenW != 56)
96 - SHA1_Update(ctx, &pad0x00, 1);
97 - SHA1_Update(ctx, padlen, 8);
96 + moz_SHA1_Update(ctx, &pad0x00, 1);
97 + moz_SHA1_Update(ctx, padlen, 8);
98
99 /* Output hash
100 */
@@ -106,13 +106,13 @@ void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx) {
106 /*
107 * Re-initialize the context (also zeroizes contents)
108 */
109 - SHA1_Init(ctx);
109 + moz_SHA1_Init(ctx);
110 }
111
112
113 #define SHA_ROT(X,n) (((X) << (n)) | ((X) >> (32-(n))))
114
115 -static void shaHashBlock(SHA_CTX *ctx) {
115 +static void shaHashBlock(moz_SHA_CTX *ctx) {
116 int t;
117 unsigned int A,B,C,D,E,TEMP;
118
mozilla-sha1/sha1.h
+9 -4
@@ -38,8 +38,13 @@ typedef struct {
38 unsigned int W[80];
39 int lenW;
40 unsigned int sizeHi,sizeLo;
41 -} SHA_CTX;
41 +} moz_SHA_CTX;
42
43 -void SHA1_Init(SHA_CTX *ctx);
44 -void SHA1_Update(SHA_CTX *ctx, const void *dataIn, int len);
45 -void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx);
43 +void moz_SHA1_Init(moz_SHA_CTX *ctx);
44 +void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int len);
45 +void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx);
46 +
47 +#define git_SHA_CTX moz_SHA_CTX
48 +#define git_SHA1_Init moz_SHA1_Init
49 +#define git_SHA1_Update moz_SHA1_Update
50 +#define git_SHA1_Final moz_SHA1_Final
pack-check.c
+8 -8
@@ -47,7 +47,7 @@ static int verify_packfile(struct packed_git *p,
47 {
48 off_t index_size = p->index_size;
49 const unsigned char *index_base = p->index_data;
50 - SHA_CTX ctx;
50 + git_SHA_CTX ctx;
51 unsigned char sha1[20], *pack_sig;
52 off_t offset = 0, pack_sig_ofs = p->pack_size - 20;
53 uint32_t nr_objects, i;
@@ -60,16 +60,16 @@ static int verify_packfile(struct packed_git *p,
60 * immediately.
61 */
62
63 - SHA1_Init(&ctx);
63 + git_SHA1_Init(&ctx);
64 while (offset < pack_sig_ofs) {
65 unsigned int remaining;
66 unsigned char *in = use_pack(p, w_curs, offset, &remaining);
67 offset += remaining;
68 if (offset > pack_sig_ofs)
69 remaining -= (unsigned int)(offset - pack_sig_ofs);
70 - SHA1_Update(&ctx, in, remaining);
70 + git_SHA1_Update(&ctx, in, remaining);
71 }
72 - SHA1_Final(sha1, &ctx);
72 + git_SHA1_Final(sha1, &ctx);
73 pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
74 if (hashcmp(sha1, pack_sig))
75 err = error("%s SHA1 checksum mismatch",
@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p)
135 {
136 off_t index_size;
137 const unsigned char *index_base;
138 - SHA_CTX ctx;
138 + git_SHA_CTX ctx;
139 unsigned char sha1[20];
140 int err = 0;
141 struct pack_window *w_curs = NULL;
@@ -146,9 +146,9 @@ int verify_pack(struct packed_git *p)
146 index_base = p->index_data;
147
148 /* Verify SHA1 sum of the index file */
149 - SHA1_Init(&ctx);
150 - SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20));
151 - SHA1_Final(sha1, &ctx);
149 + git_SHA1_Init(&ctx);
150 + git_SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20));
151 + git_SHA1_Final(sha1, &ctx);
152 if (hashcmp(sha1, index_base + index_size - 20))
153 err = error("Packfile index for %s SHA1 mismatch",
154 p->pack_name);
pack-write.c
+15 -15
@@ -25,7 +25,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
25 off_t last_obj_offset = 0;
26 uint32_t array[256];
27 int i, fd;
28 - SHA_CTX ctx;
28 + git_SHA_CTX ctx;
29 uint32_t index_version;
30
31 if (nr_objects) {
@@ -86,7 +86,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
86 sha1write(f, array, 256 * 4);
87
88 /* compute the SHA1 hash of sorted object names. */
89 - SHA1_Init(&ctx);
89 + git_SHA1_Init(&ctx);
90
91 /*
92 * Write the actual SHA1 entries..
@@ -99,7 +99,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
99 sha1write(f, &offset, 4);
100 }
101 sha1write(f, obj->sha1, 20);
102 - SHA1_Update(&ctx, obj->sha1, 20);
102 + git_SHA1_Update(&ctx, obj->sha1, 20);
103 }
104
105 if (index_version >= 2) {
@@ -140,7 +140,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
140
141 sha1write(f, sha1, 20);
142 sha1close(f, NULL, CSUM_FSYNC);
143 - SHA1_Final(sha1, &ctx);
143 + git_SHA1_Final(sha1, &ctx);
144 return index_name;
145 }
146
@@ -168,12 +168,12 @@ void fixup_pack_header_footer(int pack_fd,
168 off_t partial_pack_offset)
169 {
170 int aligned_sz, buf_sz = 8 * 1024;
171 - SHA_CTX old_sha1_ctx, new_sha1_ctx;
171 + git_SHA_CTX old_sha1_ctx, new_sha1_ctx;
172 struct pack_header hdr;
173 char *buf;
174
175 - SHA1_Init(&old_sha1_ctx);
176 - SHA1_Init(&new_sha1_ctx);
175 + git_SHA1_Init(&old_sha1_ctx);
176 + git_SHA1_Init(&new_sha1_ctx);
177
178 if (lseek(pack_fd, 0, SEEK_SET) != 0)
179 die("Failed seeking to start of %s: %s", pack_name, strerror(errno));
@@ -181,9 +181,9 @@ void fixup_pack_header_footer(int pack_fd,
181 die("Unable to reread header of %s: %s", pack_name, strerror(errno));
182 if (lseek(pack_fd, 0, SEEK_SET) != 0)
183 die("Failed seeking to start of %s: %s", pack_name, strerror(errno));
184 - SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));
184 + git_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));
185 hdr.hdr_entries = htonl(object_count);
186 - SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));
186 + git_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));
187 write_or_die(pack_fd, &hdr, sizeof(hdr));
188 partial_pack_offset -= sizeof(hdr);
189
@@ -198,7 +198,7 @@ void fixup_pack_header_footer(int pack_fd,
198 break;
199 if (n < 0)
200 die("Failed to checksum %s: %s", pack_name, strerror(errno));
201 - SHA1_Update(&new_sha1_ctx, buf, n);
201 + git_SHA1_Update(&new_sha1_ctx, buf, n);
202
203 aligned_sz -= n;
204 if (!aligned_sz)
@@ -207,11 +207,11 @@ void fixup_pack_header_footer(int pack_fd,
207 if (!partial_pack_sha1)
208 continue;
209
210 - SHA1_Update(&old_sha1_ctx, buf, n);
210 + git_SHA1_Update(&old_sha1_ctx, buf, n);
211 partial_pack_offset -= n;
212 if (partial_pack_offset == 0) {
213 unsigned char sha1[20];
214 - SHA1_Final(sha1, &old_sha1_ctx);
214 + git_SHA1_Final(sha1, &old_sha1_ctx);
215 if (hashcmp(sha1, partial_pack_sha1) != 0)
216 die("Unexpected checksum for %s "
217 "(disk corruption?)", pack_name);
@@ -220,7 +220,7 @@ void fixup_pack_header_footer(int pack_fd,
220 * pack, which also means making partial_pack_offset
221 * big enough not to matter anymore.
222 */
223 - SHA1_Init(&old_sha1_ctx);
223 + git_SHA1_Init(&old_sha1_ctx);
224 partial_pack_offset = ~partial_pack_offset;
225 partial_pack_offset -= MSB(partial_pack_offset, 1);
226 }
@@ -228,8 +228,8 @@ void fixup_pack_header_footer(int pack_fd,
228 free(buf);
229
230 if (partial_pack_sha1)
231 - SHA1_Final(partial_pack_sha1, &old_sha1_ctx);
232 - SHA1_Final(new_pack_sha1, &new_sha1_ctx);
231 + git_SHA1_Final(partial_pack_sha1, &old_sha1_ctx);
232 + git_SHA1_Final(new_pack_sha1, &new_sha1_ctx);
233 write_or_die(pack_fd, new_pack_sha1, 20);
234 fsync_or_die(pack_fd, pack_name);
235 }
patch-id.c
+6 -6
@@ -1,6 +1,6 @@
1 #include "cache.h"
2
3 -static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c)
3 +static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c)
4 {
5 unsigned char result[20];
6 char name[50];
@@ -8,10 +8,10 @@ static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c)
8 if (!patchlen)
9 return;
10
11 - SHA1_Final(result, c);
11 + git_SHA1_Final(result, c);
12 memcpy(name, sha1_to_hex(id), 41);
13 printf("%s %s\n", sha1_to_hex(result), name);
14 - SHA1_Init(c);
14 + git_SHA1_Init(c);
15 }
16
17 static int remove_space(char *line)
@@ -31,10 +31,10 @@ static void generate_id_list(void)
31 {
32 static unsigned char sha1[20];
33 static char line[1000];
34 - SHA_CTX ctx;
34 + git_SHA_CTX ctx;
35 int patchlen = 0;
36
37 - SHA1_Init(&ctx);
37 + git_SHA1_Init(&ctx);
38 while (fgets(line, sizeof(line), stdin) != NULL) {
39 unsigned char n[20];
40 char *p = line;
@@ -67,7 +67,7 @@ static void generate_id_list(void)
67 /* Compute the sha without whitespace */
68 len = remove_space(line);
69 patchlen += len;
70 - SHA1_Update(&ctx, line, len);
70 + git_SHA1_Update(&ctx, line, len);
71 }
72 flush_current_id(patchlen, sha1, &ctx);
73 }
ppc/sha1.c
+9 -9
@@ -10,10 +10,10 @@
10 #include <string.h>
11 #include "sha1.h"
12
13 -extern void sha1_core(uint32_t *hash, const unsigned char *p,
14 - unsigned int nblocks);
13 +extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,
14 + unsigned int nblocks);
15
16 -int SHA1_Init(SHA_CTX *c)
16 +int ppc_SHA1_Init(ppc_SHA_CTX *c)
17 {
18 c->hash[0] = 0x67452301;
19 c->hash[1] = 0xEFCDAB89;
@@ -25,7 +25,7 @@ int SHA1_Init(SHA_CTX *c)
25 return 0;
26 }
27
28 -int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n)
28 +int ppc_SHA1_Update(ppc_SHA_CTX *c, const void *ptr, unsigned long n)
29 {
30 unsigned long nb;
31 const unsigned char *p = ptr;
@@ -38,12 +38,12 @@ int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n)
38 nb = n;
39 memcpy(&c->buf.b[c->cnt], p, nb);
40 if ((c->cnt += nb) == 64) {
41 - sha1_core(c->hash, c->buf.b, 1);
41 + ppc_sha1_core(c->hash, c->buf.b, 1);
42 c->cnt = 0;
43 }
44 } else {
45 nb = n >> 6;
46 - sha1_core(c->hash, p, nb);
46 + ppc_sha1_core(c->hash, p, nb);
47 nb <<= 6;
48 }
49 n -= nb;
@@ -52,7 +52,7 @@ int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n)
52 return 0;
53 }
54
55 -int SHA1_Final(unsigned char *hash, SHA_CTX *c)
55 +int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c)
56 {
57 unsigned int cnt = c->cnt;
58
@@ -60,13 +60,13 @@ int SHA1_Final(unsigned char *hash, SHA_CTX *c)
60 if (cnt > 56) {
61 if (cnt < 64)
62 memset(&c->buf.b[cnt], 0, 64 - cnt);
63 - sha1_core(c->hash, c->buf.b, 1);
63 + ppc_sha1_core(c->hash, c->buf.b, 1);
64 cnt = 0;
65 }
66 if (cnt < 56)
67 memset(&c->buf.b[cnt], 0, 56 - cnt);
68 c->buf.l[7] = c->len;
69 - sha1_core(c->hash, c->buf.b, 1);
69 + ppc_sha1_core(c->hash, c->buf.b, 1);
70 memcpy(hash, c->hash, 20);
71 return 0;
72 }
ppc/sha1.h
+10 -5
@@ -5,7 +5,7 @@
5 */
6 #include <stdint.h>
7
8 -typedef struct sha_context {
8 +typedef struct {
9 uint32_t hash[5];
10 uint32_t cnt;
11 uint64_t len;
@@ -13,8 +13,13 @@ typedef struct sha_context {
13 unsigned char b[64];
14 uint64_t l[8];
15 } buf;
16 -} SHA_CTX;
16 +} ppc_SHA_CTX;
17
18 -int SHA1_Init(SHA_CTX *c);
19 -int SHA1_Update(SHA_CTX *c, const void *p, unsigned long n);
20 -int SHA1_Final(unsigned char *hash, SHA_CTX *c);
18 +int ppc_SHA1_Init(ppc_SHA_CTX *c);
19 +int ppc_SHA1_Update(ppc_SHA_CTX *c, const void *p, unsigned long n);
20 +int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c);
21 +
22 +#define git_SHA_CTX ppc_SHA_CTX
23 +#define git_SHA1_Init ppc_SHA1_Init
24 +#define git_SHA1_Update ppc_SHA1_Update
25 +#define git_SHA1_Final ppc_SHA1_Final
ppc/sha1ppc.S
+2 -2
@@ -162,8 +162,8 @@ add RE(t),RE(t),%r0; rotlwi RB(t),RB(t),30
162 STEPUP4(fn, (t)+12, (s)+12,); \
163 STEPUP4(fn, (t)+16, (s)+16, loadk)
164
165 - .globl sha1_core
166 -sha1_core:
165 + .globl ppc_sha1_core
166 +ppc_sha1_core:
167 stwu %r1,-80(%r1)
168 stmw %r13,4(%r1)
169
read-cache.c
+14 -14
@@ -1072,16 +1072,16 @@ struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
1072
1073 static int verify_hdr(struct cache_header *hdr, unsigned long size)
1074 {
1075 - SHA_CTX c;
1075 + git_SHA_CTX c;
1076 unsigned char sha1[20];
1077
1078 if (hdr->hdr_signature != htonl(CACHE_SIGNATURE))
1079 return error("bad signature");
1080 if (hdr->hdr_version != htonl(2))
1081 return error("bad index version");
1082 - SHA1_Init(&c);
1083 - SHA1_Update(&c, hdr, size - 20);
1084 - SHA1_Final(sha1, &c);
1082 + git_SHA1_Init(&c);
1083 + git_SHA1_Update(&c, hdr, size - 20);
1084 + git_SHA1_Final(sha1, &c);
1085 if (hashcmp(sha1, (unsigned char *)hdr + size - 20))
1086 return error("bad index file sha1 signature");
1087 return 0;
@@ -1278,11 +1278,11 @@ int unmerged_index(const struct index_state *istate)
1278 static unsigned char write_buffer[WRITE_BUFFER_SIZE];
1279 static unsigned long write_buffer_len;
1280
1281 -static int ce_write_flush(SHA_CTX *context, int fd)
1281 +static int ce_write_flush(git_SHA_CTX *context, int fd)
1282 {
1283 unsigned int buffered = write_buffer_len;
1284 if (buffered) {
1285 - SHA1_Update(context, write_buffer, buffered);
1285 + git_SHA1_Update(context, write_buffer, buffered);
1286 if (write_in_full(fd, write_buffer, buffered) != buffered)
1287 return -1;
1288 write_buffer_len = 0;
@@ -1290,7 +1290,7 @@ static int ce_write_flush(SHA_CTX *context, int fd)
1290 return 0;
1291 }
1292
1293 -static int ce_write(SHA_CTX *context, int fd, void *data, unsigned int len)
1293 +static int ce_write(git_SHA_CTX *context, int fd, void *data, unsigned int len)
1294 {
1295 while (len) {
1296 unsigned int buffered = write_buffer_len;
@@ -1312,7 +1312,7 @@ static int ce_write(SHA_CTX *context, int fd, void *data, unsigned int len)
1312 return 0;
1313 }
1314
1315 -static int write_index_ext_header(SHA_CTX *context, int fd,
1315 +static int write_index_ext_header(git_SHA_CTX *context, int fd,
1316 unsigned int ext, unsigned int sz)
1317 {
1318 ext = htonl(ext);
@@ -1321,13 +1321,13 @@ static int write_index_ext_header(SHA_CTX *context, int fd,
1321 (ce_write(context, fd, &sz, 4) < 0)) ? -1 : 0;
1322 }
1323
1324 -static int ce_flush(SHA_CTX *context, int fd)
1324 +static int ce_flush(git_SHA_CTX *context, int fd)
1325 {
1326 unsigned int left = write_buffer_len;
1327
1328 if (left) {
1329 write_buffer_len = 0;
1330 - SHA1_Update(context, write_buffer, left);
1330 + git_SHA1_Update(context, write_buffer, left);
1331 }
1332
1333 /* Flush first if not enough space for SHA1 signature */
@@ -1338,7 +1338,7 @@ static int ce_flush(SHA_CTX *context, int fd)
1338 }
1339
1340 /* Append the SHA1 signature at the end */
1341 - SHA1_Final(write_buffer + left, context);
1341 + git_SHA1_Final(write_buffer + left, context);
1342 left += 20;
1343 return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0;
1344 }
@@ -1392,7 +1392,7 @@ static void ce_smudge_racily_clean_entry(struct cache_entry *ce)
1392 }
1393 }
1394
1395 -static int ce_write_entry(SHA_CTX *c, int fd, struct cache_entry *ce)
1395 +static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
1396 {
1397 int size = ondisk_ce_size(ce);
1398 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)
1416
1417 int write_index(const struct index_state *istate, int newfd)
1418 {
1419 - SHA_CTX c;
1419 + git_SHA_CTX c;
1420 struct cache_header hdr;
1421 int i, err, removed;
1422 struct cache_entry **cache = istate->cache;
@@ -1430,7 +1430,7 @@ int write_index(const struct index_state *istate, int newfd)
1430 hdr.hdr_version = htonl(2);
1431 hdr.hdr_entries = htonl(entries - removed);
1432
1433 - SHA1_Init(&c);
1433 + git_SHA1_Init(&c);
1434 if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
1435 return -1;
1436
rerere.c
+5 -5
@@ -73,7 +73,7 @@ static int write_rr(struct string_list *rr, int out_fd)
73 static int handle_file(const char *path,
74 unsigned char *sha1, const char *output)
75 {
76 - SHA_CTX ctx;
76 + git_SHA_CTX ctx;
77 char buf[1024];
78 int hunk_no = 0;
79 enum {
@@ -95,7 +95,7 @@ static int handle_file(const char *path,
95 }
96
97 if (sha1)
98 - SHA1_Init(&ctx);
98 + git_SHA1_Init(&ctx);
99
100 strbuf_init(&one, 0);
101 strbuf_init(&two, 0);
@@ -127,9 +127,9 @@ static int handle_file(const char *path,
127 fputs(">>>>>>>\n", out);
128 }
129 if (sha1) {
130 - SHA1_Update(&ctx, one.buf ? one.buf : "",
130 + git_SHA1_Update(&ctx, one.buf ? one.buf : "",
131 one.len + 1);
132 - SHA1_Update(&ctx, two.buf ? two.buf : "",
132 + git_SHA1_Update(&ctx, two.buf ? two.buf : "",
133 two.len + 1);
134 }
135 strbuf_reset(&one);
@@ -154,7 +154,7 @@ static int handle_file(const char *path,
154 if (out)
155 fclose(out);
156 if (sha1)
157 - SHA1_Final(sha1, &ctx);
157 + git_SHA1_Final(sha1, &ctx);
158 if (hunk != RR_CONTEXT) {
159 if (output)
160 unlink(output);
sha1_file.c
+5 -5
@@ -2132,16 +2132,16 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,
2132 const char *type, unsigned char *sha1,
2133 char *hdr, int *hdrlen)
2134 {
2135 - SHA_CTX c;
2135 + git_SHA_CTX c;
2136
2137 /* Generate the header */
2138 *hdrlen = sprintf(hdr, "%s %lu", type, len)+1;
2139
2140 /* Sha1.. */
2141 - SHA1_Init(&c);
2142 - SHA1_Update(&c, hdr, *hdrlen);
2143 - SHA1_Update(&c, buf, len);
2144 - SHA1_Final(sha1, &c);
2141 + git_SHA1_Init(&c);
2142 + git_SHA1_Update(&c, hdr, *hdrlen);
2143 + git_SHA1_Update(&c, buf, len);
2144 + git_SHA1_Final(sha1, &c);
2145 }
2146
2147 /*
test-sha1.c
+4 -4
@@ -2,7 +2,7 @@
2
3 int main(int ac, char **av)
4 {
5 - SHA_CTX ctx;
5 + git_SHA_CTX ctx;
6 unsigned char sha1[20];
7 unsigned bufsz = 8192;
8 char *buffer;
@@ -20,7 +20,7 @@ int main(int ac, char **av)
20 die("OOPS");
21 }
22
23 - SHA1_Init(&ctx);
23 + git_SHA1_Init(&ctx);
24
25 while (1) {
26 ssize_t sz, this_sz;
@@ -39,9 +39,9 @@ int main(int ac, char **av)
39 }
40 if (this_sz == 0)
41 break;
42 - SHA1_Update(&ctx, buffer, this_sz);
42 + git_SHA1_Update(&ctx, buffer, this_sz);
43 }
44 - SHA1_Final(sha1, &ctx);
44 + git_SHA1_Final(sha1, &ctx);
45 puts(sha1_to_hex(sha1));
46 exit(0);
47 }