Code Monkey home page Code Monkey logo

Comments (1)

syncsynchalt avatar syncsynchalt commented on June 4, 2024

There are multiple algorithms to perform key exchange. RSA is one, Diffie-Hellman is another. The algorithm used in this handshake is ECDHE, which is Elliptical Curve Diffie-Hellman with Ephemeral keys. The specific EC function used is X25519 (multiplication using Curve25519).

X25519 is defined in this RFC: https://tools.ietf.org/html/rfc7748#section-5 and its use in ECDH is defined in https://tools.ietf.org/html/rfc7748#section-6 . The last "E" refers to generating a new key for every connection (ephemeral), which doesn't change the algorithm.

The comment that you quoted from curve25519-mult.c refers to a trick that the coder is using - PEM files are a base64 encoding of a binary format called DER. DER encodes things in a binary format of type+length+data, and it would take a bit of code to write a proper DER parser. However, if you know the format is fixed and that the data you want is the last field (and you know its length is 32), you can shortcut all that and just read the last 32 bytes without parsing DER at all. To see the DER data try the following command on a pem file:

$ openssl asn1parse -in server-ephemeral-private.key -inform PEM
    0:d=0  hl=2 l=  46 cons: SEQUENCE          
    2:d=1  hl=2 l=   1 prim: INTEGER           :00
    5:d=1  hl=2 l=   5 cons: SEQUENCE          
    7:d=2  hl=2 l=   3 prim: OBJECT            :X25519
   12:d=1  hl=2 l=  34 prim: OCTET STRING      [HEX DUMP]:0420909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAF

I believe the ASN.1 definition for these key files is in PKCS#8: https://tools.ietf.org/html/rfc5208

from illustrated-tls12.

Related Issues (17)

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.