Commit Graph

631 Commits

Author SHA1 Message Date
Minsoo Choo
aff90c322e Fix spelling 2024-06-16 23:30:48 -04:00
Joseph Sutton
e9bc20f5da hcrypto: Fix errors produced by compiling with FORTIFY_SOURCE=2
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
c3e3d02b01 hcrypto: Don’t cast away const
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-02 20:19:54 -05:00
Taylor R Campbell
a142767598 Fix ctype.h misuse.
Excluded: libtomath and libedit files, most of which appear to be
testing or example code not involved in production, and which are
derived from an upstream that should perhaps have patches submitted
upstream instead.

fix https://github.com/heimdal/heimdal/issues/1111
2023-05-26 14:10:11 -05:00
Nicolas Williams
48382936e5 hcrypto: Fix performance regression 2023-01-27 11:00:23 -06:00
Nicolas Williams
1d06e8fcb9 hcrypto: Quell div-by-zero in mp_root_u32() 2023-01-04 02:02:44 -06:00
Nicolas Williams
86af011f0b hcrypto: Fix integer undeflow in rsa-ltm.c 2023-01-04 00:43:35 -06:00
Nicolas Williams
274b683d76 hcrypto: Fix warning in HMAC_Init_ex() 2023-01-04 00:43:35 -06:00
Brian May
f4fd02b810 Increment hcrypto library version 2022-12-29 21:43:02 -06:00
Nicolas Williams
2ddea96ba2 hcrypto: Use builtin 1DES/RC2/RC4 (OpenSSL 3)
At some point before we make an 8.0 release we'll probably just remove
all the legacy, weak ciphers and hashes (except MD5, most likely).

To drop these we'll have to re-generate PKCS#12 test samples using
stronger PBEs, and possible add new PBE types.
2022-11-22 11:34:54 -05:00
Nicolas Williams
11846fcabb hcrypto: Fix EVP_CipherUpdate() bugs 2022-11-22 11:34:54 -05:00
Nicolas Williams
47e6c68de8 hcrypto: OpenSSL's EVP_Cipher() returns a length 2022-11-22 11:34:54 -05:00
Nicolas Williams
aa3355e3bf hcrypto: Remove dead MD2 code 2022-11-17 19:20:08 -06:00
Nicolas Williams
3a5e91eca2 hcrypto: Remove MD2 with prejudice
We don't use it anywhere for anything.
2022-11-01 16:10:57 -05:00
Nicolas Williams
5b1c69b424 hcrypto: Fix UB 2022-11-01 16:10:57 -05:00
Joseph Sutton
b19633f9b9 Use constant-time memcmp when comparing sensitive buffers
This helps to avoid timing attacks.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-04-30 13:35:52 -04:00
Joseph Sutton
20f038f4f0 hcrypto: Use memset_s() when clearing sensitive buffers
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-04-30 13:35:52 -04:00
Joseph Sutton
88ea8039e3 hcrypto: Fix typo when clearing context structure
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-04-30 13:35:52 -04:00
Jeffrey Altman
31d5c38976 lib/hcrypto: mpz2BN return NULL if mp_ubin_size(s) returns zero
If mp_ubin_size(s) returns zero then mp_to_ubin() will fail and
not return MP_OKAY.  If MP_OKAY is not returned, NULL is returned
to the caller of mpz2BN().

This change avoids the unnecessary memory allocation and function
calls.  It also removes a dereference after null warning from
coverity.

Change-Id: I52ff2c166964e41cb4eef1dac637904bf2bf13bf
2022-01-24 10:14:17 -05:00
Jeffrey Altman
04527412e3 Follow the Linux kernel's lead on "fallthrough"
The pseudo keyword 'fallthrough' is defined such that case statement
blocks must end with any of these keywords:
 * break;
 * fallthrough;
 * continue;
 * goto <label>;
 * return [expression];
 *
 *  gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes

The macro is defined either as

  __attribute__((__fallthrough__))

or as

  do {} while (0)  /* fallthrough */

not including the semicolon.

This change implements the Linux kernel style and updates several locations
where "/*fallthrough*/ and /* FALLTHROUGH */ were not previously replaced.

Externally imported code such as libedit, libtommath and sqlite are
restored to their unaltered state.

Change-Id: I69db8167b0d5884f55d96d72de3059a0235a1ba3
2022-01-21 10:39:47 -05:00
Jeffrey Altman
2e54dc7aae lib/hcrypto: DES_cfb64_encrypt init buffer in decrypt path 2022-01-20 21:29:11 -05:00
Joseph Sutton
1c93a6ff26 heimdal: Avoid overflow when performing bitwise shift operations
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-01-18 00:31:45 -05:00
Jeffrey Altman
0e3acff241 lib/hcrypto: mpz2BN unsafe to call mp_to_ubin with NULL
remove the (size != 0) exception to malloc() failure.

Change-Id: I7a678b0fadd51c673491b61c06afd4203c871318
2022-01-17 21:41:21 -05:00
Jeffrey Altman
1ebebe1d2f lib/hcrypto: RSA_check_key if rsa->n is NULL cannot call RSA_size
Avoid a theoretical NULL pointer dereference.

Change-Id: Ia7b8671152b5444fd5cfdb3e37fd62e4db68c9c5
2022-01-17 21:36:49 -05:00
Jeffrey Altman
ee3cd2e4a9 lib/hcrypto: RSA_new_method pass correct ptr to ENGINE_finish
Pass rsa->engine not engine.

Change-Id: I1251c50898b267d14cbf0bb2adb40516d24fa369
2022-01-17 21:28:37 -05:00
Jeffrey Altman
94a7e97e09 lib/hcrypto: DH_new_method pass correct ptr to ENGINE_finish
Pass dh->engine not engine.

Change-Id: Id7294a5ac3715d557202349bf20755d873ced7ae
2022-01-17 21:27:00 -05:00
Jeffrey Altman
5c7a4436e3 lib/hcrypto: dh-ltm update use of libtommath
warning: 'mp_read_unsigned_bin' is deprecated
(declared at ./libtommath/tommath.h:732): replaced by mp_from_ubin
[-Wdeprecated-declarations]

warning: 'mp_unsigned_bin_size' is deprecated
(declared at ./libtommath/tommath.h:731): replaced by mp_ubin_size
[-Wdeprecated-declarations]

warning: 'mp_to_unsigned_bin' is deprecated
(declared at ./libtommath/tommath.h:733): replaced by mp_to_ubin
[-Wdeprecated-declarations]

warning: 'mp_unsigned_bin_size' is deprecated
(declared at ./libtommath/tommath.h:731): replaced by mp_ubin_size
[-Wdeprecated-declarations]

warning: ignoring return value of 'mp_init_multi',
declared with attribute warn_unused_result [-Wunused-result]

warning: ignoring return value of 'mp_to_unsigned_bin',
declared with attribute warn_unused_result [-Wunused-result]

warning: ignoring return value of 'mp_read_unsigned_bin',
declared with attribute warn_unused_result [-Wunused-result]

Change-Id: I510fd7a57c9cd52b59086a85d13aa6204ebb9fd9
2022-01-17 21:11:54 -05:00
Nicolas Williams
bb791ee52c hcrypto: dlclose(dso) at ENGINE finish time 2022-01-16 14:08:22 -06:00
Jeffrey Altman
3707c52ea7 lib/hcrypto: ENGINE_by_dso do not leak handle
Must dlclose(handle) before returning even if 'engine' is
returned to caller.

Change-Id: I169044a768934e9b7774a323fe6c855fd07a09e4
2022-01-16 00:05:07 -05:00
Jeffrey Altman
19eae8b4a9 lib/hcrypto: BN_set_word return false if input 'bn' is NULL
If the input 'bn' is NULL then BN_bin2bn() will allocate and
return a BIGNUM which will then be leaked.   BN_set_word()
would then return true even though it didn't set the word
into a BIGNUM known to the caller.

Change-Id: I6681f548e6bfb330cec009ae7c18e6151016179e
2022-01-15 23:17:26 -05:00
Luke Howard
4891d713fb bn_s_mp_rand_platform.c: s_read_urandom: correctly handle split read
s_read_urandom has a while loop to handle read() that returns less
than the full buffer (either due to EINTR or because more than the
atomic guarantee from urandom was requested). However, the target
of the read was always the base pointer p instead of the updated
pointer q, so in the end less than the requested randomness is returned.

Use q instead of p in the read() call.

Upstream pull request:
https://github.com/libtom/libtommath/pull/512

Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
2022-01-15 13:38:18 +11:00
Luke Howard
046675ce0e Revert "tommath: Fix warning in s_read_getrandom()"
This reverts commit 489da75e65.

Will be replaced with upstream commit.
2022-01-15 13:37:33 +11:00
Nicolas Williams
f076ed57cc Fix make dist 2022-01-14 20:10:19 -06:00
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