Commit 2ad5fc71 authored by Niels Möller's avatar Niels Möller
Browse files

(spki_pkcs5_encrypt): Handle the case of no IV.

Rev: src/spki.c:1.64
parent ae707435
...@@ -381,9 +381,10 @@ spki_pkcs5_encrypt(struct lsh_string *label, ...@@ -381,9 +381,10 @@ spki_pkcs5_encrypt(struct lsh_string *label,
struct lsh_string *key; struct lsh_string *key;
struct lsh_string *salt; struct lsh_string *salt;
struct lsh_string *iv; struct lsh_string *iv;
const uint8_t *iv_data;
struct lsh_string *encrypted; struct lsh_string *encrypted;
struct lsh_string *value; struct lsh_string *value;
assert(crypto); assert(crypto);
assert(prf); assert(prf);
...@@ -395,16 +396,20 @@ spki_pkcs5_encrypt(struct lsh_string *label, ...@@ -395,16 +396,20 @@ spki_pkcs5_encrypt(struct lsh_string *label,
crypto->key_size); crypto->key_size);
if (crypto->iv_size) if (crypto->iv_size)
iv = lsh_string_random(crypto->iv_size); {
iv = lsh_string_random(crypto->iv_size);
iv_data = lsh_string_data(iv);
}
else else
iv = NULL; {
iv = NULL;
iv_data = NULL;
}
encrypted = crypt_string_pad(MAKE_ENCRYPT(crypto, encrypted = crypt_string_pad(MAKE_ENCRYPT(crypto,
lsh_string_data(key), lsh_string_data(key),
iv ? lsh_string_data(iv) : NULL), iv_data),
data); data);
/* FIXME: Handle iv == NULL. */
value = lsh_string_format_sexp(0, "(password-encrypted%s(Xpkcs5v2%0s" value = lsh_string_format_sexp(0, "(password-encrypted%s(Xpkcs5v2%0s"
"(iterations%i)(salt%s))" "(iterations%i)(salt%s))"
"(%0s(iv%s)(data%s)))", "(%0s(iv%s)(data%s)))",
...@@ -413,7 +418,7 @@ spki_pkcs5_encrypt(struct lsh_string *label, ...@@ -413,7 +418,7 @@ spki_pkcs5_encrypt(struct lsh_string *label,
iterations, iterations,
STRING_LD(salt), STRING_LD(salt),
get_atom_name(crypto_name), get_atom_name(crypto_name),
STRING_LD(iv), crypto->iv_size, iv_data,
STRING_LD(encrypted)); STRING_LD(encrypted));
lsh_string_free(key); lsh_string_free(key);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment