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 161220 2006-08-11 19:09:12Z 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 */
63#define G_ELI_VERSION 2
64
65/* ON DISK FLAGS. */
66/* Use random, onetime keys. */
67#define G_ELI_FLAG_ONETIME 0x00000001
68/* Ask for the passphrase from the kernel, before mounting root. */
69#define G_ELI_FLAG_BOOT 0x00000002
70/* Detach on last close, if we were open for writing. */
71#define G_ELI_FLAG_WO_DETACH 0x00000004
--- 151 unchanged lines hidden (view full) ---
223 MD5Init(&ctx);
224 MD5Update(&ctx, data, p - data);
225 MD5Final(md->md_hash, &ctx);
226 if (bcmp(md->md_hash, p, 16) != 0)
227 return (EINVAL);
228 return (0);
229}
230static __inline int
231eli_metadata_decode_v1v2(const u_char *data, struct g_eli_metadata *md)
232{
233 MD5_CTX ctx;
234 const u_char *p;
235
236 p = data + sizeof(md->md_magic) + sizeof(md->md_version);
237 md->md_flags = le32dec(p); p += sizeof(md->md_flags);
238 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo);
239 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen);
--- 19 unchanged lines hidden (view full) ---
259 bcopy(data, md->md_magic, sizeof(md->md_magic));
260 md->md_version = le32dec(data + sizeof(md->md_magic));
261 switch (md->md_version) {
262 case 0:
263 error = eli_metadata_decode_v0(data, md);
264 break;
265 case 1:
266 case 2:
267 error = eli_metadata_decode_v1v2(data, md);
268 break;
269 default:
270 error = EINVAL;
271 break;
272 }
273 return (error);
274}
275#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 161220 2006-08-11 19:09:12Z 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 */
63#define G_ELI_VERSION 2
64
65/* ON DISK FLAGS. */
66/* Use random, onetime keys. */
67#define G_ELI_FLAG_ONETIME 0x00000001
68/* Ask for the passphrase from the kernel, before mounting root. */
69#define G_ELI_FLAG_BOOT 0x00000002
70/* Detach on last close, if we were open for writing. */
71#define G_ELI_FLAG_WO_DETACH 0x00000004
--- 151 unchanged lines hidden (view full) ---
223 MD5Init(&ctx);
224 MD5Update(&ctx, data, p - data);
225 MD5Final(md->md_hash, &ctx);
226 if (bcmp(md->md_hash, p, 16) != 0)
227 return (EINVAL);
228 return (0);
229}
230static __inline int
231eli_metadata_decode_v1v2(const u_char *data, struct g_eli_metadata *md)
232{
233 MD5_CTX ctx;
234 const u_char *p;
235
236 p = data + sizeof(md->md_magic) + sizeof(md->md_version);
237 md->md_flags = le32dec(p); p += sizeof(md->md_flags);
238 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo);
239 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen);
--- 19 unchanged lines hidden (view full) ---
259 bcopy(data, md->md_magic, sizeof(md->md_magic));
260 md->md_version = le32dec(data + sizeof(md->md_magic));
261 switch (md->md_version) {
262 case 0:
263 error = eli_metadata_decode_v0(data, md);
264 break;
265 case 1:
266 case 2:
267 error = eli_metadata_decode_v1v2(data, md);
268 break;
269 default:
270 error = EINVAL;
271 break;
272 }
273 return (error);
274}
275#endif /* !_OpenSSL */
--- 214 unchanged lines hidden ---