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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*
* New driver for /dev/crypto device (aka CryptoDev)
* Copyright (c) 2010 Nikos Mavrogiannopoulos <nmav@gnutls.org>
*
* This file is part of linux cryptodev.
*
* cryptodev is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* cryptodev 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/crypto.h>
#include <linux/mm.h>
#include <linux/highmem.h>
#include <linux/random.h>
#include "cryptodev.h"
#include <asm/uaccess.h>
#include <asm/ioctl.h>
#include <linux/scatterlist.h>
#include "ncr.h"
#include "ncr_int.h"
void* ncr_init_lists(void)
{
struct ncr_lists *lst;
lst = kmalloc(sizeof(*lst), GFP_KERNEL);
if(!lst) {
err();
return NULL;
}
memset(lst, 0, sizeof(*lst));
init_MUTEX(&lst->data.sem);
INIT_LIST_HEAD(&lst->data.list);
init_MUTEX(&lst->key.sem);
INIT_LIST_HEAD(&lst->key.list);
return lst;
}
void ncr_deinit_lists(struct ncr_lists *lst)
{
if(lst) {
ncr_data_list_deinit(&lst->data);
ncr_key_list_deinit(&lst->key);
kfree(lst);
}
}
int
ncr_ioctl(struct ncr_lists* lst, struct file *filp,
unsigned int cmd, unsigned long arg)
{
if (unlikely(!lst))
BUG();
switch (cmd) {
case NCRIO_DATA_INIT:
return ncr_data_init(filp, &lst->data, (void*)arg);
case NCRIO_DATA_GET:
return ncr_data_get(&lst->data, (void*)arg);
case NCRIO_DATA_SET:
return ncr_data_set(&lst->data, (void*)arg);
case NCRIO_DATA_DEINIT:
return ncr_data_deinit(&lst->data, (void*)arg);
case NCRIO_KEY_INIT:
return ncr_key_init(filp, &lst->key, (void*)arg);
case NCRIO_KEY_DEINIT:
return ncr_key_deinit(&lst->key, (void*)arg);
case NCRIO_KEY_GENERATE:
return ncr_key_generate(&lst->key, (void*)arg);
case NCRIO_KEY_EXPORT:
return ncr_key_export(&lst->data, &lst->key, (void*)arg);
case NCRIO_KEY_IMPORT:
return ncr_key_import(&lst->data, &lst->key, (void*)arg);
case NCRIO_KEY_GET_INFO:
return ncr_key_info(&lst->key, (void*)arg);
#if 0
case NCRIO_KEY_GENERATE_PAIR:
return ncr_key_generate_pair(&lst->key, (void*)arg);
case NCRIO_KEY_DERIVE:
return ncr_key_derive(&lst->key, (void*)arg);
case NCRIO_KEY_GET_PUBLIC:
return ncr_key_get_public(&lst->key, (void*)arg);
case NCRIO_KEY_SET_PUBLIC:
return ncr_key_set_public(&lst->key, (void*)arg);
case NCRIO_KEY_GET_PRIVATE:
return ncr_key_get_private(&lst->key, (void*)arg);
case NCRIO_KEY_SET_PRIVATE:
return ncr_key_set_private(&lst->key, (void*)arg);
#endif
default:
return -EINVAL;
}
}
/* Returns NCR_KEY_TYPE_SECRET if a secret key algorithm or MAC is given,
* and NCR_KEY_TYPE_PUBLIC if a public key algorithm is given.
*/
ncr_key_type_t ncr_algorithm_to_key_type(ncr_algorithm_t algo)
{
switch(algo) {
case NCR_ALG_3DES_CBC:
case NCR_ALG_AES_CBC:
case NCR_ALG_CAMELLIA_CBC:
case NCR_ALG_ARCFOUR:
case NCR_ALG_HMAC_SHA1:
case NCR_ALG_HMAC_MD5:
case NCR_ALG_HMAC_SHA2_224:
case NCR_ALG_HMAC_SHA2_256:
case NCR_ALG_HMAC_SHA2_384:
case NCR_ALG_HMAC_SHA2_512:
return NCR_KEY_TYPE_SECRET;
case NCR_ALG_RSA:
case NCR_ALG_DSA:
return NCR_KEY_TYPE_PUBLIC;
default:
return NCR_KEY_TYPE_INVALID;
}
}
|