summaryrefslogtreecommitdiffstats
path: root/userspace/ncrypto_masterkey.c
blob: 68c79eec55116a05e33e23f1288cca48e2f00938 (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

#include <sys/types.h>
#include <sys/ioctl.h>
#include <string.h>
#include <errno.h>
#include <linux/ncr.h>
#include "ncrypto.h"
#include "ncrypto_internal.h"

int
ncr_masterkey_set(void *key, size_t key_size)
{
	struct ncr_master_key_st io;
	memset(&io, 0, sizeof(io));

	if (!key || !key_size) {
		errno = EINVAL;
		return -1;
	}

        io.key = key = key;
        io.key_size = key_size;

	if (__ncr_file_descriptor < 0) {
		errno = EBADF;
		return -1;
	}

	if (ioctl(__ncr_file_descriptor, NCRIO_MASTER_KEY_SET, &io) < 0)
		return -1;

	return 0;
}