Giter VIP home page Giter VIP logo

rsa's Introduction

RSA (Rivest–Shamir–Adleman) Asymmetric Cipher in Rust

Samples of RSA (Rivest–Shamir–Adleman) public-key cryptosystem implementations for learning purposes

Key generation

  1. Choose two distinct primes p and q

    FIPS.186-4, Section: B.3.1 Criteria for IFC Key Pairs

    sqrt(2)*2^((nlen/2)-1) <= p <= 2^(nlen/2)-1
    
    sqrt(2)*2^((nlen/2)-1) <= q <= 2^(nlen/2)-1
    
    |p - q| > 2^((nlen/2)-100)  
    

    where:

    ^ is an exponentiation (power) arithmetic operation

    nlen is the appropriate length for the desired security strength

  2. Compute the modulus, n

    n = p * q
    
  3. Compute the totient, t

  • Euler's totient function is used in the original RSA

    φ(n) = (p − 1) * (q − 1)
    

    which outputs the amount of numbers that are coprime to n

  • Carmichael function is recommended for modern RSA-based cryptosystems, also known as reduced totient function or least universal exponent function

    λ(n) = lcm(p − 1, q − 1)
    

    where lcm() is the least common multiple

  1. Choose a public key exponent, integer e (usually 65537 in decimal, or 0x010001 in hex)

    1 < e < t
    gcd(t, e) = 1
    
  2. Compute the modular multiplicative inverse, d

    d = (e ^ (−1)) mod t
    1 = (d * e) mod t
    
  3. Public key

    (e, n)
    
  4. Private key

    (d, n)
    

The numbers p, q, and d must be kept secret

Encryption

The encryption of the plaintext message, m

c = (m ^ e) mod n

Decryption

The decryption of the ciphertext, c

D = (c ^ d) mod n

References

Disclaimer

This project was created for research purposes and is not intended for use in production systems.

rsa's People

Contributors

sheroz avatar

Stargazers

 avatar  avatar

Watchers

 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.