Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Just Enough Math to Understand Elliptic Curve Cryptography

Just Enough Math to Understand Elliptic Curve Cryptography

Elliptic Curve Cryptography is used in many real world protocols like TLS, SSH, IPsec, Whatsapp, Bitcoin and many more.

Trying to build an understanding of how it works, however, can be fairly daunting for anyone who doesn't have a deep mathematics background. This talk walks through just enough math needed to understand how the most common Elliptic Curve Cryptography primitives work.

Mrinal Wadhwa

March 04, 2020
Tweet

More Decks by Mrinal Wadhwa

Other Decks in Programming

Transcript

  1. Elliptic Curve Cryptography
    Mrinal Wadhwa
    @mrinal
    Just enough math, to understand:
    Ockam
    ockam.io/team

    View full-size slide

  2. Banking, Commerce, Communication …
    The systems, we build, rely on various cryptographic protocols to ensure integrity and confidentiality of data that flows within them.
    Systems

    View full-size slide

  3. Banking, Commerce, Communication …
    PKI, TLS, SSH, Wiregaurd, Signal, Bitcoin …
    The systems, we build, rely on various cryptographic protocols to ensure integrity and confidentiality of data that flows within them.
    Systems
    Protocols

    View full-size slide

  4. Banking, Commerce, Communication …
    These protocols are, in turn, constructed by combining well defined cryptographic primitives - key agreement, signatures etc.
    PKI, TLS, SSH, Wiregaurd, Signal, Bitcoin …
    ECDH, EcDSA, EdDSA, Schnorr …
    Systems
    Protocols
    Primitives

    View full-size slide

  5. Banking, Commerce, Communication …
    The primitives themselves often need a hard to reverse operation, which with elliptic curves is usually scalar multiplication.
    PKI, TLS, SSH, Wiregaurd, Signal, Bitcoin …
    ECDH, EcDSA, EdDSA, Schnorr …
    Scalar Multiplication
    Systems
    Protocols
    Primitives
    Hard to reverse operation

    View full-size slide

  6. Banking, Commerce, Communication …
    Scalar multiplication involves two group operations - point addition and doubling.
    PKI, TLS, SSH, Wiregaurd, Signal, Bitcoin …
    ECDH, EcDSA, EdDSA, Schnorr …
    Scalar Multiplication
    Point Addition, Point Doubling
    Systems
    Protocols
    Primitives
    Hard to reverse operation
    Group Operations

    View full-size slide

  7. Systems Banking, Commerce, Communication …
    Protocols PKI, TLS, SSH, Wiregaurd, Signal, Bitcoin …
    Primitives ECDH, EcDSA, EdDSA, Schnorr …
    Hard to reverse operation Scalar Multiplication
    Group Operations Point Addition, Point Doubling
    Modular Arithmetic Addition, Subtraction, Multiplication
    and Inversion.

    View full-size slide

  8. Most number sets, that we’re used to, are infinite - natural numbers,
    real numbers etc.
    Elliptic Curve Cryptography, however, relies on arithmetic within a
    finite set of numbers.

    View full-size slide

  9. {, , , , }
    For example we may want the result, of adding any two numbers in this set, to also be in this set.

    View full-size slide

  10. {, , , , }
    1+3 =4 is easy because the result 4 is in our set.
    + =

    View full-size slide

  11. {, , , , }
    But, 3+4=7 is not in the set.
    + =

    View full-size slide

  12. Modular
    Arithmetic.
    Modular arithmetic is way of keeping the result in our finite set.

    View full-size slide

  13. {, , , , }
    + ≡ mod
    Perform regular integer arithmetic as long as the
    result is smaller than 5.

    View full-size slide

  14. {, , , , }
    + ≡
    Perform regular integer arithmetic, if the result is
    greater than 5, divide the result by 5. This remainder
    is the new result.

    View full-size slide

  15. Calculating a multiplicative inverse.

    View full-size slide

  16. ≡ + + mod
    Elliptic Curve over a Finite Field.

    View full-size slide

  17. ≡ + + mod
    Elliptic Curve over a Finite Field.

    View full-size slide

  18. Curve P-256 / NIST P256 / secp256r1 / prime256v1

    View full-size slide

  19. Group
    Operations
    Point Addition & Doubling

    View full-size slide

  20. Scalar
    Multiplication
    Multiply a Point with a scalar.

    View full-size slide

  21. Really means ADD a point to itself scalar times.

    View full-size slide

  22. Diffie-Hellman
    Key Exchange

    View full-size slide

  23. ECDH - Elliptic Curve Diffie-Hellman

    View full-size slide

  24. ECDH - Elliptic Curve Diffie-Hellman

    View full-size slide

  25. ECDH - Elliptic Curve Diffie-Hellman

    View full-size slide

  26. ECDH - Elliptic Curve Diffie-Hellman

    View full-size slide

  27. ECDH - Elliptic Curve Diffie-Hellman

    View full-size slide

  28. Systems Banking, Commerce, Communication …
    Protocols PKI, TLS, SSH, Wiregaurd, Signal, Bitcoin …
    Primitives ECDH, EcDSA, EdDSA, Schnorr …
    Hard to reverse operation Scalar Multiplication
    Group Operations Point Addition, Point Doubling
    Modular Arithmetic Addition, Subtraction, Multiplication
    and Inversion.

    View full-size slide

  29. Use: Tink, Golang Crypto, Rust Crypto, BearSSL, dalek-cryptography …
    Don’t use any of this code in your app!
    https://gist.github.com/mrinalwadhwa/1b3c0a6c6da74065d2baf755a8fc90e8
    ECDH - Elliptic Curve Diffie-Hellman key exchange implemented from
    scratch with everything we learnt in this talk

    View full-size slide

  30. Mrinal Wadhwa
    Ockam
    @mrinal
    Cryptography Meetup
    @CryptographySF
    meetup.com/Cryptography-Meetup
    ockam.io/team

    View full-size slide