File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
Runtime/Algorand.Unity.Crypto Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -19,5 +19,11 @@ internal static unsafe partial class sodium
19
19
20
20
[ DllImport ( Library , CallingConvention = CallingConvention . Cdecl ) ]
21
21
internal static extern void sodium_free ( IntPtr handle ) ;
22
+
23
+ [ DllImport ( Library , CallingConvention = CallingConvention . Cdecl ) ]
24
+ internal static extern void sodium_mlock ( IntPtr handle , UIntPtr size ) ;
25
+
26
+ [ DllImport ( Library , CallingConvention = CallingConvention . Cdecl ) ]
27
+ internal static extern void sodium_munlock ( IntPtr handle , UIntPtr size ) ;
22
28
}
23
29
}
Original file line number Diff line number Diff line change @@ -27,18 +27,21 @@ public struct SecureString : INativeDisposable
27
27
public SecureString ( ReadOnlySpan < char > source )
28
28
{
29
29
totalCapacity = source . Length * 2 ;
30
- handle = SecureMemoryHandle . Create ( ( UIntPtr ) totalCapacity ) ;
30
+ var totalCapacityNUint = ( UIntPtr ) totalCapacity ;
31
+ handle = SecureMemoryHandle . Create ( totalCapacityNUint ) ;
31
32
unsafe
32
33
{
33
34
fixed ( char * sourceptr = source )
34
35
{
36
+ sodium . sodium_mlock ( ( IntPtr ) sourceptr , totalCapacityNUint ) ;
35
37
var error = UTF8ArrayUnsafeUtility . Copy (
36
38
handle . GetUnsafePtr ( ) ,
37
39
out length ,
38
40
totalCapacity - 1 ,
39
41
sourceptr ,
40
42
source . Length
41
43
) ;
44
+ sodium . sodium_munlock ( ( IntPtr ) sourceptr , totalCapacityNUint ) ;
42
45
if ( error != CopyError . None )
43
46
{
44
47
if ( handle . IsCreated ) handle . Dispose ( ) ;
You can’t perform that action at this time.
0 commit comments