Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 227798
b: refs/heads/master
c: 1f35065
h: refs/heads/master
v: v3
  • Loading branch information
Mimi Zohar authored and James Morris committed Dec 15, 2010
1 parent 68e042c commit 5d03b1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1bdbb4024c309e470711b434a24fb356fc92edea
refs/heads/master: 1f35065a9e2573427ce3fd6c4a40b355c2ddfb92
29 changes: 15 additions & 14 deletions trunk/security/keys/encrypted_defined.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ static int valid_master_desc(const char *new_desc, const char *orig_desc)
* On success returns 0, otherwise -EINVAL.
*/
static int datablob_parse(char *datablob, char **master_desc,
char **decrypted_datalen, char **hex_encoded_iv,
char **hex_encoded_data)
char **decrypted_datalen, char **hex_encoded_iv)
{
substring_t args[MAX_OPT_ARGS];
int ret = -EINVAL;
Expand Down Expand Up @@ -167,7 +166,6 @@ static int datablob_parse(char *datablob, char **master_desc,
*hex_encoded_iv = strsep(&datablob, " \t");
if (!*hex_encoded_iv)
break;
*hex_encoded_data = *hex_encoded_iv + (2 * ivsize) + 2;
ret = 0;
break;
case Opt_update:
Expand Down Expand Up @@ -558,18 +556,24 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key,
}

static int encrypted_key_decrypt(struct encrypted_key_payload *epayload,
const char *hex_encoded_iv,
const char *hex_encoded_data)
const char *hex_encoded_iv)
{
struct key *mkey;
u8 derived_key[HASH_SIZE];
u8 *master_key;
u8 *hmac;
const char *hex_encoded_data;
unsigned int master_keylen;
unsigned int encrypted_datalen;
size_t asciilen;
int ret;

encrypted_datalen = roundup(epayload->decrypted_datalen, blksize);
asciilen = (ivsize + 1 + encrypted_datalen + HASH_SIZE) * 2;
if (strlen(hex_encoded_iv) != asciilen)
return -EINVAL;

hex_encoded_data = hex_encoded_iv + (2 * ivsize) + 2;
hex2bin(epayload->iv, hex_encoded_iv, ivsize);
hex2bin(epayload->encrypted_data, hex_encoded_data, encrypted_datalen);

Expand Down Expand Up @@ -620,20 +624,18 @@ static void __ekey_init(struct encrypted_key_payload *epayload,
*/
static int encrypted_init(struct encrypted_key_payload *epayload,
const char *master_desc, const char *datalen,
const char *hex_encoded_iv,
const char *hex_encoded_data)
const char *hex_encoded_iv)
{
int ret = 0;

__ekey_init(epayload, master_desc, datalen);
if (!hex_encoded_data) {
if (!hex_encoded_iv) {
get_random_bytes(epayload->iv, ivsize);

get_random_bytes(epayload->decrypted_data,
epayload->decrypted_datalen);
} else
ret = encrypted_key_decrypt(epayload, hex_encoded_iv,
hex_encoded_data);
ret = encrypted_key_decrypt(epayload, hex_encoded_iv);
return ret;
}

Expand All @@ -653,7 +655,6 @@ static int encrypted_instantiate(struct key *key, const void *data,
char *master_desc = NULL;
char *decrypted_datalen = NULL;
char *hex_encoded_iv = NULL;
char *hex_encoded_data = NULL;
int ret;

if (datalen <= 0 || datalen > 32767 || !data)
Expand All @@ -665,7 +666,7 @@ static int encrypted_instantiate(struct key *key, const void *data,
datablob[datalen] = 0;
memcpy(datablob, data, datalen);
ret = datablob_parse(datablob, &master_desc, &decrypted_datalen,
&hex_encoded_iv, &hex_encoded_data);
&hex_encoded_iv);
if (ret < 0)
goto out;

Expand All @@ -675,7 +676,7 @@ static int encrypted_instantiate(struct key *key, const void *data,
goto out;
}
ret = encrypted_init(epayload, master_desc, decrypted_datalen,
hex_encoded_iv, hex_encoded_data);
hex_encoded_iv);
if (ret < 0) {
kfree(epayload);
goto out;
Expand Down Expand Up @@ -722,7 +723,7 @@ static int encrypted_update(struct key *key, const void *data, size_t datalen)

buf[datalen] = 0;
memcpy(buf, data, datalen);
ret = datablob_parse(buf, &new_master_desc, NULL, NULL, NULL);
ret = datablob_parse(buf, &new_master_desc, NULL, NULL);
if (ret < 0)
goto out;

Expand Down

0 comments on commit 5d03b1e

Please sign in to comment.