summaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth
AgeCommit message (Expand)Author
2017-11-04Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netDavid S. Miller
2017-11-02License cleanup: add SPDX GPL-2.0 license identifier to files with no licenseGreg Kroah-Hartman
2017-10-30Bluetooth: hci_ldisc: Fix another race when closing the tty.Ronald Tschalär
2017-10-30Bluetooth: btusb: Fix isochronous interface assignmentsMarcel Holtmann
2017-10-30Bluetooth: btusb: Update firmware filename for Intel 9x60 and laterJaya P G
2017-10-30Bluetooth: Use bt_dev_err and bt_dev_info when possibleMarcel Holtmann
2017-10-29Bluetooth: hci_ath: Add ath_vendor_cmd helperLoic Poulain
2017-10-29Bluetooth: btusb: Add new NFA344A entry.Bartosz Chronowski
2017-10-29Bluetooth: hci_ldisc: Allow sleeping while proto locks are held.Ronald Tschalär
2017-10-14Bluetooth: mark expected switch fall-throughsGustavo A. R. Silva
2017-10-14Revert "Bluetooth: btusb: Add workaround for Broadcom devices without product...Hans de Goede
2017-10-14Bluetooth: hci_bcm: Add support for BCM2E7EHans de Goede
2017-10-14Bluetooth: btbcm: Add entry for BCM4356A2 UART bluetoothHans de Goede
2017-10-11Bluetooth: BT_HCIUART now depends on SERIAL_DEV_BUSArnd Bergmann
2017-10-11Bluetooth: hci_bcm: fix build error without CONFIG_PMArnd Bergmann
2017-10-10Bluetooth: btbcm: Add support for MINIX Z83-4 based devicesIan W MORRISON
2017-10-10Bluetooth: hci_bcm: Add support for MINIX Z83-4 based devicesIan W MORRISON
2017-10-10Bluetooth: avoid silent hci_bcm ACPI PM regressionJohan Hovold
2017-10-09Bluetooth: hci_bcm: Correct context of IRQ polarity messageIan W MORRISON
2017-10-06Bluetooth: Convert timers to use timer_setup()Kees Cook
2017-10-06Bluetooth: hci_bcm: Add (runtime)pm support to the serdev driverHans de Goede
2017-10-06Bluetooth: hci_bcm: Make suspend/resume functions platform_dev independentHans de Goede
2017-10-06Bluetooth: hci_bcm: Make acpi_probe get irq from ACPI resourcesHans de Goede
2017-10-06Bluetooth: hci_bcm: Rename bcm_platform_probe to bcm_get_resourcesHans de Goede
2017-10-06Bluetooth: hci_bcm: Store device pointer instead of platform_device pointerHans de Goede
2017-10-06Bluetooth: hci_bcm: Move platform_get_irq call to bcm_probeHans de Goede
2017-10-06Bluetooth: hci_bcm: Move bcm_platform_probe call out of bcm_acpi_probeHans de Goede
2017-10-06Bluetooth: hci_bcm: Fix setting of irq trigger typeHans de Goede
2017-10-06Bluetooth: hci_uart_set_flow_control: Fix NULL deref when using serdevHans de Goede
2017-10-06Bluetooth: btmrvl: *_err() and *_info() strings should end with newlinesArvind Yadav
2017-10-06Bluetooth: btqcomsmd: retrieve BD address from DT propertyLoic Poulain
2017-10-06Bluetooth: btqcomsmd: Add support for BD address setupLoic Poulain
2017-08-17Bluetooth: hci_bcm: Handle empty packet after firmware loadingMarcel Holtmann
2017-08-17Bluetooth: hci_bcm: Add serdev supportLoic Poulain
2017-08-17Bluetooth: btbcm: Consolidate the controller information commandsMarcel Holtmann
2017-08-16Bluetooth: hci_bcm: Use operation speed of 4Mbps only for ACPI devicesMarcel Holtmann
2017-08-16Bluetooth: btusb: driver to enable the usb-wakeup featureSukumar Ghorai
2017-08-15Bluetooth: btusb: Add workaround for Broadcom devices without product idMarcel Holtmann
2017-08-08Bluetooth: Add support of 13d3:3494 RTL8723BE deviceDmitry Tunin
2017-08-07Bluetooth: bluecard: blink LED during continuous activityOndrej Zary
2017-08-07Bluetooth: bluecard: fix LED behaviorOndrej Zary
2017-08-07Bluetooth: bluecard: Always enable LEDs (fix for Anycom CF-300)Ondrej Zary
2017-08-01Bluetooth: btusb: add ID for LiteOn 04ca:3016Brian Norris
2017-07-31Bluetooth: hci_uart: Fix uninitialized alignment valueLoic Poulain
2017-07-28Bluetooth: btrtl: Fix a error code in rtl_load_config()Dan Carpenter
2017-07-24Bluetooth: hci_nokia: select BT_BCM for btbcm_set_bdaddr()Marcel Holtmann
2017-07-24Bluetooth: btusb: Fix memory leak in play_deferredJeffy Chen
2017-07-22Bluetooth: Style fix - align block commentsDerek Robson
2017-07-20Bluetooth: btwilink: remove unnecessary static in bt_ti_probe()Gustavo A. R. Silva
2017-07-20Bluetooth: hci_ll: Use new hci_uart_unregister_device() functionIan Molton
sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* $OpenBSD: digest-openssl.c,v 1.9 2020/10/29 02:52:43 djm Exp $ */
/*
 * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "includes.h"

#ifdef WITH_OPENSSL

#include <sys/types.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

#include <openssl/evp.h>

#include "openbsd-compat/openssl-compat.h"

#include "sshbuf.h"
#include "digest.h"
#include "ssherr.h"

#ifndef HAVE_EVP_SHA256
# define EVP_sha256 NULL
#endif
#ifndef HAVE_EVP_SHA384
# define EVP_sha384 NULL
#endif
#ifndef HAVE_EVP_SHA512
# define EVP_sha512 NULL
#endif

struct ssh_digest_ctx {
	int alg;
	EVP_MD_CTX *mdctx;
};

struct ssh_digest {
	int id;
	const char *name;
	size_t digest_len;
	const EVP_MD *(*mdfunc)(void);
};

/* NB. Indexed directly by algorithm number */
const struct ssh_digest digests[] = {
	{ SSH_DIGEST_MD5,	"MD5",		16,	EVP_md5 },
	{ SSH_DIGEST_SHA1,	"SHA1",		20,	EVP_sha1 },
	{ SSH_DIGEST_SHA256,	"SHA256",	32,	EVP_sha256 },
	{ SSH_DIGEST_SHA384,	"SHA384",	48,	EVP_sha384 },
	{ SSH_DIGEST_SHA512,	"SHA512",	64,	EVP_sha512 },
	{ -1,			NULL,		0,	NULL },
};

static const struct ssh_digest *
ssh_digest_by_alg(int alg)
{
	if (alg < 0 || alg >= SSH_DIGEST_MAX)
		return NULL;
	if (digests[alg].id != alg) /* sanity */
		return NULL;
	if (digests[alg].mdfunc == NULL)
		return NULL;
	return &(digests[alg]);
}

int
ssh_digest_alg_by_name(const char *name)
{
	int alg;

	for (alg = 0; digests[alg].id != -1; alg++) {
		if (strcasecmp(name, digests[alg].name) == 0)
			return digests[alg].id;
	}
	return -1;
}

const char *
ssh_digest_alg_name(int alg)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(alg);

	return digest == NULL ? NULL : digest->name;
}

size_t
ssh_digest_bytes(int alg)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(alg);

	return digest == NULL ? 0 : digest->digest_len;
}

size_t
ssh_digest_blocksize(struct ssh_digest_ctx *ctx)
{
	return EVP_MD_CTX_block_size(ctx->mdctx);
}

struct ssh_digest_ctx *
ssh_digest_start(int alg)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(alg);
	struct ssh_digest_ctx *ret;

	if (digest == NULL || ((ret = calloc(1, sizeof(*ret))) == NULL))
		return NULL;
	ret->alg = alg;
	if ((ret->mdctx = EVP_MD_CTX_new()) == NULL) {
		free(ret);
		return NULL;
	}
	if (EVP_DigestInit_ex(ret->mdctx, digest->mdfunc(), NULL) != 1) {
		ssh_digest_free(ret);
		return NULL;
	}
	return ret;
}

int
ssh_digest_copy_state(struct ssh_digest_ctx *from, struct ssh_digest_ctx *to)
{
	if (from->alg != to->alg)
		return SSH_ERR_INVALID_ARGUMENT;
	/* we have bcopy-style order while openssl has memcpy-style */
	if (!EVP_MD_CTX_copy_ex(to->mdctx, from->mdctx))
		return SSH_ERR_LIBCRYPTO_ERROR;
	return 0;
}

int
ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
{
	if (EVP_DigestUpdate(ctx->mdctx, m, mlen) != 1)
		return SSH_ERR_LIBCRYPTO_ERROR;
	return 0;
}

int
ssh_digest_update_buffer(struct ssh_digest_ctx *ctx, const struct sshbuf *b)
{
	return ssh_digest_update(ctx, sshbuf_ptr(b), sshbuf_len(b));
}

int
ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(ctx->alg);
	u_int l = dlen;

	if (digest == NULL || dlen > UINT_MAX)
		return SSH_ERR_INVALID_ARGUMENT;
	if (dlen < digest->digest_len) /* No truncation allowed */
		return SSH_ERR_INVALID_ARGUMENT;
	if (EVP_DigestFinal_ex(ctx->mdctx, d, &l) != 1)
		return SSH_ERR_LIBCRYPTO_ERROR;
	if (l != digest->digest_len) /* sanity */
		return SSH_ERR_INTERNAL_ERROR;
	return 0;
}

void
ssh_digest_free(struct ssh_digest_ctx *ctx)
{
	if (ctx == NULL)
		return;
	EVP_MD_CTX_free(ctx->mdctx);
	freezero(ctx, sizeof(*ctx));
}

int
ssh_digest_memory(int alg, const void *m, size_t mlen, u_char *d, size_t dlen)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(alg);
	u_int mdlen;

	if (digest == NULL)
		return SSH_ERR_INVALID_ARGUMENT;
	if (dlen > UINT_MAX)
		return SSH_ERR_INVALID_ARGUMENT;
	if (dlen < digest->digest_len)
		return SSH_ERR_INVALID_ARGUMENT;
	mdlen = dlen;
	if (!EVP_Digest(m, mlen, d, &mdlen, digest->mdfunc(), NULL))
		return SSH_ERR_LIBCRYPTO_ERROR;
	return 0;
}

int
ssh_digest_buffer(int alg, const struct sshbuf *b, u_char *d, size_t dlen)
{
	return ssh_digest_memory(alg, sshbuf_ptr(b), sshbuf_len(b), d, dlen);
}
#endif /* WITH_OPENSSL */