Interface SecureMemory.Native
- All Known Implementing Classes:
LazySodium,LazySodiumJava
- Enclosing interface:
- SecureMemory
public static interface SecureMemory.Native
-
Method Summary
Modifier and TypeMethodDescriptioncom.sun.jna.PointersodiumAllocArray(int count, int size) Returns a pointer from which count objects that are size bytes of memory each can be accessed.voidsodiumFree(com.sun.jna.Pointer p) Unlocks and deallocates memory allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)}.com.sun.jna.PointersodiumMalloc(int size) Returns a pointer from which exactly size contiguous bytes of memory can be accessed.booleansodiumMemZero(byte[] pnt, int len) The sodium_memzero() function tries to effectively zero len bytes starting at pnt, even if optimizations are being applied to the code.booleansodiumMLock(byte[] array, int len) Locks at least len bytes of memory from the array.booleansodiumMProtectNoAccess(com.sun.jna.Pointer ptr) Makes a region allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)} inaccessible.booleansodiumMProtectReadOnly(com.sun.jna.Pointer ptr) Marks a region allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)} as read-only.booleansodiumMProtectReadWrite(com.sun.jna.Pointer ptr) Marks a region allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)} as readable and writable, after having been protected usingsodiumMProtectReadOnly(Pointer)orsodiumMProtectNoAccess(Pointer)}/booleansodiumMUnlock(byte[] array, int len) Unlocks at least len bytes of memory from the array.
-
Method Details
-
sodiumMemZero
boolean sodiumMemZero(byte[] pnt, int len) The sodium_memzero() function tries to effectively zero len bytes starting at pnt, even if optimizations are being applied to the code.- Parameters:
pnt- The byte array to zero out.len- How many bytes to zero out.- Returns:
- True if zeroed
-
sodiumMLock
boolean sodiumMLock(byte[] array, int len) Locks at least len bytes of memory from the array. This can help avoid swapping sensitive data to disk.- Parameters:
array- Array to lock.len- Number of bytes to lock.- Returns:
- True if locked, false otherwise.
-
sodiumMUnlock
boolean sodiumMUnlock(byte[] array, int len) Unlocks at least len bytes of memory from the array.- Parameters:
array- Array to unlock.len- Number of bytes to unlock.- Returns:
- True if unlocked, false otherwise.
-
sodiumMalloc
com.sun.jna.Pointer sodiumMalloc(int size) Returns a pointer from which exactly size contiguous bytes of memory can be accessed.- Parameters:
size- The size of the byte array to allocate.- Returns:
- A Pointer to the byte array.
-
sodiumAllocArray
com.sun.jna.Pointer sodiumAllocArray(int count, int size) Returns a pointer from which count objects that are size bytes of memory each can be accessed. It provides the same guarantees assodiumMalloc(int)but also protects against arithmetic overflows when count * size exceeds SIZE_MAX.- Parameters:
count- Number of objectssize- Size of those objects- Returns:
- A Pointer to the resulting array.
-
sodiumFree
void sodiumFree(com.sun.jna.Pointer p) Unlocks and deallocates memory allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)}.- Parameters:
p- The pointer to which an array shall be freed.
-
sodiumMProtectNoAccess
boolean sodiumMProtectNoAccess(com.sun.jna.Pointer ptr) Makes a region allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)} inaccessible. It cannot be read or written, but the data is preserved.- Parameters:
ptr- The pointer to a region to decline access to.- Returns:
- True if operation completed successfully.
-
sodiumMProtectReadOnly
boolean sodiumMProtectReadOnly(com.sun.jna.Pointer ptr) Marks a region allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)} as read-only. Attempting to modify the data will cause the process to terminate.- Parameters:
ptr- Pointer to the region.- Returns:
- True if operation completed successfully.
-
sodiumMProtectReadWrite
boolean sodiumMProtectReadWrite(com.sun.jna.Pointer ptr) Marks a region allocated usingsodiumMalloc(int)orsodiumAllocArray(int, int)} as readable and writable, after having been protected usingsodiumMProtectReadOnly(Pointer)orsodiumMProtectNoAccess(Pointer)}/- Parameters:
ptr- Pointer to the region.- Returns:
- True if operation completed successfully.
-