Commit Graph

563 Commits

Author SHA1 Message Date
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
Jeffrey Altman
6c1ba82623 hcrypto: no openssl build requires evp-hcrypto.h include
When building evp-openssl.c without support for OpenSSL it is necessary
to include evp-hcrypto.h to define the HCRYPTO_FALLBACK functions.

Change-Id: Ifd51f9fcd2b1805a534a9f88992162818afffe7d
2016-04-23 19:03:56 -04:00
Nicolas Williams
ca0dff891b Check HCRYPTO_FALLBACK in W32 backend 2016-04-19 13:40:47 -05:00
Nicolas Williams
c6c858c0ca Check HCRYPTO_FALLBACK in PKCS#11 backend 2016-04-19 13:40:47 -05:00
Nicolas Williams
7f96a2cc1a Check HCRYPTO_FALLBACK in CC backend 2016-04-19 13:40:47 -05:00
Nicolas Williams
8a749ced78 Check HCRYPTO_FALLBACK in ossl backend 2016-04-19 13:40:47 -05:00
Nicolas Williams
e751e09108 Fix warnings in test_bulk.c 2016-04-19 13:40:46 -05:00
Nicolas Williams
7df276258a Fix mis-merge in evp-openssl.c 2016-04-19 13:40:46 -05:00
Nicolas Williams
e02832b199 Fix initialization race in evp-openssl.c 2016-04-19 13:24:36 -05:00
Jeffrey Altman
4ad2f5830a hcrypto: p11_module_init_once make handle static global
Coverity complains about the leakage of 'handle' when the identifier
goes out of scope.  Change handle into a static global to hold the
value instead of a stack variable.

Change-Id: I040707ac731558f7d523f128a006a80b98d45b79
2016-04-17 15:11:55 -05:00
Nicolas Williams
514f719e4a evp-openssl: fallback to hcrypto
The Windows and PKCS#11 backends do this.  The Common Crypto (OS X)
backend does not.  Ideally this should be a ./configure option, and that
might be the next step, but right now we need this fallback in order to
get tests passing in Travis-CI.
2016-04-16 18:05:26 -05:00
Nicolas Williams
3d4fbf9aac Fix lib/hcrypto for Windows 2016-04-16 16:58:08 -05:00
Nicolas Williams
b2a78463de Add missing <hcrypto/undef.h> 2016-04-16 13:59:34 -05:00
Nicolas Williams
f064f2d14b Add seed operation for unix RAND method 2016-04-15 00:16:18 -05:00