コード例 #1
0
ファイル: socket.c プロジェクト: mysidia/snservices1
int socket_init(int maxfds)
{
	int	n;
	_socket_fds = maxfds;

	if (maxfds < 1)
	{
		return -1;
	}
	fds = (sock **) irc_malloc(sizeof(sock *) * maxfds);
	if (fds == NULL)
	{
		return -1;
	}
	n = _socket_init();
	if (n != 0)
	{
		return -1;
	}
	config_monitor("network/maxfds", conf_fds, CONFIG_SINGLE);
	config_monitor("network/address", conf_address, CONFIG_SINGLE);
	config_monitor("network/address6", conf_address6, CONFIG_SINGLE);
#ifdef HAVE_SSL
	SSL_load_error_strings();
	SSLeay_add_ssl_algorithms();
	ctx = SSL_CTX_new (SSLv23_method());
	if (!ctx)
	{
		return 0;
	}
	config_monitor("network/ssl", conf_ssl, CONFIG_SINGLE);
#endif
	return 0;
}
コード例 #2
0
ファイル: crypto_kernel.c プロジェクト: meh/cryptsetup
int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
		    const void *buffer, size_t length)
{
	struct crypt_hmac *h;
	struct hash_alg *ha;
	struct sockaddr_alg sa = {
		.salg_family = AF_ALG,
		.salg_type = "hash",
	};

	h = malloc(sizeof(*h));
	if (!h)
		return -ENOMEM;

	ha = _get_alg(name);
	if (!ha) {
		free(h);
		return -EINVAL;
	}
	h->hash_len = ha->length;

	snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
		 "hmac(%s)", ha->kernel_name);

	if (_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
		free(h);
		return -EINVAL;
	}

	if (setsockopt(h->tfmfd, SOL_ALG, ALG_SET_KEY, buffer, length) == -1) {
		crypt_hmac_destroy(h);
		return -EINVAL;
	}

	*ctx = h;
	return 0;
}

int crypt_hmac_restart(struct crypt_hmac *ctx)
{
	return 0;
}

int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
{
	ssize_t r;

	r = send(ctx->opfd, buffer, length, MSG_MORE);
	if (r < 0 || (size_t)r < length)
		return -EIO;

	return 0;
}
コード例 #3
0
int crypt_backend_init(struct crypt_device *ctx)
{
	struct utsname uts;

	struct sockaddr_alg sa = {
		.salg_family = AF_ALG,
		.salg_type = "hash",
		.salg_name = "sha1",
	};
	int tfmfd = -1, opfd = -1;

	if (crypto_backend_initialised)
		return 0;

	log_dbg("Initialising kernel crypto API backend.");

	if (uname(&uts) == -1 || strcmp(uts.sysname, "Linux"))
		return -EINVAL;
	log_dbg("Kernel version %s %s.", uts.sysname, uts.release);

	if (_socket_init(&sa, &tfmfd, &opfd) < 0)
		return -EINVAL;

	close(tfmfd);
	close(opfd);

	crypto_backend_initialised = 1;
	return 0;
}

uint32_t crypt_backend_flags(void)
{
	return CRYPT_BACKEND_KERNEL;
}

static struct hash_alg *_get_alg(const char *name)
{
	int i = 0;

	while (name && hash_algs[i].name) {
		if (!strcmp(name, hash_algs[i].name))
			return &hash_algs[i];
		i++;
	}
	return NULL;
}
コード例 #4
0
ファイル: crypto_kernel.c プロジェクト: meh/cryptsetup
int crypt_hash_init(struct crypt_hash **ctx, const char *name)
{
	struct crypt_hash *h;
	struct hash_alg *ha;
	struct sockaddr_alg sa = {
		.salg_family = AF_ALG,
		.salg_type = "hash",
	};

	h = malloc(sizeof(*h));
	if (!h)
		return -ENOMEM;

	ha = _get_alg(name);
	if (!ha) {
		free(h);
		return -EINVAL;
	}
	h->hash_len = ha->length;

	strncpy((char *)sa.salg_name, ha->kernel_name, sizeof(sa.salg_name));

	if (_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
		free(h);
		return -EINVAL;
	}

	*ctx = h;
	return 0;
}

int crypt_hash_restart(struct crypt_hash *ctx)
{
	return 0;
}

int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
{
	ssize_t r;

	r = send(ctx->opfd, buffer, length, MSG_MORE);
	if (r < 0 || (size_t)r < length)
		return -EIO;

	return 0;
}