summaryrefstree
path: root/kernel/include/sdp/pub_crypto_emul.h
blob: c039ffed68c79e4a1b1142f6a8d0b0f4fc0d4f75 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * Sensitive Data Protection
 *
 * 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 _FIPS_CRYPTO_H
#define _FIPS_CRYPTO_H

#include <sdp/dek_common.h>

#include <linux/list.h>
#include <linux/wait.h>
#include <linux/spinlock.h>

#define OP_RSA_ENC 10
#define OP_RSA_DEC 11
#define OP_DH_DEC 12
#define OP_DH_ENC 13
#define OP_ECDH_DEC 14
#define OP_ECDH_ENC 15
#define OP_ECDH_REQ_SS 16

#define PUB_CRYPTO_ERROR 99

typedef struct __cipher_param {
	u32 request_id;
	u8 opcode;
	dek_t in;
	kek_t key;
} cipher_param_t;

typedef struct result {
	u32 request_id;
	u8 opcode;
	s16 ret;
	dek_t dek;
} result_t;

/** The request state */
enum req_state {
	PUB_CRYPTO_REQ_INIT = 0,
	PUB_CRYPTO_REQ_PENDING,
	PUB_CRYPTO_REQ_FINISHED
};

typedef struct pub_crypto_contorl {
	struct list_head pending_list;
	//wait_queue_head_t waitq;
	spinlock_t lock;

	/** The next unique request id */
	u32 reqctr;
} pub_crypto_control_t;

typedef struct pub_crypto_request {
	u32 id;
	u8 opcode;

	struct list_head list;
	/** refcount */
	atomic_t count;

	wait_queue_head_t waitq;

	enum req_state state;

	cipher_param_t cipher_param;

	result_t result;

	/** The request was aborted */
	u8 aborted;
} pub_crypto_request_t;

int rsa_encryptByPub(dek_t *dek, dek_t *edek, kek_t *key);
int rsa_decryptByPair(dek_t *edek, dek_t *dek, kek_t *key);
int dh_decryptEDEK(dek_t *edek, dek_t *dek, kek_t *key);
int dh_encryptDEK(dek_t *dek, dek_t *edek, kek_t *key);
int ecdh_decryptEDEK(dek_t *edek, dek_t *dek, kek_t *key);
int ecdh_encryptDEK(dek_t *dek, dek_t *edek, kek_t *key);
int ecdh_deriveSS(dek_t *in, dek_t *out, kek_t *drv_key);
#endif