summaryrefslogtreecommitdiffstats
path: root/include/blobgen.h
blob: 09a6637b778121586fb71797cc73916e252946df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (C) 2016 Pengutronix, Steffen Trumtrar <kernel@pengutronix.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __BLOBGEN_H__
#define __BLOBGEN_H__

#include <common.h>

enum access_rights {
	KERNEL,
	KERNEL_EVM,
	USERSPACE,
};

#define KEYMOD_LENGTH		16
#define MAX_BLOB_LEN		4096
#define BLOCKSIZE_BYTES		8

struct blobgen {
	struct device_d dev;
	int (*encrypt)(struct blobgen *bg, const char *modifier,
		       const void *plain, int plainsize, void *blob,
		       int *blobsize);
	int (*decrypt)(struct blobgen *bg, const char *modifier,
		       const void *blob, int blobsize, void **plain,
		       int *plainsize);

	enum access_rights access;
	unsigned int max_payload_size;

	struct list_head list;
};

int blob_gen_register(struct device_d *dev, struct blobgen *bg);

struct blobgen *blobgen_get(const char *name);

int blob_encrypt(struct blobgen *blg, const char *modifier, const void *plain,
		 int plainsize, void **blob, int *blobsize);
int blob_encrypt_to_env(struct blobgen *blg, const char *modifier,
			const void *plain, int plainsize, const char *varname);
int blob_decrypt(struct blobgen *bg, const char *modifier, const void *blob,
		 int blobsize, void **plain, int *plainsize);
int blob_decrypt_from_base64(struct blobgen *blg, const char *modifier,
			     const char *encrypted, void **plain, int *plainsize);

#endif