Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a function to compute a sha256 hash out of a buffer
Baptiste Daroussin committed 12 years ago
commit 9968ceb1f596dcb35abfd59818844dea8233e583
parent 3b61d10
2 files changed +17 -0
modified libpkg/private/utils.h
@@ -83,6 +83,7 @@ int format_exec_cmd(char **, const char *, const char *, const char *, char *);
int is_dir(const char *);
int is_conf_file(const char *path, char *newpath, size_t len);

+
int sha256_buf(char *, size_t len, char[SHA256_DIGEST_LENGTH * 2 +1]);
int sha256_file(const char *, char[SHA256_DIGEST_LENGTH * 2 +1]);
int sha256_fd(int fd, char[SHA256_DIGEST_LENGTH * 2 +1]);
int md5_file(const char *, char[MD5_DIGEST_LENGTH * 2 +1]);
modified libpkg/utils.c
@@ -350,6 +350,22 @@ sha256_file(const char *path, char out[SHA256_DIGEST_LENGTH * 2 + 1])
}

int
+
sha256_buf(char *buf, size_t len, char out[SHA256_DIGEST_LENGTH * 2 + 1])
+
{
+
	unsigned char hash[SHA256_DIGEST_LENGTH];
+
	SHA256_CTX sha256;
+

+
	out[0] = '\0';
+

+
	SHA256_Init(&sha256);
+
	SHA256_Update(&sha256, buf, len);
+
	SHA256_Final(hash, &sha256);
+
	sha256_hash(hash, out);
+

+
	return (EPKG_OK);
+
}
+

+
int
sha256_fd(int fd, char out[SHA256_DIGEST_LENGTH * 2 + 1])
{
	int my_fd = -1;