Live data from Hacker News

How I implemented my own crypto

loup-vaillant.fr

41–50 of 409 posts

Re: How I implemented my own crypto

#41

I still believe it's a bad idea to roll your own crypto, interesting as an exercise, but I would never use it in a production environment.

There is a difference between rolling your own crypto and rolling your own crypto. There is Monocypher, then there is this company that is trying to do some weird protocol using CRC, DES in CBC mode and MD5. The sentence was targeting the latter case.

Re: How I implemented my own crypto

#42

Main lesson not learned: instead of testing, prove correctness in high assurance code like this. Rigorously and formally. Preferably even refine the proof to executable code. (Yes, it would take somewhere on the order of 10k LOC to prove correctness of this 1k.)

https://github.com/mitls/hacl-star

Re: How I implemented my own crypto

#43

I still believe it's a bad idea to roll your own crypto, interesting as an exercise, but I would never use it in a production environment.

How will cryptography libraries ever develop if someone doesn't roll their own?

tbh, they do develop like this. Some guy come up with a library, a lot of critics arise, but the guy pushes through and many years later it becomes somehow a reference when someone big on twitter mentions it as his/her favorite crypto library.

Re: How I implemented my own crypto

#44
post #26

Earlier quoted context omitted.

C adds a layer between your code and the system. It abstracts away memory layout, locations, as well as function call semantics, and a many other things. For example, given a C program, you will not be able to tell me with certainty that a variable will occupy memory on the stack, any of your particular processor registers, etc. Formally, C is a language to control the C Abstract Machine , as described in the standar…

> Haskell I think writing timing-attack resistant code in Haskell would be very hard to impossible, at least without writing very unidiomatic code (basically "C in Haskell"). I'm happy to be proven wrong, though.

One approach would be do design an embedded DSL for implementing cryto algorithms. And then a compiler for this DSL into C or LLVM.

In fact, I believe something along the lines of this has already been done: https://cryptol.net

Re: How I implemented my own crypto

#45
post #31

Earlier quoted context omitted.

Curious about the other language. What other language that doesn't add another layer between the code and system instructions were you thinking about?

Most programming languages with compilers to native code (JIT/AOT), the myth of high level Assembler for C only applies if your computer is a PDP-11 or a basic 8-bit CPU like a 6502 or Z80. The ANSI C and C++ standards define the concept of abstract machine for the language semantics, just like in most languages. Additionally you have the concepts of sequence points, the new memory model semantics for multi-threaded…

Aren't all undocumented instructions / opcodes actually UB? If you execute an undocumented instruction the processor has to do something.

Re: How I implemented my own crypto

#46
I've always seen 'rolling your own crypto' as not being recommendation against writing your own library, but creating your own primitive.

Sure, writing your own library is very difficult, but you have a simpler set of problems, which proper testing, another set of eyes and enough tools will take care of the big problems.

Now, implementing your own primitive and recommending to use it is bad. For a primitive to be deemed secure, it has to undergo years of review and testing by seasoned cryptographers.

This isn't a recommendation to write your own library, but my opinion that it is okay to do so if you want something that none of the major libraries offer.

Re: How I implemented my own crypto

#47
post #40
post #21

Earlier quoted context omitted.

Portability is not black or white. Macros are essentially selecting different code depending on the platform. A good high-level language would not need to do this.

Just because you don't see those ugly macros to make your pure high level language portable, doesn't mean they're not there, somewhere.

Yes but this is a separation of concerns. This is precisely the point of an abstraction, especially at the level of a language and its implementations.

Writing code in Common Lisp means you're writing something with semantics promised by the Common Lisp specification. Vendors implement the spec (perhaps using nasty #ifdefs), and developers write code against the spec. The spec is a contract, and from the point of view of the programmer, it's indifferent to platform change and so on (up to what the spec says is platform-dependent, like machine integer size or maximum array length).

Just because a particular implementation may not be considered portable, doesn't mean my program (which I may choose to run on that implementation) isn't portable.

Re: How I implemented my own crypto

#48

It was a fun read, except when all the C bugs were listed. It's getting tiresome to hear about folks writing nominally Important software in a language where it is extraordinarily difficult to get things absolutely correct, with paltry excuses such as "it needs to be fast" or "it needs to be portable [0] to a VAX-11/750." It doesn't give me confidence that these completely usual bugs popped up early on, and it will n…

Curious about the other language. What other language that doesn't add another layer between the code and system instructions were you thinking about?

I'd say that Ada would be well-suited for this. Particularly for implementing crypto. It has a steep learning curve, though.

Edit: Sorry, wrote this too hastily and want to put it in perspective. While Ada is well-suited for cryptography and has some good implementations, it is probably not as secure as C crypto libraries in practice. The reason is that the implementations I know don't do OS-specific things like locking memory or preventing core dumps, and doing this in Ada is a bit harder than in C.

Re: How I implemented my own crypto

#49
post #40
post #21

Earlier quoted context omitted.

Portability is not black or white. Macros are essentially selecting different code depending on the platform. A good high-level language would not need to do this.

Just because you don't see those ugly macros to make your pure high level language portable, doesn't mean they're not there, somewhere.

It's called abstraction. It's a good thing when trying to build correct software.

Re: How I implemented my own crypto

#50
post #40
post #21

Earlier quoted context omitted.

Portability is not black or white. Macros are essentially selecting different code depending on the platform. A good high-level language would not need to do this.

Just because you don't see those ugly macros to make your pure high level language portable, doesn't mean they're not there, somewhere.

The issue here is handling portability yourself or let the language and its toolchain do it. The odds that you are doing a better job than the community to handle portability are pretty low right from the start and they get lower and lower if the laguage is well-supported.

My "ugly macros" are tested against my own implementation only. Compiler's are tested against thousands.

Post reply on HN