コード例 #1
0
ファイル: rsa.c プロジェクト: AlexanderThaller/pkg
static int
rsa_verify_cb(int fd, void *ud)
{
	struct rsa_verify_cbdata *cbdata = ud;
	char sha256[SHA256_DIGEST_LENGTH *2 +1];
	char errbuf[1024];
	RSA *rsa = NULL;
	int ret;

	if (sha256_fd(fd, sha256) != EPKG_OK)
		return (EPKG_FATAL);

	rsa = _load_rsa_public_key_buf(cbdata->key, cbdata->keylen);
	if (rsa == NULL)
		return(EPKG_FATAL);

	ret = RSA_verify(NID_sha1, sha256, sizeof(sha256), cbdata->sig,
			cbdata->siglen, rsa);
	if (ret == 0) {
		pkg_emit_error("%s: %s", cbdata->key,
				ERR_error_string(ERR_get_error(), errbuf));
		RSA_free(rsa);
		return (EPKG_FATAL);
	}

	RSA_free(rsa);

	return (EPKG_OK);
}
コード例 #2
0
ファイル: utils.c プロジェクト: dpl0/pkg
int
sha256_file(const char *path, char out[SHA256_DIGEST_LENGTH * 2 + 1])
{
	int fd;
	int ret;

	if ((fd = open(path, O_RDONLY)) == -1) {
		pkg_emit_errno("open", path);
		return (EPKG_FATAL);
	}

	ret = sha256_fd(fd, out);

	close(fd);

	return (ret);
}