Deleted Added
full compact
pkcs5v2.c (302408) pkcs5v2.c (327856)
1/*-
2 * Copyright (c) 2005 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 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: stable/11/sys/geom/eli/pkcs5v2.c 293306 2016-01-07 05:47:34Z allanjude $");
28__FBSDID("$FreeBSD: stable/11/sys/geom/eli/pkcs5v2.c 327856 2018-01-12 00:31:07Z asomers $");
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#else
35#include <sys/resource.h>
36#include <stdint.h>

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

51void
52pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
53 size_t saltsize, const char *passphrase, u_int iterations)
54{
55 uint8_t md[SHA512_MDLEN], saltcount[saltsize + sizeof(uint32_t)];
56 uint8_t *counter, *keyp;
57 u_int i, bsize, passlen;
58 uint32_t count;
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#else
35#include <sys/resource.h>
36#include <stdint.h>

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

51void
52pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
53 size_t saltsize, const char *passphrase, u_int iterations)
54{
55 uint8_t md[SHA512_MDLEN], saltcount[saltsize + sizeof(uint32_t)];
56 uint8_t *counter, *keyp;
57 u_int i, bsize, passlen;
58 uint32_t count;
59 struct hmac_ctx startpoint, ctx;
59
60 passlen = strlen(passphrase);
61 bzero(key, keylen);
62 bcopy(salt, saltcount, saltsize);
63 counter = saltcount + saltsize;
64
65 keyp = key;
66 for (count = 1; keylen > 0; count++, keylen -= bsize, keyp += bsize) {
67 bsize = MIN(keylen, sizeof(md));
68
60
61 passlen = strlen(passphrase);
62 bzero(key, keylen);
63 bcopy(salt, saltcount, saltsize);
64 counter = saltcount + saltsize;
65
66 keyp = key;
67 for (count = 1; keylen > 0; count++, keylen -= bsize, keyp += bsize) {
68 bsize = MIN(keylen, sizeof(md));
69
69 counter[0] = (count >> 24) & 0xff;
70 counter[1] = (count >> 16) & 0xff;
71 counter[2] = (count >> 8) & 0xff;
72 counter[3] = count & 0xff;
73 g_eli_crypto_hmac(passphrase, passlen, saltcount,
74 sizeof(saltcount), md, 0);
70 be32enc(counter, count);
71
72 g_eli_crypto_hmac_init(&startpoint, passphrase, passlen);
73 ctx = startpoint;
74 g_eli_crypto_hmac_update(&ctx, saltcount, sizeof(saltcount));
75 g_eli_crypto_hmac_final(&ctx, md, sizeof(md));
75 xor(keyp, md, bsize);
76
77 for(i = 1; i < iterations; i++) {
76 xor(keyp, md, bsize);
77
78 for(i = 1; i < iterations; i++) {
78 g_eli_crypto_hmac(passphrase, passlen, md, sizeof(md),
79 md, 0);
79 ctx = startpoint;
80 g_eli_crypto_hmac_update(&ctx, md, sizeof(md));
81 g_eli_crypto_hmac_final(&ctx, md, sizeof(md));
80 xor(keyp, md, bsize);
81 }
82 }
82 xor(keyp, md, bsize);
83 }
84 }
85 explicit_bzero(&startpoint, sizeof(startpoint));
86 explicit_bzero(&ctx, sizeof(ctx));
83}
84
85#ifndef _KERNEL
86#ifndef _STAND
87/*
88 * Return the number of microseconds needed for 'interations' iterations.
89 */
90static int

--- 35 unchanged lines hidden ---
87}
88
89#ifndef _KERNEL
90#ifndef _STAND
91/*
92 * Return the number of microseconds needed for 'interations' iterations.
93 */
94static int

--- 35 unchanged lines hidden ---