TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to Interchange Ed25519 Keys

69 pointsby tmfiabout 4 years ago

9 comments

agwaabout 4 years ago
This is unnecessarily complicated. The beautiful thing about Ed25519 keys (private and public) is that they are simply opaque byte strings. Indeed, here is Go&#x27;s definition of ed25519.PublicKey:<p><pre><code> type PublicKey []byte </code></pre> So if your application uses exclusively Ed25519, you can just pass around the raw bytes (encoded as base64 as desired). There is no need to muck around with ASN.1.<p>And if you do need to transmit keys in ASN.1 structures, Go&#x27;s standard library has functions for that:<p><a href="https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;crypto&#x2F;x509&#x2F;#MarshalPKIXPublicKey" rel="nofollow">https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;crypto&#x2F;x509&#x2F;#MarshalPKIXPublicKey</a><p><a href="https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;crypto&#x2F;x509&#x2F;#ParsePKIXPublicKey" rel="nofollow">https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;crypto&#x2F;x509&#x2F;#ParsePKIXPublicKey</a><p>The author has just written worse versions of those functions.
评论 #26916544 未加载
评论 #26915579 未加载
评论 #26915269 未加载
评论 #26920185 未加载
评论 #26915737 未加载
评论 #26915121 未加载
评论 #26914641 未加载
评论 #26914244 未加载
评论 #26922015 未加载
评论 #26915364 未加载
formerly_provenabout 4 years ago
Why exactly would you do any of this instead of<p>a) just having a field of 32 bytes in the wire protocol (if binary)<p>b) just turning it into a hex string (if text is needed) or base64&#x2F;85 if you don&#x27;t want hex for some reason
评论 #26914498 未加载
评论 #26915443 未加载
评论 #26915221 未加载
kodablahabout 4 years ago
Why use ASN.1? Just base64 and send. Besides a few bytes at the end, a Tor v3 onion service address is just a base32&#x27;d ed25519 public key.
ajrwabout 4 years ago
JWK is a good option for representing public keys, for an Ed25519 key you would have something like this:<p>{ &quot;kty&quot;:&quot;OKP&quot;, &quot;crv&quot;:&quot;Ed25519&quot;, &quot;x&quot;:&quot;oF0a6lgwrJplzfs4RmDUl-NpfEa0Gc8s7IXei9JFRZ0&quot; }
wahernabout 4 years ago
Ed25519 isn&#x27;t quite as simple as people make it out to be, at least in the sense that it&#x27;s an answer to a problem that&#x27;s been entirely elided in these discussions, whilst the problems with older alternatives are more familiar.<p>Both RSA and NIST-defined elliptic curves support both signatures and key exchange using the same public key. Not so with Curve25519. Ed25519 is just for signatures and X25519 for key exchange, and the &quot;opaque&quot; 32-byte public keys are actually different. You can convert Ed25519 public keys to X25519 public keys, but for a reverse transformation there are two incompatible methods, and so any protocol where you would like to keep a single public key association for parties--particularly offline protocols where a sender can&#x27;t ask the recipient to generate an ephemeral key pair for confidential message reception--one is faced with a couple of choices. And the choices made by some existing protocols aren&#x27;t always obvious. Indeed, the very fact that these differences exist isn&#x27;t necessarily obvious until you&#x27;re already knee-deep in the weeds.<p>At this point the solution is more-or-less settled--just publish Ed25519 keys. But it wasn&#x27;t always that way considering that the Ed25519 signature scheme is much newer than Curve25519. And of course the legacy of this complexity will always be around to some extent.<p>Also left undiscussed is the different modes of Ed25519--regular and prehashed message digestion, a choice that is absent for older schemes. That&#x27;s a whole &#x27;nother can of worms.<p>Time and usage effect almost every new protocol and format--they don&#x27;t stay pristine forever. The sheen has already dulled on Curve25519. If you want the fewest possible interoperability headaches Curve448 is the new hotness, if only because Curve448 has been standardized more times than actually deployed. It&#x27;s also more secure--longer keys[1] and slightly better mathematical properties, AFAIU, of the type that originally made Curve25519 and DJB&#x27;s SafeCurves initiative appealing.<p>[1] Arguably useful if there&#x27;s an extended period of time between quantum computing scaling to threaten 128-bit classically equivalent but non-quantum-safe asymmetric schemes, and scaling to threaten ~256-bit equivalent schemes. You&#x27;re probably better off with RSA in that case, though. Or just not worrying about it and sticking to Curve25519--one of the few times where &quot;but 32 is such a nice, round, convenient string length&quot; is perhaps a legitimate argument.
评论 #26919354 未加载
nemo1618about 4 years ago
I&#x27;ve always found PEM&#x2F;ASN.1 to be rather ugly. I encode my ed25519 keys as &quot;ed25519:&lt;hex key&gt;&quot;.
评论 #26918623 未加载
kfredsabout 4 years ago
First of all, I enjoyed reading this article. Second, it inspired me to write the following, with curious beginners as the target audience.<p>It was meant to be about the importance of reducing the computing power of recognizers &#x2F; parsers &#x2F; interfaces &#x2F; meaning-makers, as the author brings up PEM, ASN.1, and X.509. It grew a bit. Enjoy.<p>&lt;rant&gt;<p>In my opinion security exists to facilitate trust, and security has a lot to do with managing complexity.<p>One of the most powerful security technologies we have is math. Especially math that is easy to do in one direction and very difficult to do in the opposite direction. RSA, Ed25519, Diffie-Hellman, and SHA256 all rely on this concept.<p>Another power tool is combining these cryptographic primitives to build protocols that provide e.g. authentication, forward secrecy, confidentiality, and integrity-protection.<p>When using cryptographic primitives directly it is easy to make mistakes. For example, before Ed25519 there were other similar signature schemes that, in addition to a message to be signed, required a number that must not be repeated for different messages, called a nonce. If this number was repeated, an attacker could collect signatures and combine them to get the private key. Ed25519 removes this sharp corner by essentially using nonce=SHA512(message) internally.<p>When designing a protocol like TLS, SSH, Signal, or WireGuard, multiple primitives of different types are combined to get the desired security properties.<p>Cryptographers work hard to combine primitives such that the resulting construction is easy to reason about, and ideally prove that the construction will only break if one of the primitives break.<p>Unfortunately this key insight is often ignored further up the stack. Many protocols, file formats, etc are unnecessarily complex. This makes them harder to reason about, which makes it harder to build a safe recognizer &#x2F; parser &#x2F; interface &#x2F; meaning-maker for them. Complex parsers lead to incorrect mental models, which lead to security vulnerabilities.<p>If you are ever tasked with building a protocol, file format, or API, consider making it only as complex as it must be. We will suffer for a long time with the complex beasts that have already been standardized. Let’s not make more of them.<p>Remember that security, trustworthiness, understanding, and managing complexity are intertwined. Don’t use more complexity than necessary.<p>&lt;&#x2F;rant&gt;<p>P.S. If anyone is curious about Ed25519 I can highly recommend the following article: <a href="https:&#x2F;&#x2F;blog.mozilla.org&#x2F;warner&#x2F;2011&#x2F;11&#x2F;29&#x2F;ed25519-keys&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.mozilla.org&#x2F;warner&#x2F;2011&#x2F;11&#x2F;29&#x2F;ed25519-keys&#x2F;</a>
upofadownabout 4 years ago
&gt;...if ed25519 fails, it’ll fail slowly and there’ll be time to migrate to something else.<p>Why would you assume that? The curve in question has been around for only something like 10 years....
latortugaabout 4 years ago
There&#x27;s a typo in the HN title, it should be 25519, not 25119.
评论 #26915243 未加载
评论 #26917954 未加载