8000 Add support for libsodium 1.0.19 by uio-torjus · Pull Request #138 · saltstack/libnacl · GitHub
[go: up one dir, main page]

Skip to content

Add support for libsodium 1.0.19 #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add SHA256/512 HKDF
  • Loading branch information
uio-torjus committed Jan 10, 2024
commit 1039f1e6f864d80e4067a6b60173aa5ecfdca980
67 changes: 67 additions & 0 deletions libnacl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,23 @@ class CryptError(Exception):
HAS_CRYPT_KDF = True
except AttributeError:
HAS_CRYPT_KDF = False

try:
crypto_kdf_hkdf_sha256_KEYBYTES = nacl.crypto_kdf_hkdf_sha256_keybytes()
crypto_kdf_hkdf_sha256_BYTES_MIN = nacl.crypto_kdf_hkdf_sha256_bytes_min()
crypto_kdf_hkdf_sha256_BYTES_MAX = nacl.crypto_kdf_hkdf_sha256_bytes_max()
HAS_CRYPT_KDF_HKDF_SHA256 = True
except AttributeError:
HAS_CRYPT_KDF_HKDF_SHA256 = False

try:
crypto_kdf_hkdf_sha512_KEYBYTES = nacl.crypto_kdf_hkdf_sha512_keybytes()
crypto_kdf_hkdf_sha512_BYTES_MIN = nacl.crypto_kdf_hkdf_sha512_bytes_min()
crypto_kdf_hkdf_sha512_BYTES_MAX = nacl.crypto_kdf_hkdf_sha512_bytes_max()
HAS_CRYPT_KDF_HKDF_SHA512 = True
except AttributeError:
HAS_CRYPT_KDF_HKDF_SHA512 = False


try:
crypto_kx_PUBLICKEYBYTES = nacl.crypto_kx_publickeybytes()
Expand Down Expand Up @@ -1371,6 +1388,56 @@ def crypto_kdf_derive_from_key(subkey_size, subkey_id, context, master_key):
nacl.crypto_kdf_derive_from_key(buf, subkey_size, ctypes.c_ulonglong(subkey_id), context, master_key)
return buf.raw

def crypto_kdf_hkdf_sha256_keygen():
buf = ctypes.create_string_buffer(crypto_kdf_hkdf_sha256_KEYBYTES)
nacl.crypto_kdf_hkdf_sha256_keygen(buf)
return buf.raw

def crypto_kdf_hkdf_sha256_extract(salt, key):
prk = ctypes.create_string_buffer(crypto_kdf_hkdf_sha256_KEYBYTES)
nacl.crypto_kdf_hkdf_sha256_extract(
prk,
salt, len(salt),
key, len(key)
)
return prk.raw

def crypto_kdf_hkdf_sha256_expand(size, ctx, prk):
out = ctypes.create_string_buffer(size)
ret = nacl.crypto_kdf_hkdf_sha256_expand(
out, size,
ctx, len(ctx),
prk
)
if ret:
raise ValueError("Error")
return out.raw

def crypto_kdf_hkdf_sha512_keygen():
buf = ctypes.create_string_buffer(crypto_kdf_hkdf_sha512_KEYBYTES)
nacl.crypto_kdf_hkdf_sha512_keygen(buf)
return buf.raw

def crypto_kdf_hkdf_sha512_extract(salt, key):
prk = ctypes.create_string_buffer(crypto_kdf_hkdf_sha512_KEYBYTES)
nacl.crypto_kdf_hkdf_sha512_extract(
prk,
salt, len(salt),
key, len(key)
)
return prk.raw

def crypto_kdf_hkdf_sha512_expand(size, ctx, prk):
out = ctypes.create_string_buffer(size)
ret = nacl.crypto_kdf_hkdf_sha512_expand(
out, size,
ctx, len(ctx),
prk
)
if ret:
raise ValueError("Error")
return out.raw

# Key Exchange API

def crypto_kx_keypair():
Expand Down
Loading
0