On Thu, 2016-08-04 at 09:53 +0200, Niels Möller wrote: > > My main concern is that rsa_private_key_prepare() multiplies q and > > p, > > I don't quite like that either, but I don't think it matters much for > performance. The time for that multiplication is only a tiny fraction > of the time needed to create a single signature.
That's correct, but it still bugs me as a cost that gets added into busy servers. What about adding a version of prepare that takes both the public key and the pubkey as in the attached patch? regards, Nikos
From 40b6546cfeb45e48bfa616cb96b36873ec58ea33 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos <[email protected]> Date: Fri, 5 Aug 2016 08:50:38 +0200 Subject: [PATCH] Added rsa_private_key_prepare2 This function behaves as rsa_private_key_prepare but does not need to calculate n from p and q. --- nettle.texinfo | 4 +++- rsa-sign.c | 8 ++++++++ rsa.h | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/nettle.texinfo b/nettle.texinfo index e539dbe..5e416c5 100644 --- a/nettle.texinfo +++ b/nettle.texinfo @@ -3645,8 +3645,10 @@ When you have assigned values to the attributes of a key, you must call @deftypefun int rsa_public_key_prepare (struct rsa_public_key *@var{pub}) @deftypefunx int rsa_private_key_prepare (struct rsa_private_key *@var{key}) +@deftypefunx int rsa_private_key_prepare2 (struct rsa_private_key *@var{key}, const struct rsa_public_key *@var{pub}) Computes the octet size of the key (stored in the @code{size} attribute, -and may also do other basic sanity checks. Returns one if successful, or +and may also do other basic sanity checks. @code{rsa_private_key_prepare2} +is an optimized version of @code{rsa_private_key_prepare}. Return one if successful, or zero if the key can't be used, for instance if the modulo is smaller than the minimum size needed for @acronym{RSA} operations specified by PKCS#1. @end deftypefun diff --git a/rsa-sign.c b/rsa-sign.c index 4832352..18eb635 100644 --- a/rsa-sign.c +++ b/rsa-sign.c @@ -84,6 +84,14 @@ rsa_private_key_prepare(struct rsa_private_key *key) return (key->size > 0); } +int +rsa_private_key_prepare2(struct rsa_private_key *key, const struct rsa_public_key *pub) +{ + key->size = _rsa_check_size(pub->n); + + return (key->size > 0); +} + /* Computing an rsa root. */ void rsa_compute_root(const struct rsa_private_key *key, diff --git a/rsa.h b/rsa.h index 6d2574b..4e31e6d 100644 --- a/rsa.h +++ b/rsa.h @@ -52,6 +52,7 @@ extern "C" { #define rsa_private_key_init nettle_rsa_private_key_init #define rsa_private_key_clear nettle_rsa_private_key_clear #define rsa_private_key_prepare nettle_rsa_private_key_prepare +#define rsa_private_key_prepare2 nettle_rsa_private_key_prepare2 #define rsa_pkcs1_verify nettle_rsa_pkcs1_verify #define rsa_pkcs1_sign nettle_rsa_pkcs1_sign #define rsa_pkcs1_sign_tr nettle_rsa_pkcs1_sign_tr @@ -187,6 +188,9 @@ rsa_private_key_clear(struct rsa_private_key *key); int rsa_private_key_prepare(struct rsa_private_key *key); +int +rsa_private_key_prepare2(struct rsa_private_key *key, const struct rsa_public_key *pub); + /* PKCS#1 style signatures */ int -- 2.7.4
_______________________________________________ nettle-bugs mailing list [email protected] http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs
