Git Product home page Git Product logo

embeddedmontgomeryrsa's Introduction

EmbeddedMontgomeryRSA

An optimized C implementation of the RSA public key encryption using the Montgomery Multiplication algorithm.

RSA and Modular Exponentiation

The RSA operations for encryption and decryption involve modular exponentiation: X^Y mod M.

  • C: Ciphertext
  • P: PlainText
  • e: Public Exponent
  • d: Private Exponent
  • M: modulo
  • C = Pe mod M (encrypt with public key)
  • P = Cd mod M (decrypt with private key)

The public key is (e,M) and the private key is (d,M).

Generation of Modulus (M)

Choose two prime numbers with half the bit-length of the desired public/private keys.

  • p: prime
  • q: prime
  • M = p x q

See [https://www.mobilefish.com/services/rsa_key_generation/rsa_key_generation.php] for more information.

Generation of Public Exponent (e)

The public exponent (e) is a small integer. Valid choices are 3, 5, 7, 17, 257, or 65537.
With RSA keys the public exponent is usually 65537.

The requirements for e are:

  • 1 < e < phi(M) = (p - 1) * (q - 1)
  • e and Euler's phi(M) function are coprime.

Generaion of Private Exponent (d)

The private exponent is generated from primes p and q and the public exponent.

  • d = e-1 mod (p - 1) * (q - 1)

Efficient Modular Exponentiation (using Montgomery Multiplication)

The multiply and square algorithm for Modular Exponentiation requires modular multiplication in the forms:

  • Z = X * X mod M
  • Z = X * Y mod M

This operation requires expensive multiplication and division operations. Montgomery Multiplication converts parameters into modular residues wherein multiplication becomes addition and division becomes a bitwise shift.

Modular residues require a pre computed value (R), related to the size of the modulus (M):

  • R2m = 22m mod M, where m = # bits of in the modulus (M)

The bitwise Montgomery Multiplication algorithm uses the equation:

  • X (residue) = X * R2m * (R-1) mod M

This bitwise algorithm internally calculates the modular inverse (R-1). The modular inverse is defined as R-1 where R * R-1 mod M = 1.

Optimization Results

Key Size Auto Opt. CPU Time (sec) All Opt. Optimization (%)
512 2.42 0.53 78.1
1024 9.58 2.05 78.6
2048 38.49 8.27 78.5

embeddedmontgomeryrsa's People

Contributors

tsalomon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.