xref: /freebsd/stand/libsa/geli/geli_metadata.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1c1418270SIan Lepore /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3c1418270SIan Lepore  *
4c1418270SIan Lepore  * Copyright (c) 2018 Ian Lepore <ian@FreeBSD.org>
5c1418270SIan Lepore  *
6c1418270SIan Lepore  * Redistribution and use in source and binary forms, with or without
7c1418270SIan Lepore  * modification, are permitted provided that the following conditions
8c1418270SIan Lepore  * are met:
9c1418270SIan Lepore  * 1. Redistributions of source code must retain the above copyright
10c1418270SIan Lepore  *    notice, this list of conditions and the following disclaimer.
11c1418270SIan Lepore  * 2. Redistributions in binary form must reproduce the above copyright
12c1418270SIan Lepore  *    notice, this list of conditions and the following disclaimer in the
13c1418270SIan Lepore  *    documentation and/or other materials provided with the distribution.
14c1418270SIan Lepore  *
15c1418270SIan Lepore  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16c1418270SIan Lepore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17c1418270SIan Lepore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18c1418270SIan Lepore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19c1418270SIan Lepore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20c1418270SIan Lepore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21c1418270SIan Lepore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22c1418270SIan Lepore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23c1418270SIan Lepore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24c1418270SIan Lepore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25c1418270SIan Lepore  * SUCH DAMAGE.
26c1418270SIan Lepore  */
27c1418270SIan Lepore 
28c1418270SIan Lepore #include <stand.h>
29c1418270SIan Lepore #include <bootstrap.h>
30c1418270SIan Lepore #include <sys/param.h>
31c1418270SIan Lepore #include <sys/linker.h>
32c1418270SIan Lepore #include "geliboot.h"
33c1418270SIan Lepore 
34c1418270SIan Lepore /*
35c1418270SIan Lepore  * Export a keybuf as metadata attached to a kernel module.  This is separate
36c1418270SIan Lepore  * from the lower-level key management functions to avoid creating a linker
37c1418270SIan Lepore  * dependency on the libsa metadata routines when the geli code is linked into
38c1418270SIan Lepore  * early-stage bootloaders such as gptboot.  Only loader(8) variants call this.
39c1418270SIan Lepore  */
40c1418270SIan Lepore void
geli_export_key_metadata(struct preloaded_file * kfp)41c1418270SIan Lepore geli_export_key_metadata(struct preloaded_file *kfp)
42c1418270SIan Lepore {
43c1418270SIan Lepore     struct keybuf *keybuf;
44c1418270SIan Lepore 
45c1418270SIan Lepore     keybuf = malloc(GELI_KEYBUF_SIZE);
46c1418270SIan Lepore     geli_export_key_buffer(keybuf);
47c1418270SIan Lepore     file_addmetadata(kfp, MODINFOMD_KEYBUF, GELI_KEYBUF_SIZE, keybuf);
48c1418270SIan Lepore     explicit_bzero(keybuf, GELI_KEYBUF_SIZE);
49c1418270SIan Lepore     free(keybuf);
50c1418270SIan Lepore }
51