Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Stephan Mueller <smueller@chronox.de>
To: Tudor-Dan Ambarus <tudor-dan.ambarus@nxp.com>
Cc: "herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	Horia Ioan Geanta Neag <horia.geanta@nxp.com>
Subject: Re: [PATCH v6 0/3] crypto: caam - add support for RSA algorithm
Date: Mon, 23 May 2016 15:02:57 +0200	[thread overview]
Message-ID: <3395695.ChDFsreWpU@tauon.atsec.com> (raw)
In-Reply-To: <AMSPR04MB536BAC8C0E2406B390B1C4CB84E0@AMSPR04MB536.eurprd04.prod.outlook.com>

Am Montag, 23. Mai 2016, 12:56:18 schrieb Tudor-Dan Ambarus:

Hi Tudor,

> Hi Stephan,
> 
> > as I am looking into the RSA countermeasures, I am wondering how much of
> > countermeasures are actually applied inside hardware implementations.
> 
> Please point me to the reference RSA countermeasures so that we have
> a common point of start.

As the entire MPI logic is derived from libgcrypt, I am planning to use the 
libgcrypt implementation as a basis to implement the blinding defined by the 
Handbook of Applied Cryptograpy 11.118/11.119.


This is the code from libgcrypt:

    {
      /* First, we need a random number r between 0 and n - 1, which
         is relatively prime to n (i.e. it is neither p nor q).  The
         random number needs to be only unpredictable, thus we employ
         the gcry_create_nonce function by using GCRY_WEAK_RANDOM with
         gcry_mpi_randomize.  */
      r  = mpi_snew (ctx.nbits);
      ri = mpi_snew (ctx.nbits);
      bldata = mpi_snew (ctx.nbits);

      do
        {
          _gcry_mpi_randomize (r, ctx.nbits, GCRY_WEAK_RANDOM);
          mpi_mod (r, r, sk.n);
        }
      while (!mpi_invm (ri, r, sk.n));

      /* Do blinding.  We calculate: y = (x * r^e) mod n, where r is
         the random number, e is the public exponent, x is the
         non-blinded data and n is the RSA modulus.  */
      mpi_powm (bldata, r, sk.e, sk.n);
      mpi_mulm (bldata, bldata, data, sk.n);

      /* Perform decryption.  */
      secret (plain, bldata, &sk);
      _gcry_mpi_release (bldata); bldata = NULL;

      /* Undo blinding.  Here we calculate: y = (x * r^-1) mod n,
         where x is the blinded decrypted data, ri is the modular
         multiplicative inverse of r and n is the RSA modulus.  */
      mpi_mulm (plain, plain, ri, sk.n);

      _gcry_mpi_release (r); r = NULL;
      _gcry_mpi_release (ri); ri = NULL;
    }


"All we need" in the kernel is mpi_invm and mpi_mulm.

> 
> Thanks,
> ta


Ciao
Stephan

  reply	other threads:[~2016-05-23 13:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-19 12:15 [PATCH v6 0/3] crypto: caam - add support for RSA algorithm Tudor Ambarus
2016-05-19 12:15 ` [PATCH v6 1/3] crypto: scatterwak - Add scatterwalk_sg_copychunks Tudor Ambarus
2016-05-19 12:15 ` [PATCH v6 2/3] crypto: scatterwalk - export scatterwalk_pagedone Tudor Ambarus
2016-05-19 12:15 ` [PATCH v6 3/3] crypto: caam - add support for RSA algorithm Tudor Ambarus
2016-05-19 15:13   ` Horia Ioan Geanta Neag
2016-05-19 15:45 ` [PATCH v6 0/3] " Horia Ioan Geanta Neag
2016-05-19 21:51 ` Stephan Mueller
2016-05-23 12:56   ` Tudor-Dan Ambarus
2016-05-23 13:02     ` Stephan Mueller [this message]
2016-05-24 16:13       ` Tudor-Dan Ambarus
2016-05-24 16:58         ` Stephan Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3395695.ChDFsreWpU@tauon.atsec.com \
    --to=smueller@chronox.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=tudor-dan.ambarus@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox