Deleted Added
full compact
g_eli_hmac.c (213072) g_eli_hmac.c (259429)
1/*-
2 * Copyright (c) 2005-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_crypto.c 213072 2010-09-23 12:02:08Z pjd $");
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_crypto.c 259429 2013-12-15 22:52:18Z pjd $");
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/uio.h>
36#else

--- 246 unchanged lines hidden (view full) ---

283
284 SHA512_Final(digest, &ctx->shactx);
285 /* Perform outer SHA512. */
286 SHA512_Init(&lctx);
287 SHA512_Update(&lctx, ctx->k_opad, sizeof(ctx->k_opad));
288 bzero(ctx, sizeof(*ctx));
289 SHA512_Update(&lctx, digest, sizeof(digest));
290 SHA512_Final(digest, &lctx);
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/uio.h>
36#else

--- 246 unchanged lines hidden (view full) ---

283
284 SHA512_Final(digest, &ctx->shactx);
285 /* Perform outer SHA512. */
286 SHA512_Init(&lctx);
287 SHA512_Update(&lctx, ctx->k_opad, sizeof(ctx->k_opad));
288 bzero(ctx, sizeof(*ctx));
289 SHA512_Update(&lctx, digest, sizeof(digest));
290 SHA512_Final(digest, &lctx);
291 bzero(&lctx, sizeof(lctx));
291 /* mdsize == 0 means "Give me the whole hash!" */
292 if (mdsize == 0)
293 mdsize = SHA512_MDLEN;
294 bcopy(digest, md, mdsize);
292 /* mdsize == 0 means "Give me the whole hash!" */
293 if (mdsize == 0)
294 mdsize = SHA512_MDLEN;
295 bcopy(digest, md, mdsize);
296 bzero(digest, sizeof(digest));
295}
296
297void
298g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize, const uint8_t *data,
299 size_t datasize, uint8_t *md, size_t mdsize)
300{
301 struct hmac_ctx ctx;
302
303 g_eli_crypto_hmac_init(&ctx, hkey, hkeysize);
304 g_eli_crypto_hmac_update(&ctx, data, datasize);
305 g_eli_crypto_hmac_final(&ctx, md, mdsize);
306}
297}
298
299void
300g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize, const uint8_t *data,
301 size_t datasize, uint8_t *md, size_t mdsize)
302{
303 struct hmac_ctx ctx;
304
305 g_eli_crypto_hmac_init(&ctx, hkey, hkeysize);
306 g_eli_crypto_hmac_update(&ctx, data, datasize);
307 g_eli_crypto_hmac_final(&ctx, md, mdsize);
308}