Blame src/hash/hash_collisiondetect.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
#ifndef INCLUDE_hash_collisiondetect_h__
Packit Service 20376f
#define INCLUDE_hash_collisiondetect_h__
Packit Service 20376f
Packit Service 20376f
#include "hash.h"
Packit Service 20376f
#include "sha1dc/sha1.h"
Packit Service 20376f
Packit Service 20376f
struct git_hash_ctx {
Packit Service 20376f
	SHA1_CTX c;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#define git_hash_global_init() 0
Packit Service 20376f
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
Packit Service 20376f
#define git_hash_ctx_cleanup(ctx)
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
Packit Service 20376f
{
Packit Service 20376f
	assert(ctx);
Packit Service 20376f
	SHA1DCInit(&ctx->c);
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
Packit Service 20376f
{
Packit Service 20376f
	assert(ctx);
Packit Service 20376f
	SHA1DCUpdate(&ctx->c, data, len);
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)
Packit Service 20376f
{
Packit Service 20376f
	assert(ctx);
Packit Service 20376f
	if (SHA1DCFinal(out->id, &ctx->c)) {
Packit Service 20376f
		giterr_set(GITERR_SHA1, "SHA1 collision attack detected");
Packit Service 20376f
		return -1;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
#endif /* INCLUDE_hash_collisiondetect_h__ */