1/*-
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 unchanged lines hidden (view full) ---
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 * $FreeBSD: head/sys/geom/eli/g_eli.h 162353 2006-09-16 10:43:17Z pjd $
27 */
28
29#ifndef _G_ELI_H_
30#define _G_ELI_H_
31
32#include <sys/endian.h>
33#include <sys/errno.h>
34#include <sys/malloc.h>
--- 19 unchanged lines hidden (view full) ---
54/*
55 * Version history:
56 * 0 - Initial version number.
57 * 1 - Added data authentication support (md_aalgo field and
58 * G_ELI_FLAG_AUTH flag).
59 * 2 - Added G_ELI_FLAG_READONLY.
60 * - IV is generated from offset converted to little-endian
61 * (flag G_ELI_FLAG_NATIVE_BYTE_ORDER will be set for older versions).
62 * 3 - Added 'configure' subcommand.
63 */
64#define G_ELI_VERSION 3
65
66/* ON DISK FLAGS. */
67/* Use random, onetime keys. */
68#define G_ELI_FLAG_ONETIME 0x00000001
69/* Ask for the passphrase from the kernel, before mounting root. */
70#define G_ELI_FLAG_BOOT 0x00000002
71/* Detach on last close, if we were open for writing. */
72#define G_ELI_FLAG_WO_DETACH 0x00000004
--- 151 unchanged lines hidden (view full) ---
224 MD5Init(&ctx);
225 MD5Update(&ctx, data, p - data);
226 MD5Final(md->md_hash, &ctx);
227 if (bcmp(md->md_hash, p, 16) != 0)
228 return (EINVAL);
229 return (0);
230}
231static __inline int
232eli_metadata_decode_v1v2v3(const u_char *data, struct g_eli_metadata *md)
233{
234 MD5_CTX ctx;
235 const u_char *p;
236
237 p = data + sizeof(md->md_magic) + sizeof(md->md_version);
238 md->md_flags = le32dec(p); p += sizeof(md->md_flags);
239 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo);
240 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen);
--- 19 unchanged lines hidden (view full) ---
260 bcopy(data, md->md_magic, sizeof(md->md_magic));
261 md->md_version = le32dec(data + sizeof(md->md_magic));
262 switch (md->md_version) {
263 case 0:
264 error = eli_metadata_decode_v0(data, md);
265 break;
266 case 1:
267 case 2:
268 case 3:
269 error = eli_metadata_decode_v1v2v3(data, md);
270 break;
271 default:
272 error = EINVAL;
273 break;
274 }
275 return (error);
276}
277#endif /* !_OpenSSL */
--- 214 unchanged lines hidden ---
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 unchanged lines hidden (view full) ---
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 * $FreeBSD: head/sys/geom/eli/g_eli.h 162353 2006-09-16 10:43:17Z pjd $
27 */
28
29#ifndef _G_ELI_H_
30#define _G_ELI_H_
31
32#include <sys/endian.h>
33#include <sys/errno.h>
34#include <sys/malloc.h>
--- 19 unchanged lines hidden (view full) ---
54/*
55 * Version history:
56 * 0 - Initial version number.
57 * 1 - Added data authentication support (md_aalgo field and
58 * G_ELI_FLAG_AUTH flag).
59 * 2 - Added G_ELI_FLAG_READONLY.
60 * - IV is generated from offset converted to little-endian
61 * (flag G_ELI_FLAG_NATIVE_BYTE_ORDER will be set for older versions).
62 * 3 - Added 'configure' subcommand.
63 */
64#define G_ELI_VERSION 3
65
66/* ON DISK FLAGS. */
67/* Use random, onetime keys. */
68#define G_ELI_FLAG_ONETIME 0x00000001
69/* Ask for the passphrase from the kernel, before mounting root. */
70#define G_ELI_FLAG_BOOT 0x00000002
71/* Detach on last close, if we were open for writing. */
72#define G_ELI_FLAG_WO_DETACH 0x00000004
--- 151 unchanged lines hidden (view full) ---
224 MD5Init(&ctx);
225 MD5Update(&ctx, data, p - data);
226 MD5Final(md->md_hash, &ctx);
227 if (bcmp(md->md_hash, p, 16) != 0)
228 return (EINVAL);
229 return (0);
230}
231static __inline int
232eli_metadata_decode_v1v2v3(const u_char *data, struct g_eli_metadata *md)
233{
234 MD5_CTX ctx;
235 const u_char *p;
236
237 p = data + sizeof(md->md_magic) + sizeof(md->md_version);
238 md->md_flags = le32dec(p); p += sizeof(md->md_flags);
239 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo);
240 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen);
--- 19 unchanged lines hidden (view full) ---
260 bcopy(data, md->md_magic, sizeof(md->md_magic));
261 md->md_version = le32dec(data + sizeof(md->md_magic));
262 switch (md->md_version) {
263 case 0:
264 error = eli_metadata_decode_v0(data, md);
265 break;
266 case 1:
267 case 2:
268 case 3:
269 error = eli_metadata_decode_v1v2v3(data, md);
270 break;
271 default:
272 error = EINVAL;
273 break;
274 }
275 return (error);
276}
277#endif /* !_OpenSSL */
--- 214 unchanged lines hidden ---