Internal switch to Crypto::Secret
This commit is contained in:
parent
abd43f0a1e
commit
a1706055e1
@ -22,10 +22,12 @@ module Sodium
|
|||||||
# Precalculate key for later use.
|
# Precalculate key for later use.
|
||||||
# Large speed gains with small data sizes and many messages.
|
# Large speed gains with small data sizes and many messages.
|
||||||
# Small speed gains with large data sizes or few 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
|
@secret_key.key.readonly do |skslice|
|
||||||
|
if LibSodium.crypto_box_beforenm(@key, @public_key.to_slice, skslice) != 0
|
||||||
raise Error.new("crypto_box_beforenm")
|
raise Error.new("crypto_box_beforenm")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Encrypts data and returns {ciphertext, nonce}
|
# Encrypts data and returns {ciphertext, nonce}
|
||||||
def encrypt(src)
|
def encrypt(src)
|
||||||
|
@ -82,8 +82,8 @@ module Sodium
|
|||||||
|
|
||||||
subkey = SecureBuffer.new subkey_size
|
subkey = SecureBuffer.new subkey_size
|
||||||
subkey.readwrite do |sub_slice|
|
subkey.readwrite do |sub_slice|
|
||||||
@sbuf.readonly do
|
@sbuf.readonly do |sslice|
|
||||||
if (ret = LibSodium.crypto_kdf_derive_from_key(sub_slice, sub_slice.bytesize, subkey_id, context, self.to_slice)) != 0
|
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)")
|
raise Sodium::Error.new("crypto_kdf_derive_from_key returned #{ret} (subkey size is probably out of range)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -63,8 +63,8 @@ module Sodium
|
|||||||
nonce ||= Nonce.random
|
nonce ||= Nonce.random
|
||||||
|
|
||||||
nonce.used!
|
nonce.used!
|
||||||
r = @key.readonly do
|
r = @key.readonly do |kslice|
|
||||||
LibSodium.crypto_secretbox_easy(dst, src, src.bytesize, nonce.to_slice, @key)
|
LibSodium.crypto_secretbox_easy(dst, src, src.bytesize, nonce.to_slice, kslice)
|
||||||
end
|
end
|
||||||
raise Sodium::Error.new("crypto_secretbox_easy") if r != 0
|
raise Sodium::Error.new("crypto_secretbox_easy") if r != 0
|
||||||
{dst, nonce}
|
{dst, nonce}
|
||||||
|
Loading…
Reference in New Issue
Block a user