summaryrefslogtreecommitdiffstats
path: root/crypto/userspace/ncr-key-storage.c
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-08-27 09:40:53 +0200
committerMiloslav Trmač <mitr@redhat.com>2010-08-27 09:44:36 +0200
commit5d08c95e8a0101f156cf1afe8b2fae8487d1cfce (patch)
tree2510e52b0992afb90b3a9a86ce07b8a2fd26f6f4 /crypto/userspace/ncr-key-storage.c
parentd5d46ca491d8974ac1eaf7bad3d69e468e49dc34 (diff)
parent9cab3a1a9660ed5f798b063aa7e827eb0c95ba94 (diff)
downloadkernel-crypto-5d08c95e8a0101f156cf1afe8b2fae8487d1cfce.tar.gz
kernel-crypto-5d08c95e8a0101f156cf1afe8b2fae8487d1cfce.tar.xz
kernel-crypto-5d08c95e8a0101f156cf1afe8b2fae8487d1cfce.zip
Merge branch 'standalone-rename' into userspace-crypto
Conflicts: .gitignore crypto/userspace/Makefile crypto/userspace/cryptodev_int.h crypto/userspace/ncr-key-wrap.c crypto/userspace/ncr-key.c crypto/userspace/ncr-pk.c crypto/userspace/ncr-sessions.c crypto/userspace/ncr.c include/linux/cryptodev.h
Diffstat (limited to 'crypto/userspace/ncr-key-storage.c')
-rw-r--r--crypto/userspace/ncr-key-storage.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/crypto/userspace/ncr-key-storage.c b/crypto/userspace/ncr-key-storage.c
index 0db4eeddfff..4d0cb872153 100644
--- a/crypto/userspace/ncr-key-storage.c
+++ b/crypto/userspace/ncr-key-storage.c
@@ -32,9 +32,10 @@
#include "cryptodev_int.h"
struct packed_key {
+ uint32_t version;
uint8_t type;
uint32_t flags;
- uint16_t algorithm; /* valid for public/private keys */
+ uint8_t algorithm[32]; /* NUL-terminated */
uint8_t key_id[MAX_KEY_ID_SIZE];
uint8_t key_id_size;
@@ -42,6 +43,8 @@ struct packed_key {
uint32_t raw_size;
} __attribute__((__packed__));
+#define THIS_VERSION 1
+
int key_to_storage_data( uint8_t** sdata, size_t * sdata_size, const struct key_item_st *key)
{
struct packed_key * pkey;
@@ -53,9 +56,11 @@ int key_to_storage_data( uint8_t** sdata, size_t * sdata_size, const struct key_
return -ENOMEM;
}
+ pkey->version = THIS_VERSION;
pkey->type = key->type;
pkey->flags = key->flags;
- pkey->algorithm = key->algorithm->algo;
+ BUG_ON(strlen(key->algorithm->kstr) > sizeof(pkey->algorithm) - 1);
+ strcpy(pkey->algorithm, key->algorithm->kstr);
pkey->key_id_size = key->key_id_size;
memcpy(pkey->key_id, key->key_id, key->key_id_size);
@@ -90,7 +95,9 @@ int key_from_storage_data(struct key_item_st* key, const void* data, size_t data
const struct packed_key * pkey = data;
int ret;
- if (data_size != sizeof(*pkey) || pkey->key_id_size > MAX_KEY_ID_SIZE) {
+ if (data_size != sizeof(*pkey) || pkey->version != THIS_VERSION
+ || memchr(pkey->algorithm, '\0', sizeof(pkey->algorithm)) == NULL
+ || pkey->key_id_size > MAX_KEY_ID_SIZE) {
err();
return -EINVAL;
}