xref: /freebsd/stand/libsa/geli/geliboot.h (revision b3e76948)
162bd02ceSWarner Losh /*-
262bd02ceSWarner Losh  * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org>
362bd02ceSWarner Losh  * Copyright (c) 2005-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
462bd02ceSWarner Losh  * All rights reserved.
562bd02ceSWarner Losh  *
662bd02ceSWarner Losh  * Redistribution and use in source and binary forms, with or without
762bd02ceSWarner Losh  * modification, are permitted provided that the following conditions
862bd02ceSWarner Losh  * are met:
962bd02ceSWarner Losh  * 1. Redistributions of source code must retain the above copyright
1062bd02ceSWarner Losh  *    notice, this list of conditions and the following disclaimer.
1162bd02ceSWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
1262bd02ceSWarner Losh  *    notice, this list of conditions and the following disclaimer in the
1362bd02ceSWarner Losh  *    documentation and/or other materials provided with the distribution.
1462bd02ceSWarner Losh  *
1562bd02ceSWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
1662bd02ceSWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1762bd02ceSWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1862bd02ceSWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
1962bd02ceSWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2062bd02ceSWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2162bd02ceSWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2262bd02ceSWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2362bd02ceSWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2462bd02ceSWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2562bd02ceSWarner Losh  * SUCH DAMAGE.
2662bd02ceSWarner Losh  */
2762bd02ceSWarner Losh 
2862bd02ceSWarner Losh #include <crypto/intake.h>
2962bd02ceSWarner Losh 
3062bd02ceSWarner Losh #ifndef _GELIBOOT_H_
3162bd02ceSWarner Losh #define _GELIBOOT_H_
3262bd02ceSWarner Losh 
33c1418270SIan Lepore #include <geom/eli/g_eli.h>
34c1418270SIan Lepore 
3562bd02ceSWarner Losh #ifndef DEV_BSIZE
3662bd02ceSWarner Losh #define DEV_BSIZE 			512
3762bd02ceSWarner Losh #endif
3862bd02ceSWarner Losh #ifndef DEV_GELIBOOT_BSIZE
3962bd02ceSWarner Losh #define DEV_GELIBOOT_BSIZE		4096
4062bd02ceSWarner Losh #endif
4162bd02ceSWarner Losh 
4262bd02ceSWarner Losh #ifndef MIN
4362bd02ceSWarner Losh #define    MIN(a,b) (((a) < (b)) ? (a) : (b))
4462bd02ceSWarner Losh #endif
4562bd02ceSWarner Losh 
4662bd02ceSWarner Losh #define	GELI_MAX_KEYS			64
4762bd02ceSWarner Losh #define	GELI_PW_MAXLEN			256
48c1418270SIan Lepore #define	GELI_KEYBUF_SIZE		(sizeof(struct keybuf) + \
49c1418270SIan Lepore     (GELI_MAX_KEYS * sizeof(struct keybuf_ent)))
5062bd02ceSWarner Losh 
51de776da3SToomas Soome typedef enum geli_op {
52de776da3SToomas Soome 	GELI_DECRYPT,
53de776da3SToomas Soome 	GELI_ENCRYPT
54de776da3SToomas Soome } geli_op_t;
55de776da3SToomas Soome 
5662bd02ceSWarner Losh extern void pwgets(char *buf, int n, int hide);
5762bd02ceSWarner Losh 
58c1418270SIan Lepore typedef u_char geli_ukey[G_ELI_USERKEYLEN];
5962bd02ceSWarner Losh 
60c1418270SIan Lepore /*
61c1418270SIan Lepore  * An opaque struct used internally by geliboot functions. Returned by
62c1418270SIan Lepore  * geli_taste(), a pointer to one of these is essentially a device handle. There
63c1418270SIan Lepore  * is no need to release or free or "give back" the pointer.
64c1418270SIan Lepore  */
65c1418270SIan Lepore struct geli_dev;
6662bd02ceSWarner Losh 
67c1418270SIan Lepore /* Forward decls. */
68c1418270SIan Lepore struct open_file;
69c1418270SIan Lepore struct preloaded_file;
7062bd02ceSWarner Losh 
71c1418270SIan Lepore /*
72c1418270SIan Lepore  * Low-level interface, used by early-stage bootloaders...
73c1418270SIan Lepore  */
74c1418270SIan Lepore 
75c1418270SIan Lepore /* Read callback function type for geli_taste(). */
76c1418270SIan Lepore typedef int (*geli_readfunc)(void *vdev, void *readpriv, off_t offbytes,
77c1418270SIan Lepore     void *buf, size_t sizebytes);
78c1418270SIan Lepore 
79c1418270SIan Lepore struct geli_dev *geli_taste(geli_readfunc readfunc, void *readpriv,
80c1418270SIan Lepore     daddr_t lastsector, const char *namefmt, ...);
81de776da3SToomas Soome int geli_io(struct geli_dev *gdev, geli_op_t, off_t offset, u_char *buf,
82de776da3SToomas Soome     size_t bytes);
83c1418270SIan Lepore int geli_havekey(struct geli_dev *gdev);
84c1418270SIan Lepore int geli_passphrase(struct geli_dev *gdev, char *pw);
85c1418270SIan Lepore 
86c1418270SIan Lepore /*
87c1418270SIan Lepore  * Libsa device-and-file-level interface.
88c1418270SIan Lepore  */
89c1418270SIan Lepore void geli_probe_and_attach(struct open_file *f);
90c1418270SIan Lepore 
91c1418270SIan Lepore /*
92c1418270SIan Lepore  * Manage key data.
93c1418270SIan Lepore  */
94c1418270SIan Lepore void geli_add_key(geli_ukey key);
95c1418270SIan Lepore void geli_import_key_buffer(struct keybuf *keybuf);
96c1418270SIan Lepore void geli_export_key_buffer(struct keybuf *keybuf);
97c1418270SIan Lepore void geli_export_key_metadata(struct preloaded_file *kfp);
9862bd02ceSWarner Losh 
9962bd02ceSWarner Losh #endif /* _GELIBOOT_H_ */
100