/*-1* Copyright (c) 2015 Allan Jude <[email protected]>2* Copyright (c) 2005-2011 Pawel Jakub Dawidek <[email protected]>3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include <crypto/intake.h>2829#ifndef _GELIBOOT_H_30#define _GELIBOOT_H_3132#include <geom/eli/g_eli.h>3334#ifndef DEV_BSIZE35#define DEV_BSIZE 51236#endif37#ifndef DEV_GELIBOOT_BSIZE38#define DEV_GELIBOOT_BSIZE 409639#endif4041#ifndef MIN42#define MIN(a,b) (((a) < (b)) ? (a) : (b))43#endif4445#define GELI_MAX_KEYS 6446#define GELI_PW_MAXLEN 25647#define GELI_KEYBUF_SIZE (sizeof(struct keybuf) + \48(GELI_MAX_KEYS * sizeof(struct keybuf_ent)))4950typedef enum geli_op {51GELI_DECRYPT,52GELI_ENCRYPT53} geli_op_t;5455extern void pwgets(char *buf, int n, int hide);5657typedef u_char geli_ukey[G_ELI_USERKEYLEN];5859/*60* An opaque struct used internally by geliboot functions. Returned by61* geli_taste(), a pointer to one of these is essentially a device handle. There62* is no need to release or free or "give back" the pointer.63*/64struct geli_dev;6566/* Forward decls. */67struct open_file;68struct preloaded_file;6970/*71* Low-level interface, used by early-stage bootloaders...72*/7374/* Read callback function type for geli_taste(). */75typedef int (*geli_readfunc)(void *vdev, void *readpriv, off_t offbytes,76void *buf, size_t sizebytes);7778struct geli_dev *geli_taste(geli_readfunc readfunc, void *readpriv,79daddr_t lastsector, const char *namefmt, ...);80int geli_io(struct geli_dev *gdev, geli_op_t, off_t offset, u_char *buf,81size_t bytes);82int geli_havekey(struct geli_dev *gdev);83int geli_passphrase(struct geli_dev *gdev, char *pw);8485/*86* Libsa device-and-file-level interface.87*/88void geli_probe_and_attach(struct open_file *f);8990/*91* Manage key data.92*/93void geli_add_key(geli_ukey key);94void geli_import_key_buffer(struct keybuf *keybuf);95void geli_export_key_buffer(struct keybuf *keybuf);96void geli_export_key_metadata(struct preloaded_file *kfp);9798#endif /* _GELIBOOT_H_ */99100101