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 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
|
||||
KEYBYTES = _lib.aegis128l_keybytes()
|
||||
@@ -805,7 +805,8 @@ __all__ = [
|
||||
# utility functions
|
||||
"random_key",
|
||||
"random_nonce",
|
||||
"nonce_inc_inplace",
|
||||
"nonce_increment",
|
||||
"wipe",
|
||||
# one-shot functions
|
||||
"encrypt_detached",
|
||||
"decrypt_detached",
|
||||
|
||||
@@ -7,7 +7,7 @@ import secrets
|
||||
|
||||
from ._loader import ffi
|
||||
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
|
||||
KEYBYTES = _lib.aegis128x2_keybytes()
|
||||
@@ -805,7 +805,8 @@ __all__ = [
|
||||
# utility functions
|
||||
"random_key",
|
||||
"random_nonce",
|
||||
"nonce_inc_inplace",
|
||||
"nonce_increment",
|
||||
"wipe",
|
||||
# one-shot functions
|
||||
"encrypt_detached",
|
||||
"decrypt_detached",
|
||||
|
||||
@@ -7,7 +7,7 @@ import secrets
|
||||
|
||||
from ._loader import ffi
|
||||
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
|
||||
KEYBYTES = _lib.aegis128x4_keybytes()
|
||||
@@ -805,7 +805,8 @@ __all__ = [
|
||||
# utility functions
|
||||
"random_key",
|
||||
"random_nonce",
|
||||
"nonce_inc_inplace",
|
||||
"nonce_increment",
|
||||
"wipe",
|
||||
# one-shot functions
|
||||
"encrypt_detached",
|
||||
"decrypt_detached",
|
||||
|
||||
@@ -7,7 +7,7 @@ import secrets
|
||||
|
||||
from ._loader import ffi
|
||||
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
|
||||
KEYBYTES = _lib.aegis256_keybytes()
|
||||
@@ -805,7 +805,8 @@ __all__ = [
|
||||
# utility functions
|
||||
"random_key",
|
||||
"random_nonce",
|
||||
"nonce_inc_inplace",
|
||||
"nonce_increment",
|
||||
"wipe",
|
||||
# one-shot functions
|
||||
"encrypt_detached",
|
||||
"decrypt_detached",
|
||||
|
||||
@@ -7,7 +7,7 @@ import secrets
|
||||
|
||||
from ._loader import ffi
|
||||
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
|
||||
KEYBYTES = _lib.aegis256x2_keybytes()
|
||||
@@ -805,7 +805,8 @@ __all__ = [
|
||||
# utility functions
|
||||
"random_key",
|
||||
"random_nonce",
|
||||
"nonce_inc_inplace",
|
||||
"nonce_increment",
|
||||
"wipe",
|
||||
# one-shot functions
|
||||
"encrypt_detached",
|
||||
"decrypt_detached",
|
||||
|
||||
@@ -7,7 +7,7 @@ import secrets
|
||||
|
||||
from ._loader import ffi
|
||||
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
|
||||
KEYBYTES = _lib.aegis256x4_keybytes()
|
||||
@@ -805,7 +805,8 @@ __all__ = [
|
||||
# utility functions
|
||||
"random_key",
|
||||
"random_nonce",
|
||||
"nonce_inc_inplace",
|
||||
"nonce_increment",
|
||||
"wipe",
|
||||
# one-shot functions
|
||||
"encrypt_detached",
|
||||
"decrypt_detached",
|
||||
|
||||
@@ -10,7 +10,7 @@ from typing import Protocol
|
||||
|
||||
from ._loader import ffi
|
||||
|
||||
__all__ = ["new_aligned_struct", "aligned_address", "Buffer", "nonce_increment"]
|
||||
__all__ = ["new_aligned_struct", "aligned_address", "Buffer", "nonce_increment", "wipe"]
|
||||
|
||||
try:
|
||||
from collections.abc import Buffer as _Buffer
|
||||
@@ -61,3 +61,16 @@ def nonce_increment(nonce: Buffer) -> None:
|
||||
n[i] += 1
|
||||
return
|
||||
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