TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Guidance on implementing cryptography as a developer

33 点作者 ementally超过 1 年前

7 条评论

briHass超过 1 年前
The problem with pedantry over the actual crypto algorithms is that it almost never covers serious flaws in protecting the key material. This list only dedicates a few sentences that recommend clearing the memory used for keys&#x2F;secrets, but noting GC languages provide no guarantees.<p>For something like modern .NET, worrying about algos is bad advice. Use the library standard Data Protection APIs (in ASP.NET, but available for console apps also) which handle things like protecting&#x2F;clearing key material in memory, key rotation, deriving context-specific sub keys from master keys, and even storing secrets in a manner that makes them far less likely to end up dumped to logs or floating around in memory. The algos (AES, HMACSHA2, PBKDF2) aren&#x27;t the new hotness, but that tradeoff doesn&#x27;t practically matter for normal attacks. Far more important is the simple API surface of Encrypt, Decrypt, and Protect&#x2F;Verify password with all footguns removed. Persistence of keys is also abstracted and can be a simple as a file protected with a cert up to using a HSM with a change to one line of code.
评论 #38267371 未加载
User23超过 1 年前
Back in the day a former NSA employee told me that they almost never crack the encryption algorithm. Rather, they crack errors in the implementation.
评论 #38258716 未加载
matheusmoreira超过 1 年前
&gt; most languages provide access to old algorithms (e.g. MD5 and SHA1)<p>Why is this a problem? Isn&#x27;t it fine to use them for non-cryptogrphic purposes?
评论 #38258658 未加载
geph2021超过 1 年前
<p><pre><code> Avoid : OpenSSL </code></pre> Sometimes you&#x27;re using OpenSSL and you don&#x27;t realize it. For example, the python cryptography library relies on OpenSSL, although in such a case you&#x27;re relying on someone else having properly used the OpenSSL library.
candiddevmike超过 1 年前
If you&#x27;re going to write things that touch crypto, make sure you test your stuff with inputs and outputs from other (known good) implementations. A lot of times the std lib provides primitives that give you plenty of rope to hang yourself with.
tptacek超过 1 年前
A writer I used to read did an annual Christmas guide for kitchen gifts. It started out interestingly, or at least idiosyncratically (they were weirdly enamored with the Thermomix, a blender that also cooks food and is only really available in Europe). But as it went on, they&#x27;d invariably get to the point where they were writing paragraphs about individual spoons, and not interesting ones but the kinds you can get off the shelf at Williams Sonoma or whatever. It became clear that they just really liked writing about their kitchen.<p>That&#x27;s the vibe here. There&#x27;s something to be said for an article that forthrightly declares &quot;here are all my idiosyncratic opinions about implementing cryptography&quot;. But this one instead purports to be offering guidance to developers. That&#x27;s a little troublesome, because reasons:<p>* Some of these opinions are pretty outré, such as the encouragement to compose your own CTR-based encrypt-then-MAC out of XChaCha20 and a Blake2b KMAC because... key committing? It&#x27;s fine to have this opinion and to argue it forcefully but if you&#x27;re offering guidance, it should probably include the fact that in most situations, simply using a Seal&#x2F;Unseal AEAD is a more-than-cromulent call.<p>* Some of them seem factually off? I&#x27;m no advocate for RSA, but the idea that you should avoid RSA-KEM because it&#x27;s &quot;worse than using hybrid encryption&quot; --- RSA-KEM is a construction for doing hybrid encryption! (RSA-KEM, roughly: fill the RSA modulus with a full-width random number, then HKDF it to generate a symmetric key).<p>* Some of this gets into Applied Cryptography levels of trivia; for instance: it is probably not all that important to tell developers to avoid Streebog, Meowhash, and SHAcrypt (&quot;nobody uses this, and I’ve never even seen it in a cryptographic library&quot;).<p>* A bunch of things have landed on this guy&#x27;s shitlist for no reason other than not having seen them in many places? This includes SIV (this author really doesn&#x27;t like SIV), Blake2s, Kangaroo12, any PAKE, or any PQC (note: this follows an earlier recommendation <i>to</i> use PQC). &quot;They&#x27;re all bad&quot;.<p>* There&#x27;s a bunch of random NSA FUD sprinkled across this; for instance, &quot;SHA2 was designed behind closed doors at the NSA&quot;, as if any serious practitioner avoids SHA2, or &quot;P-256 is probably the most popular curve, the seeds for these curves haven’t been explained, which is not a good look considering that Dual_EC_DRBG was a NIST standard despite containing an NSA backdoor&quot; --- Dual EC being basically unrelated to the NIST P-curves, you might as well apply the same logic to SHA2.<p>None of this is like, disqualifying, especially if you&#x27;re doing a &quot;this is what makes me tick&quot; kind of article, but I think the title it has right now is missing a word before &quot;developer&quot;.<p>Colin Percival kicked off this genre of articles with his &quot;Cryptographic Right Answers&quot;, which I recall as essentially being a subtextual argument against elliptic curve cryptography. I found his recommendations a little odd (what set me off was probably &quot;Use RSAES-OAEP with SHA256 as the hash function, MGF1+SHA256 as the mask generation function&quot;) and set out to write a &quot;Crypographic Right Answers&quot; that fit the zeitgeist as I understood it --- ChaPoly, Nacl&#x2F;Sodium, Curve25519 and Ed25519. I updated that article at Latacora to be much more prescriptive, and have kind of regretted it; it had become a step back towards what Colin had done, a docket of fiddly decisions we would have made if you contracted us to design something, but not really a reflection of any kind of accepted best practices in our field.<p>We have come full circle with stuff like this, which describes the best practices of exactly one developer in the world, the author. Again, fair enough. But maybe we can just kill this species of post off now.
beloch超过 1 年前
The short, short version:<p>Don&#x27;t.<p>The short version:<p>Don&#x27;t. Use somebody else&#x27;s implementation if at all possible, because you&#x27;re almost certainly going to F it up.