-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit add3e52c0e6ba22048a0d76fd7d0e431890b20d3 Author: Nicolas Chabbey <[email protected]> Date: Mon Feb 27 15:40:51 2023 +0100 Implemented AES decrypt function Updated cli.py for shared cmd-line options Add new cli test for aes.decrypt() Moved test constants out of constants.py commit 6ffec270da0e8e26f5adf5db0d584861d420acb0 Author: Nicolas Chabbey <[email protected]> Date: Mon Feb 27 10:40:57 2023 +0100 Moved PBKDF2 function in its own module Renamed directory /ciphers to /crypto
- Loading branch information
Showing
7 changed files
with
276 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
kryptoxin PBKDF2 module. | ||
This is the key-derivation function PBKDF2 module of the kryptoxin project. | ||
""" | ||
from ..core import log | ||
from ..core.constants import * | ||
import hashlib | ||
|
||
|
||
def derive_key(key, key_size, halg, iter, salt): | ||
""" This function perform the key derivation function | ||
using PBKDF2. | ||
Arguments: | ||
key: Cipher's key (bytes[]) | ||
key_size: Algorithm key size | ||
halg: PBKDF2 HMAC algorithm | ||
iter: Number of iterations for the key-derivation function | ||
salt: Salt used to enhance hash security (bytes[]) | ||
""" | ||
# Derived key sizes per block-cipher algorithms. | ||
# must be 16, 24 or 32 bytes for AES128,192,256 respectively. | ||
dklen = CIPHER_PBKDF2_AES256_KS | ||
if key_size == 128: | ||
dklen = CIPHER_PBKDF2_AES128_KS | ||
elif key_size == 192: | ||
dklen = CIPHER_PBKDF2_AES192_KS | ||
elif key_size == 256: | ||
dklen = CIPHER_PBKDF2_AES256_KS | ||
else: | ||
log.error(f"Invalid AES key size '{key_size}") | ||
raise SystemExit | ||
|
||
# Derive the encryption key from the password. | ||
derived_key = hashlib.pbkdf2_hmac(halg, memoryview( | ||
key), memoryview(salt), iter, dklen) | ||
|
||
# return the derived_key | ||
return derived_key |
Oops, something went wrong.