Internal switch to Crypto::Secret

master
Didactic Drunk 2021-06-21 02:53:06 -07:00
parent abd43f0a1e
commit a1706055e1
3 changed files with 8 additions and 6 deletions

View File

@ -22,8 +22,10 @@ module Sodium
# Precalculate key for later use.
# Large speed gains with small data sizes and many messages.
# Small speed gains with large data sizes or few messages.
if LibSodium.crypto_box_beforenm(@key, @public_key.to_slice, @secret_key.to_slice) != 0
raise Error.new("crypto_box_beforenm")
@secret_key.key.readonly do |skslice|
if LibSodium.crypto_box_beforenm(@key, @public_key.to_slice, skslice) != 0
raise Error.new("crypto_box_beforenm")
end
end
end

View File

@ -82,8 +82,8 @@ module Sodium
subkey = SecureBuffer.new subkey_size
subkey.readwrite do |sub_slice|
@sbuf.readonly do
if (ret = LibSodium.crypto_kdf_derive_from_key(sub_slice, sub_slice.bytesize, subkey_id, context, self.to_slice)) != 0
@sbuf.readonly do |sslice|
if (ret = LibSodium.crypto_kdf_derive_from_key(sub_slice, sub_slice.bytesize, subkey_id, context, sslice)) != 0
raise Sodium::Error.new("crypto_kdf_derive_from_key returned #{ret} (subkey size is probably out of range)")
end
end

View File

@ -63,8 +63,8 @@ module Sodium
nonce ||= Nonce.random
nonce.used!
r = @key.readonly do
LibSodium.crypto_secretbox_easy(dst, src, src.bytesize, nonce.to_slice, @key)
r = @key.readonly do |kslice|
LibSodium.crypto_secretbox_easy(dst, src, src.bytesize, nonce.to_slice, kslice)
end
raise Sodium::Error.new("crypto_secretbox_easy") if r != 0
{dst, nonce}