summaryrefslogtreecommitdiff
path: root/lib/crypto
AgeCommit message (Collapse)AuthorFilesLines
2025-09-26lib:crypto: Use gnutls_cipher_decrypt3() if possibleAndreas Schneider1-0/+17
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Sep 26 18:38:57 UTC 2025 on atb-devel-224
2025-09-26lib:crypto: Use gnutls_cipher_encrypt3() if possibleAndreas Schneider1-22/+58
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2025-08-27lib:crypto: Don’t pass null pointer to memcpy()Jennifer Sutton1-1/+3
This results in undefined behaviour. Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-08-27lib:crypto: Remove trailing whitespaceJennifer Sutton1-30/+28
Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-01-02replace direct calls to memset_s() with commonly used macrosMichael Tokarev1-1/+1
samba provides macros for zeroing various structures in memory, and all code uses them instead of relying on memset_s(). However, a few places use memset_s() directly. Replace these usages with macros for consistency and to be able to replace memset_s() easier. A few notes. Commit 03a50d8f7d872b6ef701d12 "lib:util: Check memset_s() error code in talloc_keep_secret_destructor()" (Aug-2022) added a check for error return from memset_s(). This is the only place in whole codebase which bothers about doing this. But I've difficult time figuring out the intention. Was there a real case when this code path is actually executed? Commit 7658c9bf0a9c99e3f200571 "lib:crypto: Remove redundant array zeroing" (Nov-2023) removed the OTHER line from the two lines used to zero memory in here. Initially the code used both memset_s() *and* ZERO_ARRAY_LEN(), the former has been removed. This change removes the other - memset_s(), reintroducing ZERO_ARRAY_LEN(). Here however, it's probably better to use BURN_PTR instead of ZERO_ARRAY - in this place and a few lines above. Commit 8dddea2ceda40f2365bd6b1 "lib:talloc: Use memset_s() to avoid the call gets optimized out" (Feb-2024) is a recent commit which introduces memset_s(). However, it does not seem like it makes any difference whatsoever for a testsuite, or that it actually needs to clean up the memory to begin with. We've quite an assortment of all this memory zeroing stuff. Also it is repeated in replace.h and memory.h (two sets in these files are different but has big intersection). I'd say, to fix this mess, things from replace.h should be removed in favour of memory.h, and necessary includes added, but this is for the next time. We also have lots of direct usages of memset_s() in heimdal code. Cc: Joseph Sutton <josephsutton@catalyst.net.nz> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
2024-07-02lib:crypto: Remove unused macro definitionsJo Sutton1-9/+0
As we now require GnuTLS 3.6.13, we can rely on GnuTLS providing these macros. Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-05-16lib:crypto: Add constant denoting maximum GKDI clock skew in minutesJo Sutton1-0/+1
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-04-24lib:crypto: Fix Coverity buildJo Sutton1-1/+1
The Coverity build is failing with the following errors: [1936/5164] Compiling lib/crypto/gkdi.c In file included from /usr/lib64/gcc/x86_64-suse-linux/7/include/stdint.h:9:0, from /usr/include/inttypes.h:27, from ../../lib/crypto/../replace/replace.h:64, from ../../source4/include/includes.h:23, from ../../lib/crypto/gkdi.c:21: ../../lib/crypto/gkdi.c: In function ‘gkdi_get_key_start_time’: ../../lib/crypto/gkdi.c:197:4: error: initializer element is not constant UINT64_MAX / ^ ../../lib/crypto/gkdi.c:197:4: note: (near initialization for ‘max_gkid.l0_idx’) ../../lib/crypto/gkdi.c:200:4: error: initializer element is not constant UINT64_MAX / ^ ../../lib/crypto/gkdi.c:200:4: note: (near initialization for ‘max_gkid.l1_idx’) ../../lib/crypto/gkdi.c:204:4: error: initializer element is not constant UINT64_MAX / gkdi_key_cycle_duration % ^ ../../lib/crypto/gkdi.c:204:4: note: (near initialization for ‘max_gkid.l2_idx’) Fix the build by removing the ‘static’ specifier on this constant. Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-04-23lib/crypto: add legacy_gnutls_server_end_point_cb() if neededStefan Metzmacher3-1/+141
gnutls_session_channel_binding(GNUTLS_CB_TLS_SERVER_END_POINT) is only available with gnutls 3.7.2, but we still want to support older gnutls versions and that's easily doable... BUG: https://bugzilla.samba.org/show_bug.cgi?id=15621 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-04-21lib:crypto: Add more unit tests for GKDI functionsJo Sutton1-0/+183
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-04-16lib:crypto: Reformat source codeJo Sutton1-2/+6
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-28s4-dsdb: Populate new GKDI root keys from the server configuration objectAndrew Bartlett1-0/+2
This honours MS-GKDI 3.1.4.1.1 Creating a New Root Key Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-03-01lib:crypto: Check for overflow in GKDI rollover interval calculationJo Sutton1-1/+12
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-01lib:crypto: Correct GKDI interval start time calculationJo Sutton1-1/+1
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-01lib:crypto: Add error checking to GKDI key start time calculationJo Sutton2-5/+39
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16lib:crypto: Add test for GMSA password derivationJo Sutton2-0/+155
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16lib:crypto: Add functions for deriving gMSA passwordsJo Sutton3-0/+324
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16lib:crypto: Add more GKDI functionsJo Sutton2-0/+317
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16lib:crypto: Explicitly check for zeroJo Sutton1-1/+1
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16lib:crypto: Comment on GKDI definitionsJo Sutton1-2/+2
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16lib:crypto: Export gkid_key_type() and gkid_is_valid()Jo Sutton2-2/+6
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16lib:crypto: Fix code formattingJo Sutton3-20/+17
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-12-22lib:crypto: Add tests for GKDI key derivationJoseph Sutton2-0/+497
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Fri Dec 22 06:31:29 UTC 2023 on atb-devel-224
2023-12-22lib:crypto: Add implementation of GKDI key derivationJoseph Sutton3-1/+448
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-12-21lib:crypto: Add GKDI module with some constantsJoseph Sutton3-0/+56
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-12-08lib:crypto: Remove unused Rijndael cipher headerJoseph Sutton1-46/+0
The corresponding code was removed with commit 11b3c6826d19d60937f75825075fc5eb67385e11. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-12-08lib:crypto: Remove redundant array zeroingJoseph Sutton1-1/+0
The call to memset_s() was supposed to replace the use of ZERO_ARRAY_LEN(), but somehow both lines have crept in. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Use bytearray macrosAndreas Schneider1-2/+2
Do not use old macros which are not descriptive by the name. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-30lib:crypto: Add test for samba_gnutls_sp800_108_derive_key() using NIST test ↵Joseph Sutton1-0/+260
vectors Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Thu Nov 30 01:03:29 UTC 2023 on atb-devel-224
2023-11-30lib:crypto: Add ‘FixedData’ parameter to samba_gnutls_sp800_108_derive_key()Joseph Sutton3-20/+52
Our code won’t use this, but NIST’s test vectors are based on handing a fixed buffer to the key derivation function. View with ‘git show -b’. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Have samba_gnutls_sp800_108_derive_key() support various output ↵Joseph Sutton1-24/+63
key lengths View with ‘git show -b’. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Clean up HMAC handle in one placeJoseph Sutton1-6/+5
This is less error prone than having to ensure it’s cleaned up in every error path. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Add missing call to gnutls_hmac_deinit()Joseph Sutton1-0/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Add common out path to samba_gnutls_sp800_108_derive_key()Joseph Sutton1-3/+4
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Split out core of samba_gnutls_sp800_108_derive_key()Joseph Sutton1-34/+62
We are going to need to alter the structure of this function a little bit. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Add tests for samba_gnutls_sp800_108_derive_key()Joseph Sutton2-0/+138
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Add samba_gnutls_sp800_108_derive_key()Joseph Sutton3-0/+182
Rename smb2_key_derivation() to samba_gnutls_sp800_108_derive_key() and move it to GNUTLS_HELPERS. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Remove unused variableJoseph Sutton1-2/+0
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30lib:crypto: Remove unused importsJoseph Sutton1-1/+0
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-20Use python.h from libreplaceAndreas Schneider1-1/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15513 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-09-11lib:crypto: Fix code spellingJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-08python: Use correct function signaturesJoseph Sutton1-2/+2
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-06-30build: Remove unused check for SHA1_Update and SHA1_RENAME_NEEDEDAndrew Bartlett1-5/+0
I can not find the code that required this, even in the history. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Jun 30 14:59:46 UTC 2023 on atb-devel-224
2023-06-30Remove redundant check and fallback for AES CMAC 128 as we now require ↵Andrew Bartlett10-2627/+1
GnuTLS 3.6.13 This allows us to remove a lot of conditionally compiled code and so know with more certainly that our tests are covering our code-paths. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2023-06-30crypto: Remove aesni-intel accelerated AES crypto functionsAndrew Bartlett1-26/+0
These will shortly be unused as we will rely on GnuTLS for all AES cryptography now that we require GnuTLS 3.6.13 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2023-06-30crypto: Rely on GnuTLS 3.6.13 and gnutls_pbkdf2()Andrew Bartlett2-11/+0
This removes a lot of inline #ifdef and means this feature is always tested. We can do this as we have chosen GnuTLS 3.6.13 as the new minimum version. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2023-06-16lib: Add a few required #includesVolker Lendecke1-0/+1
You find them if you try to #include these files directly Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2023-04-03lib:crypto: Improve comment about weak cryptoAndreas Schneider1-2/+1
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-10-05lib:crypto: Change error return to SMB_ASSERT()Joseph Sutton1-8/+6
Getting an HMAC too long to fit our array is a programming error. It should always be 64 bytes exactly. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-09-12CVE-2021-20251 lib:crypto: Add Python functions for AES SAMR password changeJoseph Sutton1-0/+221
These functions allow us to perform key derivation and AES256 encryption in Python. They will be used in a following commit. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>