summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ncr-key.c4
-rw-r--r--ncr-sessions.c67
-rw-r--r--ncr.c28
-rw-r--r--ncr_int.h6
4 files changed, 50 insertions, 55 deletions
diff --git a/ncr-key.c b/ncr-key.c
index 4aa6a06..82a3818 100644
--- a/ncr-key.c
+++ b/ncr-key.c
@@ -443,7 +443,7 @@ size_t size;
err();
return ret;
}
- item->type = ncr_algorithm_to_key_type(algo);
+ item->type = algo->key_type;
if (item->type == NCR_KEY_TYPE_SECRET) {
/* arbitrary */
item->algorithm = _ncr_algo_to_properties(NCR_ALG_AES_CBC);
@@ -539,7 +539,7 @@ int ret;
ret = -EINVAL;
goto fail;
}
- public->type = ncr_algorithm_to_key_type(public->algorithm);
+ public->type = public->algorithm->key_type;
private->type = NCR_KEY_TYPE_PRIVATE;
public->flags |= (NCR_KEY_FLAG_EXPORTABLE|NCR_KEY_FLAG_WRAPPABLE);
diff --git a/ncr-sessions.c b/ncr-sessions.c
index e3fe411..c2cb7c3 100644
--- a/ncr-sessions.c
+++ b/ncr-sessions.c
@@ -114,51 +114,72 @@ struct session_item_st* ncr_session_new(struct list_sem_st* lst)
static const struct algo_properties_st algo_properties[] = {
{ .algo = NCR_ALG_NULL, .kstr = "ecb(cipher_null)",
- .needs_iv = 0, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 0, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_INVALID },
{ .algo = NCR_ALG_3DES_CBC, .kstr = "cbc(des3_ede)",
- .needs_iv = 1, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 1, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_AES_CBC, .kstr = "cbc(aes)",
- .needs_iv = 1, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 1, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_CAMELLIA_CBC, .kstr = "cbc(camelia)",
- .needs_iv = 1, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 1, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_AES_CTR, .kstr = "ctr(aes)",
- .needs_iv = 1, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 1, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_CAMELLIA_CTR, .kstr = "ctr(camelia)",
- .needs_iv = 1, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 1, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_ARCFOUR, .kstr = NULL,
- .needs_iv = 0, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 0, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_AES_ECB, .kstr = "ecb(aes)",
- .needs_iv = 0, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 0, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_CAMELLIA_ECB, .kstr = "ecb(camelia)",
- .needs_iv = 0, .is_symmetric=1, .can_encrypt=1 },
+ .needs_iv = 0, .is_symmetric=1, .can_encrypt=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_SHA1, .kstr = "sha1",
- .digest_size = 20, .can_digest=1 },
+ .digest_size = 20, .can_digest=1,
+ .key_type = NCR_KEY_TYPE_INVALID },
{ .algo = NCR_ALG_MD5, .kstr = "md5",
- .digest_size = 16, .can_digest=1 },
+ .digest_size = 16, .can_digest=1,
+ .key_type = NCR_KEY_TYPE_INVALID },
{ .algo = NCR_ALG_SHA2_224, .kstr = "sha224",
- .digest_size = 28, .can_digest=1 },
+ .digest_size = 28, .can_digest=1,
+ .key_type = NCR_KEY_TYPE_INVALID },
{ .algo = NCR_ALG_SHA2_256, .kstr = "sha256",
- .digest_size = 32, .can_digest=1 },
+ .digest_size = 32, .can_digest=1,
+ .key_type = NCR_KEY_TYPE_INVALID },
{ .algo = NCR_ALG_SHA2_384, .kstr = "sha384",
- .digest_size = 48, .can_digest=1 },
+ .digest_size = 48, .can_digest=1,
+ .key_type = NCR_KEY_TYPE_INVALID },
{ .algo = NCR_ALG_SHA2_512, .kstr = "sha512",
- .digest_size = 64, .can_digest=1 },
+ .digest_size = 64, .can_digest=1,
+ .key_type = NCR_KEY_TYPE_INVALID },
{ .algo = NCR_ALG_HMAC_SHA1, .is_hmac = 1, .kstr = "hmac(sha1)",
- .digest_size = 20, .can_sign=1 },
+ .digest_size = 20, .can_sign=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_HMAC_MD5, .is_hmac = 1, .kstr = "hmac(md5)",
- .digest_size = 16, .can_sign=1 },
+ .digest_size = 16, .can_sign=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_HMAC_SHA2_224, .is_hmac = 1, .kstr = "hmac(sha224)",
- .digest_size = 28, .can_sign=1 },
+ .digest_size = 28, .can_sign=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_HMAC_SHA2_256, .is_hmac = 1, .kstr = "hmac(sha256)",
- .digest_size = 32, .can_sign=1 },
+ .digest_size = 32, .can_sign=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_HMAC_SHA2_384, .is_hmac = 1, .kstr = "hmac(sha384)",
- .digest_size = 48, .can_sign=1 },
+ .digest_size = 48, .can_sign=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_HMAC_SHA2_512, .is_hmac = 1, .kstr = "hmac(sha512)",
- .digest_size = 64, .can_sign=1 },
+ .digest_size = 64, .can_sign=1,
+ .key_type = NCR_KEY_TYPE_SECRET },
{ .algo = NCR_ALG_RSA, .kstr = NULL,
- .can_encrypt=1, .can_sign=1},
+ .can_encrypt=1, .can_sign=1, .key_type = NCR_KEY_TYPE_PUBLIC },
{ .algo = NCR_ALG_DSA, .kstr = NULL,
- .can_sign=1 },
+ .can_sign=1, .key_type = NCR_KEY_TYPE_PUBLIC },
{ .algo = NCR_ALG_NONE }
};
diff --git a/ncr.c b/ncr.c
index f68a1d8..7014a30 100644
--- a/ncr.c
+++ b/ncr.c
@@ -173,31 +173,3 @@ ncr_ioctl(struct ncr_lists* lst, struct file *filp,
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(const struct algo_properties_st *algo)
-{
- switch(algo->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;
- }
-
-}
-
-
diff --git a/ncr_int.h b/ncr_int.h
index 93936ca..720fd52 100644
--- a/ncr_int.h
+++ b/ncr_int.h
@@ -20,6 +20,10 @@ struct algo_properties_st {
unsigned can_encrypt:1;
unsigned is_symmetric:1;
int digest_size;
+ /* NCR_KEY_TYPE_SECRET if for a secret key algorithm or MAC,
+ * NCR_KEY_TYPE_PUBLIC for a public key algorithm.
+ */
+ ncr_key_type_t key_type;
};
struct session_item_st {
@@ -154,8 +158,6 @@ int ncr_limits_add_and_check(uid_t uid, pid_t pid, limits_type_t type);
void ncr_limits_init(void);
void ncr_limits_deinit(void);
-ncr_key_type_t ncr_algorithm_to_key_type(const struct algo_properties_st *algo);
-
int ncr_key_wrap(struct list_sem_st* keys, struct list_sem_st* data, void __user* arg);
int ncr_key_unwrap(struct list_sem_st*, struct list_sem_st* data, void __user* arg);
int ncr_key_storage_wrap(struct list_sem_st* key_lst, struct list_sem_st* data_lst, void __user* arg);