Commit Graph

598 Commits

Author SHA1 Message Date
Nicolas Williams
c607135a03 Use fallthrough statement attribute (moar) 2022-01-14 16:53:34 -06:00
Nicolas Williams
ddc6113610 Use fallthrough statement attribute 2022-01-14 16:32:58 -06:00
Nicolas Williams
489da75e65 tommath: Fix warning in s_read_getrandom()
See https://github.com/libtom/libtommath/pull/512

(Note: this has not shipped.  Only OS X would be affected, specifically
RSA key gen would be affected on OS X.)
2022-01-14 15:26:59 -06:00
Nicolas Williams
05e8c0ede6 Check HMAC_Init_ex() return value 2022-01-14 12:48:32 -06:00
Nicolas Williams
52f3dc6aa4 hcrypto: HMAC_Init_Ex(): return int like OpenSSL 2022-01-14 12:48:32 -06:00
Nicolas Williams
77392d5d9c hcrypto: Fix warnings 2022-01-14 12:48:32 -06:00
Nicolas Williams
e56b558616 osx: Import fix for tommath #159 2022-01-13 19:56:12 -06:00
Nicolas Williams
0c7b06f9ca cf: Check cc support of -Werror=enum-conversion 2022-01-13 15:33:04 -06:00
Marc Dionne
fc4b3ce49b hcrypto: Fix return type for null_Init, null_Update and null_Final
The hc_evp_md_init, hc_evp_md_update and hc_evp_md_final typedefs
are defined as functions returning an int, but null_Init, null_Update
and null_Final are defined as void, and cast with the typedef when
assigned to the function vector.

This might result in some uninitialized value being returned to the
caller, if some of them make use of the return value.  It also causes
warnings if the -Wcast-function-type warning is enabled.

Change the type to in to match the typedef, and return 1 (success).
2022-01-13 16:00:50 -05:00
Nicolas Williams
bc7c73b5d7 hcrypto: Fix build with clang-13 2022-01-02 20:58:39 -06:00
Andrew Bartlett
7686028718 Use UTF-8 in KTH copyright notice
Samba is starting to protect against bi-di attacks and the starting point
is to require that input files be fully UTF-8.  In 2021 this is a reasonable
starting point anyway.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-11-29 12:50:26 +11:00
Nicolas Williams
a2d827ca1d hcrypto: Disable errors for now that should be fixed 2020-09-07 22:04:59 -05:00
Andrew Bartlett
44b2d68536 Squash using #if 0 a longstanding TODO to avoid warnings
Seen on Ubuntu 18.04 with
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
giving:

test_cipher.c: In function ‘test_cipher’:
test_cipher.c:299:19: error: suggest braces around empty body in an ‘if’ statement [-Werror=empty-body]
  /* XXXX check  */;
                   ^
cc1: all warnings being treated as errors

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2020-05-28 11:10:57 -04:00
Andrew Bartlett
9ffbc17a0f Fix (deliberately) unused variable warning in rsa-ltm.c
Seen on Ubuntu 18.04 with
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
giving:

rsa-ltm.c: In function ‘ltm_rsa_private_calculate’:
rsa-ltm.c:135:9: error: variable ‘where’ set but not used [-Werror=unused-but-set-variable]
     int where = 0; /* Ignore the set-but-unused warning from this */
         ^~~~~
rsa-ltm.c: In function ‘gen_p’:
rsa-ltm.c:482:9: error: variable ‘where’ set but not used [-Werror=unused-but-set-variable]
     int where = 0; /* Ignore the set-but-unused warning from this */
         ^~~~~

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2020-05-28 11:10:57 -04:00
Nicolas Williams
001cf39374 hcrypto: Fix more warnings (rsa-ltm) 2020-04-27 17:56:59 -05:00
Nicolas Williams
f88526ae78 hcrypto: Fix leaks in test_rsa.c 2020-04-27 13:14:21 -05:00
Nicolas Williams
32517c0627 hcrypto: Better RSA key generation (ltm) 2020-04-27 13:14:21 -05:00
Nicolas Williams
e4d1a91c13 hcrypto: Fix warnings in LTM 2020-04-27 13:14:21 -05:00
Luke Howard
4a7eb74374 gss: SAnon - the Simple Anonymous GSS-API mechanism
Add support for SAnon, a simple key agreement protocol that provides no
authentication of initiator or acceptor using x25519 ECDH key exchange.
See doc/standardization/draft-howard-gss-sanon-xx.txt for a protocol
description.
2020-04-25 23:19:30 -05:00
Luke Howard
beda11a079 hcrypto: Add X25519
The X25519 implementation comes from libsodium. Explicit copyright
notices have been added to each file as well as some portability changes
(e.g. align.h).
2020-04-25 23:19:30 -05:00
Luke Howard
dfb1e6fcf8 hcrypto: trim number of trials in prime number generation
Reduce the number of trials when generating RSA keys by calling
mp_prime_rabin_miller_trials() with the number of desired bits.

See libtom/libtommath#482.
2020-04-24 11:59:54 +10:00
Luke Howard
7eb397834e hcrypto: make libtommath v1.2.0 work with Heimdal 2020-04-24 11:59:54 +10:00
Luke Howard
c403b66082 hcrypto: import libtommath v1.2.0 2020-04-24 11:59:54 +10:00
Nicolas Williams
cc6a3f337b hcrypto: Fix Makefile build race 2020-03-17 19:46:37 -05:00
Rod Widdowson
7b8fa4758c Windows: Fix type cast warning.
Since at least SDK V6.1 HCRYPTPROV has been specified as ULONG_PTR
this means that comparing or setting one with NULL causes a cast
warning.

Use an explicit cast from zero to that type.
2020-02-01 12:32:09 +11:00
Luke Howard
a17a6bcc54 hcrypto: support BCRYPT_HASH_REUSABLE_FLAG
support BCRYPT_HASH_REUSABLE_FLAG in the WinCNG backend on versions of Windows
that support it, to avoid destroying and recreating a hash object
2019-12-05 20:20:28 -05:00
Nicolas Williams
8bc5d5af10 hcrypto: fix off-by-one set-bit counting 2019-07-09 12:34:26 -05:00
Luke Howard
5c70e5015e hcrypto-pkcs11: check mechanism flags
Before committing to a PKCS#11 mechanism, check that it can provide the
required encryption or digest services by validating the flags returned by
C_GetMechanismInfo().
2019-05-18 17:15:26 -04:00
Luke Howard
befe1b8f90 always load plugins with RTLD_LOCAL/RTLD_GROUP if available 2019-01-03 20:06:27 -06:00
Nicolas Williams
752c3a6139 Fix warning in lib/hcrypto/test_dh.c 2019-01-02 13:56:04 -05:00
Luke Howard
014f16883c libhcrypto: UI_UTIL_FLAG_VERIFY_SILENT 2018-12-30 15:39:49 -06:00
Luke Howard
65ed504d21 hcrypto: print failure on password mismatch (#469)
UI_UTIL_read_pw_string(), an interface borrowed from OpenSSL, should report
password verification failure to stderr.
2018-12-27 17:40:57 +11:00
David Mulder
f132d2040d solaris 8 sparc defines _LP64 to empty, causing build failure 2018-12-23 20:30:12 -06:00
Damir Franusic
329918bd67 hcrypto: fix include path 2018-12-24 02:25:08 +00:00
Olly Betts
7ad6c01a8d Fix assorted typos 2018-12-14 17:30:14 -05:00
Simon Wilkinson
2d84fc65bb hcrypto: Make more buffers persist across HMAC operations
If we don't change MD algorithm across two calls to HMAC_Init_ex
using the same context, don't bother reallocating all of our buffers.
2018-05-23 09:54:27 -04:00
Simon Wilkinson
c1eb9828f4 hcrypto: Add HMAC_CTX_new and HMAC_CTX_free
Add a pair of functions which can be used to allocate and free
an HMAC_CTX structure on the heap. This means that the caller doesn't
need to know the size of the underlying structure.
2018-05-23 09:54:27 -04:00
Luke Howard
bd2c2eb8bd hcrypto WinCNG backend: zero rgb{Hash,Key}Object on reinit
In the interest of being paranoid, when a WinCNG crypto or digest
context is being reinitialized, zero out the backing store as well
as destroying the handle.
2018-05-12 13:54:15 +10:00
Luke Howard
934d5e09bf hcrypto PKCS#11 backend: Call C_Initialize() on every hcrypto call
This is required as the PKCS#11 library needs to be reinitialized after
forking. This was causing a problem with ipropd.

This fix appears to incur a repeatable 10ms performance penalty on aes-test.

Caching the initialization status using a once control and invalidating it
on fork provided no measurable performance benefit on Solaris 11. Other
approaches would not be thread-safe or would involve more intrusive code
changes, such as exposing heimbase's atomics.
2018-05-12 13:45:30 +10:00
Luke Howard
3224a282a6 hcrypto WinCNG backend: don't leak handles on crypto reinit
Similar fix to a88d0066, but for the WinCNG EVP backend. However this
is just a fix for leaking handles if the same EVP context is used with
a new key; there is no functionality issue as cipherstate is maintained
directly in the EVP context, not internally by WinCNG.
2018-05-11 21:31:34 +10:00
Luke Howard
bd0b6f8c2b hcrypto WinCNG backend: don't leak handles on digest reinit
Similar fix to 9518f296, but for the WinCNG EVP backend.
2018-05-11 21:06:27 +10:00
Luke Howard
9518f2965b hcrypto PKCS#11 backend: don't leak sessions on digest reinit
Clients of the EVP API can reinitialize message digest contexts
without destroying them. The PKCS#11 backend assumed they were
only used once, and was leaking session handles upon reinitialization.
This fix disposes of any existing PKCS#11 message digest context
in the initialization method.
2018-05-11 20:45:10 +10:00
Luke Howard
6a1bb95323 hcrypto PKCS#11 backend: allow digest update with NULL (#378)
In the PKCS#11 backend, add an assertion check to p11_md_update()
to validate that the data length is zero if the data is NULL.
2018-05-11 13:50:38 +10:00
Luke Howard
590be3d7da hcrypto PKCS#11 backend: allow digest update with NULL (#378)
Some callers of EVP_DigestUpdate (such as libntlm) pass NULL as the
data argument. PKCS#11 returns CKR_ARGUMENTS_BAD which may poison
the context. Pass an empty string to C_DigestUpdate work around this.
2018-05-11 13:16:44 +10:00
Luke Howard
a88d00660e Fix PKCS#11 hcrypto backend regression (#314, #315, #316, #317)
81c778e broke the PKCS#11 hcrypto backend broke for many cases as it did
not support cipherstate resetting. (Prior to 81c778e, which was to fix #194,
the PKCS#11 backend did not support cipherstate chaining across invocations.)

hcrypto backends that maintain cipherstate independently of the hcrypto
context IV field need to set EVP_CIPH_ALWAYS_CALL_INIT to avoid the two
diverging. Their init function should support resetting the cipherstate
independently of key scheduling.
2018-05-11 13:11:31 +10:00
Daria Phoebe Brashear
d82817d279 hcrypto: implement missed symbol renaming in camellia-ntt and rand
camellia-ntt had none of its symbols renamed into the hc_ namespace,
and rand's missed timer_method (while all other methods were done). rename
these like we do for others
2018-04-09 14:50:17 -04:00
Jeffrey Altman
93518bfab4 use memset_s
lib roken includes support for memset_s() but it was not applied
to the Heimdal source tree.

Change-Id: I8362ec97a9be50205bb2d398e65b629b88ce1acd
2017-04-29 01:05:59 -04:00
Nicolas Williams
7dfad1ab0b Use secure_getenv() instead of issuid() 2017-04-17 18:02:30 -04:00
Nicolas Williams
352ff15477 Use labs(rand()) instead of abs(rand()) in tommath
Originally by Christos Zoulas.
2017-03-13 18:39:41 -04:00
Nicolas Williams
4c64231430 Misc last newline fixes
Originally by Christos Zoulas.
2017-03-13 18:39:41 -04:00