Score:1

Why does it take more time to decrypt the same file with 256 bit RSA in TEE than in REE?

cn flag

We all know that TEE can utilize almost all of the CPU's performance, so its time spent encrypting files using RSA256 is less than that of REE.

But why isn't decryption?

Why does it take more time to decrypt the same file with 256 bit RSA in TEE than in REE?

Maarten Bodewes avatar
in flag
Note that public key encryption is generally not performed in a TEE whatsoever. Only private key operations are usually performed inside of the TEE, and usually the TEE uses specialized hardware, which means a setup, communication and operation overhead. Without more detail that's all that may be said. Beware that implementation issues are generally considered off topic here, so if you use specific code to test you may try [so] instead.
fgrieu avatar
ng flag
I had to google REE (Rich Execution Environment), and I can't tell what that means exactly. I don't see that all "TEE can utilize almost all of the CPU's performance". Much to the contrary, many TEE (Trusted Execution Environments) are relatively small dedicated ICs that _can't_ use the main CPU (e.g. in some smartphones). I suspect the question is off-topic, and I'm sure the context should be explained better.
Gilles 'SO- stop being evil' avatar
cn flag
@fgrieu Actually “TEE” usually means an environment that's not a separate IC. In smartphones, “TEE” is pretty much synonymous with “TrustZone secure world“. I'm not sure the question is on-topic; the answer does touch on cryptography implementation, but only at a superficial level.
fgrieu avatar
ng flag
@Gilles'SO-stopbeingevil' : ah if we take TrustZone as the model of what a Trusted Execution Environment is, and Rich Execution Environment the rest of what the main CPU can do, I see better what the question is about. I do know smartphones where some select cryptographic tasks are implemented in a dedicated security IC (similar to a PC's TPM), rather than by the main CPU, and thought that was a TEE. At least, in theses devices, we can't really trust anything the main CPU does is safe from prying eyes of other processes, because there are so many side channels.
Dylan avatar
bb flag
I don't agree with "TEE can utilize almost all of the CPU's performance". Take Intel SGX as an example. In most cases, when you run applications inside the SGX enclave, it will take more time due to the context switch which may be caused by system calls or exceed EPC memory. For example, if you GDB the SGX applications, you will find that the process jumps to REE when the process initiates time-dependent calls. Eventually, it takes more time. Overall, It will not reduce the running time if the program is in SGX. There may be some concepts you missed.
Score:1
cn flag

Performance is not a generic property of either a cryptographic operation or a type of execution environment. It's a property of a specific implementation in a specific environment. So it is not generically true that “it take[s] more time to decrypt the same file with 256 bit RSA in TEE than in REE”. However there are plausible reasons why this could be the case.

(Background: a TEE (Trusted Execution Environment) is an environment which is isolated from the main operating system (REE: Rich Execution Environment) by a combination of hardware and software means. This can mean running on a different processor, or on the same processor in a different virtual machine, or on the same processor with some isolation technology such as SGX on x86 or TrustZone on arm. Usually the people who tend to use the terms “TEE” and “REE” work with TrustZone or SGX.)

A TEE running on the main processor does have all the computing power of the processor, so if it's running the exact same code, it will go as fast. However, in practice, it's likely that the TEE isn't running the same code as the REE.

SGX and TrustZone protect the TEE against direct attacks, such as REE code attempting to read memory used by the TEE. But it doesn't protect against side channel attacks. For example, the cache is shared between the TEE and the REE; the REE can't read a TEE cache line, but it can observe when the TEE displaces a cache line, so it can conduct cache timing attacks. As a consequence, software running in the TEE must protect itself against cache timing attacks. The TEE is especially vulnerable against timing attacks because the REE operating system has access to fine-grained timers, more so than an unprivileged REE process attacking another process. Defenses against side channel leakage costs performance.

In addition to countermeasures in the TEE's cryptography implementation, the TEE operating system may have countermeasures such as more frequent cache eviction, that also improve security at the detriment of performance.

It's also possible that the TEE implementation of cryptography is simply less well optimized than the REE implementation. The REE is probably running OpenSSL or a fork of OpenSSL, and OpenSSL is where most optimization effort goes outside of processor- and algorithm-specific hand-optimized assembly code. Less manpower tends to go into cryptographic optimization in a TEE.

If you're measuring timing from an REE application, there's a cost to dispatching the operation to the TEE. That cost is typically negligible for asymmetric cryptography though, especially RSA decryption which requires a large amount of computation. For symmetric cryptography, it can be substantial.

You don't say what type of TEE you're looking at. A TEE can be implemented as a separate chip, which is usually a lower-performance one since it's special purpose and therefore has to be cheap. For example, a discrete TPM is a lot slower than a even the cheapest application processor that it can be plugged into, and even dedicated accelerators for asymmetric cryptography don't fully compensate.

P.S. 256-bit RSA was ridiculously weak even in the 1980s. 2048 bits (256 bytes) is a typical RSA key size these days.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.