Commit Graph

576 Commits

Author SHA1 Message Date
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
Thorsten Glaser
005c8886d7 Do not detect x32 as 64-bit platform.
Fixes test failures due to ISO C Undefined Behaviour in MP_MASK macro.
2017-01-09 19:57:40 +00:00
Antoine Jacoutot
586e5f6d9d Fix build with LibreSSL. 2016-12-17 23:04:41 -05:00
Nicolas Williams
995c8279b1 One more missing file 2016-12-15 12:21:17 -06:00
Nicolas Williams
3e65dfbc32 Fix make dist missing files (#228) 2016-12-15 12:15:56 -06:00
Nicolas Williams
2ebec2e4ec Fix some Doxygen warnings 2016-12-14 22:05:46 -06:00
Nicolas Williams
1c81ddf4e2 Round #2 of scan-build warnings cleanup 2016-11-16 17:03:14 -06:00
Viktor Dukhovni
e4ba666221 hcrypto compiler warnings 2016-11-14 02:22:32 -05:00
Nicolas Williams
2d3c21cb61 There is no lib/hcrypto/dllmain.c 2016-11-11 15:58:33 -06:00
Nicolas Williams
81c778e0a3 Fix EVP PKCS#11 backend (#194) 2016-11-11 14:34:11 -06:00
Nicolas Williams
9c8b450aa0 Add EVP backend selection to example_evp_cipher.c 2016-11-11 14:30:13 -06:00
Nicolas Williams
e803b00bca Assume OpenCryptoki on Linux for evp-pkcs11 2016-11-11 14:30:13 -06:00
Viktor Dukhovni
a2ce04e87b We're not in Texas anymore 2016-11-10 22:29:49 -05:00
Simon Wilkinson
67ac841f8f hcrypto: Fix Win 32 cpp checks
The correct test for a windows build is if defined(_WIN32), not just
if _WIN32. Fix a few places in the build which do the wrong thing, as
it gives compiler warnings.
2016-11-09 15:36:04 +00:00
Simon Wilkinson
ac9109ff75 hcrypto: Remove roken.h include from hash.h
All of the hcrypto source files were updated with commit
0f97855826 to include roken.h. This
means that hash.h no longer needs to include the roken header.

Remove the multiple inclusion.
2016-11-09 14:22:38 +00:00
Luke Howard
7b720cf61c krb5: implement draft-ietf-kitten-aes-cts-hmac-sha2-07 2016-10-08 08:17:11 +02:00
Sean Davis
316387f619 Fix typo in rand-fortuna.c
`__GNUC__` was written as `__GUNC__`, which could have interesting results as it'll never be defined.
2016-09-19 16:06:03 -05:00
Benjamin Kaduk
aa87e08cc7 Use C99 designated initializers in a couple places
Some portions of libhcrypto are reused by other projects in
diverse environments, including within operating system kernel modules.
In some such build environments, hardening measures such as grsecurity
can (randomly) reorder structure elements, so as to make it harder
for an attacker to determine the offset from a known field's address
to a different field that is needed for an attack.

However, doing so requires the use of C99 designated initializers
to make the source code compatible with such structure rearrangement,
as opposed to the "traditional" C aggregate type initializers, which
just list fields in order.  This feature is also available as a
GCC extension since early versions of GCC.  However, it is not
provided by many common versions of visual studio (and presumably
also not by the vendor compiler for various commercial Unixes),
so the traditional initializers must remain, behind a conditional.
__GNUC__ or __STDC_VERSION__ >= 199901 should be enough to get
most cases with support for designated initializers, at least
for now.

Signed-off-by: Nicolas Williams <nico@twosigma.com>
2016-09-01 17:38:47 -05:00
David Mulder
2bee5966ab The evp-w32.h header should not be included on all platforms 2016-08-02 16:12:46 -06:00
Viktor Dukhovni
529a91d69a MacOS/X fixes 2016-06-09 01:13:14 -04:00
Roland C. Dowdeswell
b49431e47a lib/hcrypto/Makefile.am: set automake option: subdir-objects 2016-05-12 15:18:38 -04:00
Viktor Dukhovni
1017a594ef Use OpenSSL include path as needed
For consistency make "-I" part of the macro value set by autoconf.

For now, don't attempt to handle OpenSSL rpath in cf/crypto.m4.
That's much easier by just setting LDFLAGS when running configure.
Otherwise too many Makefiles to edit and libtool and automake do
their best to undo the rpath.
2016-05-07 05:29:12 -04:00
Viktor Dukhovni
9393d53538 Actually capture libcrypto autoconf results
Also infer lib path not just include path, and set rpath if not from /usr.
Also need libcrypto for test_rand.
2016-05-07 02:36:34 -04:00