From 7a31387b49e0b04ba43bdf6fbc869c6a3e970251 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 28 Jul 2010 20:26:44 +0200 Subject: NCR_CIPHER_MAX_KEY_LEN no longer exist in userspace API. --- TODO | 1 + ncr-int.h | 1 + ncr.c | 7 +++++-- ncr.h | 3 +-- userspace/setkey.c | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 5ed80e1..98b81fc 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ * ioctl_compat() mode for ncr.h API as it is in cryptodev.h * Put limits to sessions * Export private keys to PKCS #8 format (can it be implemented?) +* Documentation for functions diff --git a/ncr-int.h b/ncr-int.h index 489e052..e79747c 100644 --- a/ncr-int.h +++ b/ncr-int.h @@ -8,6 +8,7 @@ #include #define KEY_DATA_MAX_SIZE 3*1024 +#define NCR_CIPHER_MAX_KEY_LEN 1024 #define err() printk(KERN_DEBUG"ncr: %s: %s: %d\n", __FILE__, __func__, __LINE__) diff --git a/ncr.c b/ncr.c index 624d217..7608312 100644 --- a/ncr.c +++ b/ncr.c @@ -103,11 +103,14 @@ struct ncr_master_key_st st; dprintk(0, KERN_DEBUG, "Master key was previously initialized.\n"); } + if (unlikely(copy_from_user(master_key.key.secret.data, st.key, st.key_size))) { + err(); + return -EFAULT; + } + dprintk(0, KERN_INFO, "Initializing master key.\n"); master_key.type = NCR_KEY_TYPE_SECRET; - - memcpy(master_key.key.secret.data, st.key, st.key_size); master_key.key.secret.size = st.key_size; return 0; diff --git a/ncr.h b/ncr.h index 01fd413..53c77be 100644 --- a/ncr.h +++ b/ncr.h @@ -7,7 +7,6 @@ #endif #define NCR_CIPHER_MAX_BLOCK_LEN 32 -#define NCR_CIPHER_MAX_KEY_LEN 512 #define NCR_HASH_MAX_OUTPUT_SIZE 64 typedef enum { @@ -221,7 +220,7 @@ struct ncr_key_wrap_st { /* Internal ops */ struct ncr_master_key_st { - uint8_t key[NCR_CIPHER_MAX_KEY_LEN]; + uint8_t __user * key; uint16_t key_size; }; diff --git a/userspace/setkey.c b/userspace/setkey.c index d0a2b62..ea9d30e 100644 --- a/userspace/setkey.c +++ b/userspace/setkey.c @@ -25,6 +25,7 @@ int main(int argc, char** argv) struct ncr_master_key_st key; int size, ret; struct stat st; + uint8_t rawkey[32]; if (argc != 2) { fprintf(stderr, "Usage: setkey [filename]\n"); @@ -52,12 +53,13 @@ int main(int argc, char** argv) exit(1); } - size = fread(key.key, 1, sizeof(key.key), fp); + size = fread(rawkey, 1, sizeof(rawkey), fp); if (size < 16) { fprintf(stderr, "Illegal key!\n"); exit(1); } fclose(fp); + key.key = rawkey; key.key_size = size; /* Open the crypto device */ -- cgit