Live data from Hacker News

Memory Safe TLS Library Now Has AWS Crypto and FIPS

memorysafety.org

11–20 of 40 posts

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#11
post #2

But AWS Crypto is made in C/C++/ASM, so yes the wrapper is sort of safe but the implementation is not.

All safe code is inherently built on top of unsafe code.

Yes, but ideally you want the unsafe code to be as small and auditable as possible.

Most of the actual code here is unsafe.

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#12
post #2

But AWS Crypto is made in C/C++/ASM, so yes the wrapper is sort of safe but the implementation is not.

All safe code is inherently built on top of unsafe code.

Ish.

It really depends!

Fil-C is memory-safe down to the libpizlo POSIXish syscall layer, and then even those syscalls do memory safety checks (so you can't read(2) into an OOB area of a buffer, for example).

So, some safe code is built on a crapton of unsafe code, while other safe code is built on a tightly controlled TCB. There's a big spectrum there.

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#13
post #4

Earlier quoted context omitted.

All safe code is inherently built on top of unsafe code.

The Go crypto implementation uses some unsafe/asm part but it does not rely on external C/C++ lib. Very different.

It is still a safe wrapper around unsafe code. I agree that I would prefer that situation (mainly because of not needing an additional compiler) but it’s structurally the same thing.

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#14

Or you could just use memory-safe OpenSSL. https://github.com/pizlonator/deluded-openssl-3.2.0 It's based on Fil-C https://github.com/pizlonator/llvm-project-deluge/blob/delug... There's no unsafe code in it. The whole thing is recompiled with Fil-C. Works well enough that I can run a memory-safe curl and a memory-safe ssh.

"On the other hand, Fil-C is quite slow. It's 200x slower than legacy C right now. "

It's slow for good reasons, like ensuring that I have a super reliable compiler that lets me port a lot of stuff without dealing with miscompiles.

Fil-C will be fast, don't worry.

(The manifesto enumerates the hilarious reasons for the slowness. If you had read that, you probably wouldn't have cited the 200x.)

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#15

Earlier quoted context omitted.

All safe code is inherently built on top of unsafe code.

Ish. It really depends! Fil-C is memory-safe down to the libpizlo POSIXish syscall layer, and then even those syscalls do memory safety checks (so you can't read(2) into an OOB area of a buffer, for example). So, some safe code is built on a crapton of unsafe code, while other safe code is built on a tightly controlled TCB. There's a big spectrum there.

You’re describing exactly what I am describing: you still call out into a syscall that is not safe. You prevent that by checking things in the wrapper. Very standard.

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#16

Earlier quoted context omitted.

All safe code is inherently built on top of unsafe code.

Yes, but ideally you want the unsafe code to be as small and auditable as possible. Most of the actual code here is unsafe.

I agree that minimizing the unsafety is good. That doesn’t change that wrapping a small amount of unsafe code is wrapping unsafe code.

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#17
post #6

Earlier quoted context omitted.

The Rustls TLS implementation and certificate verification are all safe Rust. The underlying cryptography is still a mix of C and asm, that's the best option we have now particularly if we want support for things that make it deployable, like FIPS. We are looking for ways to improve the safety of the underlying crypto in the future.

Is it just a perf issue, or something else?

I assume you're asking why the underlying crypto still needs to be written in asm. There are two primary reasons:

1. Performance

2. Defense against side channel attacks (e.g. constant time operations)

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#18
post #2

But AWS Crypto is made in C/C++/ASM, so yes the wrapper is sort of safe but the implementation is not.

The issue with writing crypto code in anything above assembly is that there's a risk that optimizing compilers could turn your finely crafted constant time, constant power code into something which is not that.

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#19

Earlier quoted context omitted.

Ish. It really depends! Fil-C is memory-safe down to the libpizlo POSIXish syscall layer, and then even those syscalls do memory safety checks (so you can't read(2) into an OOB area of a buffer, for example). So, some safe code is built on a crapton of unsafe code, while other safe code is built on a tightly controlled TCB. There's a big spectrum there.

You’re describing exactly what I am describing: you still call out into a syscall that is not safe. You prevent that by checking things in the wrapper. Very standard.

And even in the lowest level assembly code imaginable, sometimes the syscall called by your assembly is really unsafe code: https://github.com/chrislgarry/Apollo-11/blob/master/Luminar...

Re: Memory Safe TLS Library Now Has AWS Crypto and FIPS

#20
post #18
post #2

But AWS Crypto is made in C/C++/ASM, so yes the wrapper is sort of safe but the implementation is not.

The issue with writing crypto code in anything above assembly is that there's a risk that optimizing compilers could turn your finely crafted constant time, constant power code into something which is not that.

Generally speaking, an optimizing compiler is not going to introduce a branch (especially a data-dependent branch) where one doesn't exist in the code.

To my knowledge, the bigger reasons for writing assembly for low-level cryptography are (1) performance, and (2) avoiding UB. The latter, particularly around C's type promotion and signed integer shifting rules, are a significant source of bugs[1].

[1]: https://blog.regehr.org/archives/1054

Post reply on HN