2
votes

I've successfully built and compiled an application on my PC which will generate an RSA keypair (I used GPK for the long arithmetic). I then tested encryption/decryption on a string "Hello World" (ASCII --> Hex transform first).

The question I have is, is is mathematically possible to only decrypt "Hello" from my cipher-text string "Hello World", or would I have to encrypt "Hello" first, then encrypt "World", and then decrypt them separately?

EDIT: My desired use-case:

I have a chip (Zynq SoC from Xilinx), which only has 256K of on chip memory, and 512K of L2 cache.

I can prefill and lock the cache with some basic instructions/data, and then use the 256K for my stack, heap, and .data/.bss sections of code (variables).

I need more space, so I was thinking I could use the 256K as "swap" space, and fetch the rest of the .text (the instruction code) from the external, encrypted flash, but I need to decrypt it on-chip to maintain the security.

I was wondering if I could encrypt the entire image, then "fetch, decrypt, decode, execute". It looks like I might be restricted to encrypting my image in 256K chunks, and decrypting it in that size of chunks as well.

1
Can you post your code?CodesInChaos
Don't use RSA for this. Use a block cipher, like AES - those support the kind of chunked operation you're thinking of, and at a much smaller chunk size (e.g, 128 or 256 bits at a time). I believe the Zynq SOC may even have AES in hardware already.user149341

1 Answers

2
votes

RSA is a mathematical operation. You can't recover only part of the plain text; doing the math (cd mod n) will yield the entire plain text. As you suggest, you'd have to perform two separate RSA encryption operations if you want to decrypt two parts separately.

This sounds a bit like an X-Y problem. What are you really trying to accomplish?


Update: RSA is best used as a key encryption algorithm: instead of encrypting data directly, you encrypt the key for a symmetric algorithm with RSA, then encrypt your application data with that symmetric algorithm. This is the way RSA is used in protocols like TLS, S/MIME, PGP, and any other widely accepted protocol.

So, use an algorithm like AES (use a suitable mode, preferably one that provides integrity protection) together with RSA for a secure and efficient system.