Deleted Added
full compact
g_eli_key.c (220922) g_eli_key.c (238114)
1/*-
2 * Copyright (c) 2005-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
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-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
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_key.c 220922 2011-04-21 13:31:43Z pjd $");
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_key.c 238114 2012-07-04 17:43:25Z pjd $");
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/malloc.h>
33#include <sys/systm.h>
34#include <geom/geom.h>
35#else
36#include <stdio.h>

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

192
193 /* Remember the Master Key. */
194 bcopy(mkey, sc->sc_mkey, sizeof(sc->sc_mkey));
195
196 bcopy(mkey, sc->sc_ivkey, sizeof(sc->sc_ivkey));
197 mkey += sizeof(sc->sc_ivkey);
198
199 /*
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/malloc.h>
33#include <sys/systm.h>
34#include <geom/geom.h>
35#else
36#include <stdio.h>

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

192
193 /* Remember the Master Key. */
194 bcopy(mkey, sc->sc_mkey, sizeof(sc->sc_mkey));
195
196 bcopy(mkey, sc->sc_ivkey, sizeof(sc->sc_ivkey));
197 mkey += sizeof(sc->sc_ivkey);
198
199 /*
200 * The authentication key is: akey = HMAC_SHA512(Master-Key, 0x11)
200 * The authentication key is: akey = HMAC_SHA512(Data-Key, 0x11)
201 */
202 if ((sc->sc_flags & G_ELI_FLAG_AUTH) != 0) {
203 g_eli_crypto_hmac(mkey, G_ELI_MAXKEYLEN, "\x11", 1,
204 sc->sc_akey, 0);
205 } else {
206 arc4rand(sc->sc_akey, sizeof(sc->sc_akey), 0);
207 }
208
209 /* Initialize encryption keys. */
210 g_eli_key_init(sc);
211
201 */
202 if ((sc->sc_flags & G_ELI_FLAG_AUTH) != 0) {
203 g_eli_crypto_hmac(mkey, G_ELI_MAXKEYLEN, "\x11", 1,
204 sc->sc_akey, 0);
205 } else {
206 arc4rand(sc->sc_akey, sizeof(sc->sc_akey), 0);
207 }
208
209 /* Initialize encryption keys. */
210 g_eli_key_init(sc);
211
212 if (sc->sc_flags & G_ELI_FLAG_AUTH) {
212 if ((sc->sc_flags & G_ELI_FLAG_AUTH) != 0) {
213 /*
214 * Precalculate SHA256 for HMAC key generation.
215 * This is expensive operation and we can do it only once now or
216 * for every access to sector, so now will be much better.
217 */
218 SHA256_Init(&sc->sc_akeyctx);
219 SHA256_Update(&sc->sc_akeyctx, sc->sc_akey,
220 sizeof(sc->sc_akey));

--- 17 unchanged lines hidden ---
213 /*
214 * Precalculate SHA256 for HMAC key generation.
215 * This is expensive operation and we can do it only once now or
216 * for every access to sector, so now will be much better.
217 */
218 SHA256_Init(&sc->sc_akeyctx);
219 SHA256_Update(&sc->sc_akeyctx, sc->sc_akey,
220 sizeof(sc->sc_akey));

--- 17 unchanged lines hidden ---