commit - aaa34732674e9b84fe27a8eac7fce43f1f55d36f
commit + f05170897d7b849510231de7900a6f85653af1b7
blob - 2274686ae2246b9d7b4294fbd041ff854de59b8e
blob + 84bb15514c656e502ae8af2671a92fe155d3d7ff
--- include/got_object.h
+++ include/got_object.h
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define GOT_OBJECT_ID_HEX_MAXLEN SHA1_DIGEST_STRING_LENGTH
+#define GOT_OBJECT_ID_MAXLEN SHA256_DIGEST_LENGTH
+#define GOT_OBJECT_ID_HEX_MAXLEN SHA256_DIGEST_STRING_LENGTH
enum got_hash_algorithm {
GOT_HASH_SHA1,
};
struct got_object_id {
- u_int8_t hash[SHA1_DIGEST_LENGTH];
+ uint8_t hash[GOT_OBJECT_ID_MAXLEN];
+ enum got_hash_algorithm algo;
};
struct got_blob_object;
blob - 858b723ec18cc35148de23dbc170ed12cff46f72
blob + d91f248fe08f8bda24931834c38c29dfd8d08fd2
--- lib/hash.c
+++ lib/hash.c
got_object_id_cmp(const struct got_object_id *id1,
const struct got_object_id *id2)
{
- return memcmp(id1->hash, id2->hash, SHA1_DIGEST_LENGTH);
+ if (id1->algo != id2->algo)
+ abort();
+ return memcmp(id1->hash, id2->hash, got_hash_digest_length(id1->algo));
}
const struct got_error *
char *
got_object_id_hex(struct got_object_id *id, char *buf, size_t len)
{
- return got_sha1_digest_to_str(id->hash, buf, len);
+ if (id->algo == GOT_HASH_SHA1)
+ return got_sha1_digest_to_str(id->hash, buf, len);
+ if (id->algo == GOT_HASH_SHA256)
+ return got_sha256_digest_to_str(id->hash, buf, len);
+ abort();
}
int
enum got_hash_algorithm algo)
{
memset(id, 0, sizeof(*id));
-
- /* XXX: temporary until we grow got_object_id */
- if (algo != GOT_HASH_SHA1)
- return 0;
-
+ id->algo = algo;
return got_parse_hash_digest(id->hash, line, algo);
}
got_hash_final_object_id(struct got_hash *hash, struct got_object_id *id)
{
memset(id, 0, sizeof(*id));
+ id->algo = hash->algo;
if (hash->algo == GOT_HASH_SHA1)
SHA1Final(id->hash, &hash->sha1_ctx);
else
- abort();
+ SHA256Final(id->hash, &hash->sha256_ctx);
}
int
blob - c26d62c16a4a7b6b393af5f80b4f7e30a369c8c6
blob + 19ffa25a90493a0b5593265ee761f8231c2f40f6
--- lib/object_open_io.c
+++ lib/object_open_io.c
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
- memcpy(te->id.hash, pe->id, SHA1_DIGEST_LENGTH);
+ memcpy(te->id.hash, pe->id, pe->idlen);
+ te->id.algo = pe->algo;
te->mode = pe->mode;
te->idx = i;
}
blob - 20b5ff506329860f970e4834b4b5ec6f9d3e38f4
blob + 13da36f4db4623f60a2b68897885e715fba89ba1
--- lib/object_parse.c
+++ lib/object_parse.c
*size = 0;
*hdrlen = 0;
- got_hash_init(&ctx, GOT_HASH_SHA1);
+ got_hash_init(&ctx, expected_id->algo);
memset(&csum, 0, sizeof(csum));
csum.output_ctx = &ctx;
struct got_hash ctx;
struct got_object_id id;
- got_hash_init(&ctx, GOT_HASH_SHA1);
+ got_hash_init(&ctx, expected_id->algo);
memset(&csum, 0, sizeof(csum));
csum.output_ctx = &ctx;
/* Skip object header. */
len -= obj->hdrlen;
err = got_object_parse_commit(commit, p + obj->hdrlen, len,
- GOT_HASH_SHA1);
+ expected_id->algo);
done:
free(p);
if (obj)
struct got_hash ctx;
struct got_object_id id;
- got_hash_init(&ctx, GOT_HASH_SHA1);
+ got_hash_init(&ctx, expected_id->algo);
memset(&csum, 0, sizeof(csum));
csum.output_ctx = &ctx;
/* Skip object header. */
len -= obj->hdrlen;
err = got_object_parse_tree(entries, nentries, nentries_alloc,
- *p + obj->hdrlen, len, GOT_HASH_SHA1);
+ *p + obj->hdrlen, len, expected_id->algo);
done:
if (obj)
got_object_close(obj);
struct got_hash ctx;
struct got_object_id id;
- got_hash_init(&ctx, GOT_HASH_SHA1);
+ got_hash_init(&ctx, expected_id->algo);
memset(&csum, 0, sizeof(csum));
csum.output_ctx = &ctx;
/* Skip object header. */
len -= obj->hdrlen;
err = got_object_parse_tag(tag, p + obj->hdrlen, len,
- GOT_HASH_SHA1);
+ expected_id->algo);
done:
free(p);
if (obj)
blob - 665766db5c9d9e4c139aca134f802b112e172a7e
blob + 9d8c32aaad51cfe18240cfb06d39b674f6b6b6ac
--- lib/pack.c
+++ lib/pack.c
oid = packidx->hdr.sorted_ids + idx * digest_len;
memcpy(id->hash, oid, digest_len);
+ id->algo = packidx->algo;
return NULL;
}
if (err)
return err;
memcpy(qid->id.hash, oid, digest_len);
+ qid->id.algo = packidx->algo;
STAILQ_INSERT_TAIL(matched_ids, qid, entry);
oid = packidx->hdr.sorted_ids + (++i) * digest_len;
blob - 420df55900fae5048926e340c76737b0480284d2
blob + f709a6f1ece7b45517e779175f7eda6b5e6b513c
--- lib/pack_index.c
+++ lib/pack_index.c
oid = packidx->hdr.sorted_ids + idx * digest_len;
memcpy(oid, obj->id.hash, digest_len);
+ obj->id.algo = packidx->algo;
packidx->hdr.crc32[idx] = htobe32(obj->crc);
if (obj->off < GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX)
packidx->hdr.offsets[idx] = htobe32(obj->off);
blob - ca34316533171eaaffebc13cf14010ae8e32d87c
blob + 16b07ccae25800aac74814a8f28dc862b140de76
--- lib/privsep.c
+++ lib/privsep.c
te_name = buf + sizeof(ite);
memcpy(te->name, te_name, ite.namelen);
te->name[ite.namelen] = '\0';
- memcpy(te->id.hash, ite.id, sizeof(te->id.sha1));
+ memcpy(te->id.hash, ite.id, sizeof(te->id.hash));
+ memcpy(te->id.hash, ite.id, got_hash_digest_length(ite.algo));
+ te->id.algo = ite.algo;
te->mode = ite.mode;
te->idx = *nentries;
(*nentries)++;
blob - dca64c5b3e52082226f276cca9afe7e6a997004e
blob + d39172980ea798fa07c161a3cecc055dfc76136c
--- lib/repository.c
+++ lib/repository.c
bf = get_packidx_bloom_filter(repo, path_packidx, strlen(path_packidx));
if (bf)
- return bloom_check(bf->bloom, id->hash, sizeof(id->hash));
+ return bloom_check(bf->bloom, id->hash,
+ got_hash_digest_length(id->algo));
/* No bloom filter means this pack index must be searched. */
return 1;
blob - f70fd48fd09091b36d366da7f2e938a4cf92b691
blob + 66d664aa6393a67bea7096826a3412604ea954ef
--- lib/repository_admin.c
+++ lib/repository_admin.c
break;
}
oid = packidx->hdr.sorted_ids + i * digest_len;
+ id.algo = repo->algo;
memcpy(id.hash, oid, digest_len);
offset = got_packidx_get_object_offset(packidx, i);
memset(&id, 0, sizeof(id));
memcpy(&id.hash, pid, digest_len);
+ id.algo = repo->algo;
if (got_object_idset_contains(idset, &id))
continue;
blob - b3be4749f4694271e276c0162905dccddf9cc21d
blob + bace23fd1f0b2eb7a3e6033e9af5afea04a7d486
--- libexec/got-read-blob/got-read-blob.c
+++ libexec/got-read-blob/got-read-blob.c
struct got_inflate_checksum csum;
struct got_hash ctx;
- got_hash_init(&ctx, GOT_HASH_SHA1);
- memset(&csum, 0, sizeof(csum));
- csum.output_ctx = &ctx;
-
memset(&imsg, 0, sizeof(imsg));
memset(&imsg_outfd, 0, sizeof(imsg_outfd));
}
fd = -1;
+ got_hash_init(&ctx, expected_id.algo);
+ memset(&csum, 0, sizeof(csum));
+ csum.output_ctx = &ctx;
+
if (obj->size + obj->hdrlen <=
GOT_PRIVSEP_INLINE_BLOB_DATA_MAX) {
err = got_inflate_to_mem(&buf, &size, NULL, &csum, f);
blob - f08ec067641ea4c9b844f9d5ff590d976d692e18
blob + 5e1ec6efa75876a9ed9e5f0aea1a6975639cbbfc
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
return err;
err = got_object_parse_tree(entries, nentries, nentries_alloc,
- buf, len, GOT_HASH_SHA1);
+ buf, len, id.algo);
if (err)
goto done;
goto done;
obj->size = len;
- err = got_object_parse_tag(&tag, buf, len, GOT_HASH_SHA1);
+ err = got_object_parse_tag(&tag, buf, len, id.algo);
if (err)
goto done;
struct got_object_id id1, id2;
int idx;
- memcpy(id1.hash, pte1.id, SHA1_DIGEST_LENGTH);
+ memcpy(id1.hash, pte1.id, pte1.idlen);
+ id1.algo = pack->algo;
idx = got_packidx_get_object_idx(packidx, &id1);
if (idx == -1) {
err = got_error_no_obj(&id1);
remain1 = *len1;
memcpy(id2.hash, pte2.id, SHA1_DIGEST_LENGTH);
+ id2.algo = pack->algo;
idx = got_packidx_get_object_idx(packidx, &id2);
if (idx == -1) {
err = got_error_no_obj(&id2);
err = got_object_qid_alloc_partial(&eqid);
if (err)
goto done;
+ eqid->id.algo = pte->algo;
memcpy(eqid->id.hash, pte->id, sizeof(eqid->id.hash));
if (got_object_idset_contains(idset, &eqid->id)) {
goto done;
obj->size = len;
err = got_object_parse_tag(&tag, buf, len,
- GOT_HASH_SHA1);
+ qid->id.algo);
if (err) {
free(buf);
goto done;