Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for long vectors #22

Merged
merged 1 commit into from
Jun 11, 2022
Merged

Conversation

richfitz
Copy link
Contributor

Currently (v1.2.0) sodium::data_encrypt is limited to encrypting vectors of length 2^31-17 or less. There are two slightly separate issues here:

library(sodium)
key <- sha256(charToRaw("This is a secret passphrase"))
cipher <- data_encrypt(raw(2^31 - 17), key) # works fine
cipher <- data_encrypt(raw(2^31 - 16), key) # integer overflow
## Error in data_encrypt(raw(2^31 - 16), key) : 
##   negative length vectors are not allowed
cipher <- data_encrypt(raw(2^31), key) # no support for long vectors
## Error in data_encrypt(raw(2^31), key) : 
##  long vectors not supported yet: memory.c:3887

This PR makes minor changes to the length access and storage to prevent this, following the API in R-ints where we use XLENGTH and type R_xlen_t which should be portable.

I've fairly blindly added these to the "large" components - i.e., messages and ciphertexts, but not to keys and nonces.

The package does not currently have tests, but current examples work with these changes.

@jeroen jeroen merged commit 65faf9f into r-lib:master Jun 11, 2022
@jeroen
Copy link
Member

jeroen commented Jun 11, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants