g_eli.c (161127) | g_eli.c (161220) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2005 Pawel Jakub Dawidek | 2 * Copyright (c) 2005-2006 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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 9 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> | 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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 9 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.c 161127 2006-08-09 18:11:14Z pjd $"); | 28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli.c 161220 2006-08-11 19:09:12Z pjd $"); |
29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/linker.h> 34#include <sys/module.h> 35#include <sys/lock.h> 36#include <sys/mutex.h> --- 323 unchanged lines hidden (view full) --- 360 361/* 362 * Here we generate IV. It is unique for every sector. 363 */ 364void 365g_eli_crypto_ivgen(struct g_eli_softc *sc, off_t offset, u_char *iv, 366 size_t size) 367{ | 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/linker.h> 34#include <sys/module.h> 35#include <sys/lock.h> 36#include <sys/mutex.h> --- 323 unchanged lines hidden (view full) --- 360 361/* 362 * Here we generate IV. It is unique for every sector. 363 */ 364void 365g_eli_crypto_ivgen(struct g_eli_softc *sc, off_t offset, u_char *iv, 366 size_t size) 367{ |
368 u_char hash[SHA256_DIGEST_LENGTH]; | 368 u_char off[8], hash[SHA256_DIGEST_LENGTH]; |
369 SHA256_CTX ctx; 370 | 369 SHA256_CTX ctx; 370 |
371 if (!(sc->sc_flags & G_ELI_FLAG_NATIVE_BYTE_ORDER)) 372 le64enc(off, (uint64_t)offset); |
|
371 /* Copy precalculated SHA256 context for IV-Key. */ 372 bcopy(&sc->sc_ivctx, &ctx, sizeof(ctx)); 373 SHA256_Update(&ctx, (uint8_t *)&offset, sizeof(offset)); 374 SHA256_Final(hash, &ctx); 375 bcopy(hash, iv, size); 376} 377 378int --- 131 unchanged lines hidden (view full) --- 510 */ 511 if (md->md_flags & (G_ELI_FLAG_WO_DETACH | G_ELI_FLAG_RO)) 512 gp->access = g_eli_access; 513 else 514 gp->access = g_std_access; 515 516 sc->sc_crypto = G_ELI_CRYPTO_SW; 517 sc->sc_flags = md->md_flags; | 373 /* Copy precalculated SHA256 context for IV-Key. */ 374 bcopy(&sc->sc_ivctx, &ctx, sizeof(ctx)); 375 SHA256_Update(&ctx, (uint8_t *)&offset, sizeof(offset)); 376 SHA256_Final(hash, &ctx); 377 bcopy(hash, iv, size); 378} 379 380int --- 131 unchanged lines hidden (view full) --- 512 */ 513 if (md->md_flags & (G_ELI_FLAG_WO_DETACH | G_ELI_FLAG_RO)) 514 gp->access = g_eli_access; 515 else 516 gp->access = g_std_access; 517 518 sc->sc_crypto = G_ELI_CRYPTO_SW; 519 sc->sc_flags = md->md_flags; |
520 /* Backward compatibility. */ 521 if (md->md_version < 2) 522 sc->sc_flags |= G_ELI_FLAG_NATIVE_BYTE_ORDER; |
|
518 sc->sc_ealgo = md->md_ealgo; 519 sc->sc_nkey = nkey; 520 /* 521 * Remember the keys in our softc structure. 522 */ 523 g_eli_mkey_propagate(sc, mkey); 524 sc->sc_ekeylen = md->md_keylen; 525 --- 468 unchanged lines hidden (view full) --- 994 if (sc->sc_flags & (flag)) { \ 995 if (!first) \ 996 sbuf_printf(sb, ", "); \ 997 else \ 998 first = 0; \ 999 sbuf_printf(sb, name); \ 1000 } \ 1001} while (0) | 523 sc->sc_ealgo = md->md_ealgo; 524 sc->sc_nkey = nkey; 525 /* 526 * Remember the keys in our softc structure. 527 */ 528 g_eli_mkey_propagate(sc, mkey); 529 sc->sc_ekeylen = md->md_keylen; 530 --- 468 unchanged lines hidden (view full) --- 999 if (sc->sc_flags & (flag)) { \ 1000 if (!first) \ 1001 sbuf_printf(sb, ", "); \ 1002 else \ 1003 first = 0; \ 1004 sbuf_printf(sb, name); \ 1005 } \ 1006} while (0) |
1007 ADD_FLAG(G_ELI_FLAG_NATIVE_BYTE_ORDER, "NATIVE-BYTE-ORDER"); |
|
1002 ADD_FLAG(G_ELI_FLAG_ONETIME, "ONETIME"); 1003 ADD_FLAG(G_ELI_FLAG_BOOT, "BOOT"); 1004 ADD_FLAG(G_ELI_FLAG_WO_DETACH, "W-DETACH"); 1005 ADD_FLAG(G_ELI_FLAG_RW_DETACH, "RW-DETACH"); 1006 ADD_FLAG(G_ELI_FLAG_AUTH, "AUTH"); 1007 ADD_FLAG(G_ELI_FLAG_WOPEN, "W-OPEN"); 1008 ADD_FLAG(G_ELI_FLAG_DESTROY, "DESTROY"); 1009 ADD_FLAG(G_ELI_FLAG_RO, "READ-ONLY"); --- 34 unchanged lines hidden --- | 1008 ADD_FLAG(G_ELI_FLAG_ONETIME, "ONETIME"); 1009 ADD_FLAG(G_ELI_FLAG_BOOT, "BOOT"); 1010 ADD_FLAG(G_ELI_FLAG_WO_DETACH, "W-DETACH"); 1011 ADD_FLAG(G_ELI_FLAG_RW_DETACH, "RW-DETACH"); 1012 ADD_FLAG(G_ELI_FLAG_AUTH, "AUTH"); 1013 ADD_FLAG(G_ELI_FLAG_WOPEN, "W-OPEN"); 1014 ADD_FLAG(G_ELI_FLAG_DESTROY, "DESTROY"); 1015 ADD_FLAG(G_ELI_FLAG_RO, "READ-ONLY"); --- 34 unchanged lines hidden --- |