]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - crypto/ecdh.c
x86/xen: Reset VCPU0 info pointer after shared_info remap
[mirror_ubuntu-artful-kernel.git] / crypto / ecdh.c
index 63ca33771e4e771ebd0307d75e0e82c284cc51df..61c7708905d01ec6745c03352579b2173fc6c87f 100644 (file)
@@ -4,9 +4,9 @@
  * Authors: Salvator Benedetto <salvatore.benedetto@intel.com>
  *
  * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public Licence
+ * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version
- * 2 of the Licence, or (at your option) any later version.
+ * 2 of the License, or (at your option) any later version.
  */
 
 #include <linux/module.h>
@@ -55,8 +55,12 @@ static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
        ctx->curve_id = params.curve_id;
        ctx->ndigits = ndigits;
 
+       if (!params.key || !params.key_size)
+               return ecc_gen_privkey(ctx->curve_id, ctx->ndigits,
+                                      ctx->private_key);
+
        if (ecc_is_key_valid(ctx->curve_id, ctx->ndigits,
-                            (const u8 *)params.key, params.key_size) < 0)
+                            (const u64 *)params.key, params.key_size) < 0)
                return -EINVAL;
 
        memcpy(ctx->private_key, params.key, params.key_size);
@@ -81,16 +85,14 @@ static int ecdh_compute_value(struct kpp_request *req)
                        return -EINVAL;
 
                ret = crypto_ecdh_shared_secret(ctx->curve_id, ctx->ndigits,
-                                        (const u8 *)ctx->private_key, nbytes,
-                                        (const u8 *)ctx->public_key, 2 * nbytes,
-                                        (u8 *)ctx->shared_secret, nbytes);
+                                               ctx->private_key,
+                                               ctx->public_key,
+                                               ctx->shared_secret);
 
                buf = ctx->shared_secret;
        } else {
-               ret = ecdh_make_pub_key(ctx->curve_id, ctx->ndigits,
-                                       (const u8 *)ctx->private_key, nbytes,
-                                       (u8 *)ctx->public_key,
-                                       sizeof(ctx->public_key));
+               ret = ecc_make_pub_key(ctx->curve_id, ctx->ndigits,
+                                      ctx->private_key, ctx->public_key);
                buf = ctx->public_key;
                /* Public part is a point thus it has both coordinates */
                nbytes *= 2;
@@ -106,13 +108,12 @@ static int ecdh_compute_value(struct kpp_request *req)
        return ret;
 }
 
-static int ecdh_max_size(struct crypto_kpp *tfm)
+static unsigned int ecdh_max_size(struct crypto_kpp *tfm)
 {
        struct ecdh_ctx *ctx = ecdh_get_ctx(tfm);
-       int nbytes = ctx->ndigits << ECC_DIGITS_TO_BYTES_SHIFT;
 
-       /* Public key is made of two coordinates */
-       return 2 * nbytes;
+       /* Public key is made of two coordinates, add one to the left shift */
+       return ctx->ndigits << (ECC_DIGITS_TO_BYTES_SHIFT + 1);
 }
 
 static void no_exit_tfm(struct crypto_kpp *tfm)