rage icon indicating copy to clipboard operation
rage copied to clipboard

PBE default work factor can cause OOM issues on memory-constrained environments

Open tekul opened this issue 2 years ago • 0 comments

I'm using PBE within a webapp to encrypt data on a per user basis. This appeared to work Ok, but I noticed my app was dying with an OOM error when I deployed it to fly.io. Further investigation shows that a single scrypt-based encryption is using over 500Mb which seems to be the cause. I've created a repo with the code I used to test the issue and added the output from heaptrack

heaptrack

I would like to be able to limit or set the work factor to cap memory usage - I notice there was a previous PR, #334, which did this, so I can create a fork along similar lines and use that with hard-coded values.

You mentioned a necessary refactor due to plans in the Go implementation to change PBE. Do you have a reference or a link for that? I realise there are different expectations between using a CLI to encrypt files and an API in an app, but it would be nice to have more control in the latter case since I have no control over how the work-factor is assigned on the cloud-based system and the performance-based work-factor estimate will also have an impact on the memory used.

tekul avatar May 01 '23 13:05 tekul