util.nonce_increment and util.wipe functions, also exported by each module for convenience.
This commit is contained in:
@@ -7,7 +7,7 @@ import secrets
|
|||||||
|
|
||||||
from ._loader import ffi
|
from ._loader import ffi
|
||||||
from ._loader import lib as _lib
|
from ._loader import lib as _lib
|
||||||
from .util import Buffer, new_aligned_struct, nonce_inc_inplace
|
from .util import Buffer, new_aligned_struct, nonce_increment, wipe
|
||||||
|
|
||||||
# Constants exposed as functions in C; mirror them as integers at module import time
|
# Constants exposed as functions in C; mirror them as integers at module import time
|
||||||
KEYBYTES = _lib.aegis128l_keybytes()
|
KEYBYTES = _lib.aegis128l_keybytes()
|
||||||
@@ -805,7 +805,8 @@ __all__ = [
|
|||||||
# utility functions
|
# utility functions
|
||||||
"random_key",
|
"random_key",
|
||||||
"random_nonce",
|
"random_nonce",
|
||||||
"nonce_inc_inplace",
|
"nonce_increment",
|
||||||
|
"wipe",
|
||||||
# one-shot functions
|
# one-shot functions
|
||||||
"encrypt_detached",
|
"encrypt_detached",
|
||||||
"decrypt_detached",
|
"decrypt_detached",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import secrets
|
|||||||
|
|
||||||
from ._loader import ffi
|
from ._loader import ffi
|
||||||
from ._loader import lib as _lib
|
from ._loader import lib as _lib
|
||||||
from .util import Buffer, new_aligned_struct, nonce_inc_inplace
|
from .util import Buffer, new_aligned_struct, nonce_increment, wipe
|
||||||
|
|
||||||
# Constants exposed as functions in C; mirror them as integers at module import time
|
# Constants exposed as functions in C; mirror them as integers at module import time
|
||||||
KEYBYTES = _lib.aegis128x2_keybytes()
|
KEYBYTES = _lib.aegis128x2_keybytes()
|
||||||
@@ -805,7 +805,8 @@ __all__ = [
|
|||||||
# utility functions
|
# utility functions
|
||||||
"random_key",
|
"random_key",
|
||||||
"random_nonce",
|
"random_nonce",
|
||||||
"nonce_inc_inplace",
|
"nonce_increment",
|
||||||
|
"wipe",
|
||||||
# one-shot functions
|
# one-shot functions
|
||||||
"encrypt_detached",
|
"encrypt_detached",
|
||||||
"decrypt_detached",
|
"decrypt_detached",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import secrets
|
|||||||
|
|
||||||
from ._loader import ffi
|
from ._loader import ffi
|
||||||
from ._loader import lib as _lib
|
from ._loader import lib as _lib
|
||||||
from .util import Buffer, new_aligned_struct, nonce_inc_inplace
|
from .util import Buffer, new_aligned_struct, nonce_increment, wipe
|
||||||
|
|
||||||
# Constants exposed as functions in C; mirror them as integers at module import time
|
# Constants exposed as functions in C; mirror them as integers at module import time
|
||||||
KEYBYTES = _lib.aegis128x4_keybytes()
|
KEYBYTES = _lib.aegis128x4_keybytes()
|
||||||
@@ -805,7 +805,8 @@ __all__ = [
|
|||||||
# utility functions
|
# utility functions
|
||||||
"random_key",
|
"random_key",
|
||||||
"random_nonce",
|
"random_nonce",
|
||||||
"nonce_inc_inplace",
|
"nonce_increment",
|
||||||
|
"wipe",
|
||||||
# one-shot functions
|
# one-shot functions
|
||||||
"encrypt_detached",
|
"encrypt_detached",
|
||||||
"decrypt_detached",
|
"decrypt_detached",
|
||||||
|
|||||||
+3
-2
@@ -7,7 +7,7 @@ import secrets
|
|||||||
|
|
||||||
from ._loader import ffi
|
from ._loader import ffi
|
||||||
from ._loader import lib as _lib
|
from ._loader import lib as _lib
|
||||||
from .util import Buffer, new_aligned_struct, nonce_inc_inplace
|
from .util import Buffer, new_aligned_struct, nonce_increment, wipe
|
||||||
|
|
||||||
# Constants exposed as functions in C; mirror them as integers at module import time
|
# Constants exposed as functions in C; mirror them as integers at module import time
|
||||||
KEYBYTES = _lib.aegis256_keybytes()
|
KEYBYTES = _lib.aegis256_keybytes()
|
||||||
@@ -805,7 +805,8 @@ __all__ = [
|
|||||||
# utility functions
|
# utility functions
|
||||||
"random_key",
|
"random_key",
|
||||||
"random_nonce",
|
"random_nonce",
|
||||||
"nonce_inc_inplace",
|
"nonce_increment",
|
||||||
|
"wipe",
|
||||||
# one-shot functions
|
# one-shot functions
|
||||||
"encrypt_detached",
|
"encrypt_detached",
|
||||||
"decrypt_detached",
|
"decrypt_detached",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import secrets
|
|||||||
|
|
||||||
from ._loader import ffi
|
from ._loader import ffi
|
||||||
from ._loader import lib as _lib
|
from ._loader import lib as _lib
|
||||||
from .util import Buffer, new_aligned_struct, nonce_inc_inplace
|
from .util import Buffer, new_aligned_struct, nonce_increment, wipe
|
||||||
|
|
||||||
# Constants exposed as functions in C; mirror them as integers at module import time
|
# Constants exposed as functions in C; mirror them as integers at module import time
|
||||||
KEYBYTES = _lib.aegis256x2_keybytes()
|
KEYBYTES = _lib.aegis256x2_keybytes()
|
||||||
@@ -805,7 +805,8 @@ __all__ = [
|
|||||||
# utility functions
|
# utility functions
|
||||||
"random_key",
|
"random_key",
|
||||||
"random_nonce",
|
"random_nonce",
|
||||||
"nonce_inc_inplace",
|
"nonce_increment",
|
||||||
|
"wipe",
|
||||||
# one-shot functions
|
# one-shot functions
|
||||||
"encrypt_detached",
|
"encrypt_detached",
|
||||||
"decrypt_detached",
|
"decrypt_detached",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import secrets
|
|||||||
|
|
||||||
from ._loader import ffi
|
from ._loader import ffi
|
||||||
from ._loader import lib as _lib
|
from ._loader import lib as _lib
|
||||||
from .util import Buffer, new_aligned_struct, nonce_inc_inplace
|
from .util import Buffer, new_aligned_struct, nonce_increment, wipe
|
||||||
|
|
||||||
# Constants exposed as functions in C; mirror them as integers at module import time
|
# Constants exposed as functions in C; mirror them as integers at module import time
|
||||||
KEYBYTES = _lib.aegis256x4_keybytes()
|
KEYBYTES = _lib.aegis256x4_keybytes()
|
||||||
@@ -805,7 +805,8 @@ __all__ = [
|
|||||||
# utility functions
|
# utility functions
|
||||||
"random_key",
|
"random_key",
|
||||||
"random_nonce",
|
"random_nonce",
|
||||||
"nonce_inc_inplace",
|
"nonce_increment",
|
||||||
|
"wipe",
|
||||||
# one-shot functions
|
# one-shot functions
|
||||||
"encrypt_detached",
|
"encrypt_detached",
|
||||||
"decrypt_detached",
|
"decrypt_detached",
|
||||||
|
|||||||
+14
-1
@@ -10,7 +10,7 @@ from typing import Protocol
|
|||||||
|
|
||||||
from ._loader import ffi
|
from ._loader import ffi
|
||||||
|
|
||||||
__all__ = ["new_aligned_struct", "aligned_address", "Buffer", "nonce_increment"]
|
__all__ = ["new_aligned_struct", "aligned_address", "Buffer", "nonce_increment", "wipe"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from collections.abc import Buffer as _Buffer
|
from collections.abc import Buffer as _Buffer
|
||||||
@@ -61,3 +61,16 @@ def nonce_increment(nonce: Buffer) -> None:
|
|||||||
n[i] += 1
|
n[i] += 1
|
||||||
return
|
return
|
||||||
n[i] = 0
|
n[i] = 0
|
||||||
|
|
||||||
|
|
||||||
|
def wipe(buffer: Buffer) -> None:
|
||||||
|
"""Set all bytes of the input buffer to zero.
|
||||||
|
|
||||||
|
Useful for securely clearing sensitive data from memory.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
buffer: The buffer to wipe (modified in place).
|
||||||
|
"""
|
||||||
|
n = memoryview(buffer)
|
||||||
|
for i in range(len(n)):
|
||||||
|
n[i] = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user