1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-20 02:42:09 +03:00
Commit Graph

80 Commits

Author SHA1 Message Date
Viktor Szakats
5e56002055 crypto: add LIBSSH2_NO_AES_CBC option
Also rename internal `LIBSSH2_AES` to `LIBSSH2_AES_CBC`.

Follow-up to 857e431648

Closes #990
2023-04-20 13:55:30 +00:00
Dan Fandrich
3c953c05d6 Add support for AES-GCM crypto protocols (#797)
Add support for aes256-gcm@openssh.com and aes128-gcm@openssh.com
ciphers, which are the OpenSSH implementations of AES-GCM cryptography.
It is similar to RFC5647 but has changes to the MAC protocol
negotiation.  These are implemented for recent versions of OpenSSL only.

The ciphers work differently than most previous ones in two big areas:
the cipher includes its own integrated MAC, and the packet length field
in the SSH frame is left unencrypted.  The code changes necessary are
gated by flags in the LIBSSH2_CRYPT_METHOD configuration structure.

These differences mean that both the first and last parts of a block
require special handling during encryption. The first part is where the
packet length field is, which must be kept out of the encryption path
but in the authenticated part (as AAD).  The last part is where the
Authentication Tag is found, which is calculated and appended during
encryption or removed and validated on decryption. As encryption/
decryption is performed on each packet in a loop, one block at a time,
flags indicating when the first and last blocks are being processed are
passed down to the encryption layers.

The strict block-by-block encryption that occurs with other protocols is
inappropriate for AES-GCM, since the packet length shifts the first
encrypted byte 4 bytes into the block. Additionally, the final part of
the block must contain the AES-GCM's Authentication Tag, so it must be
presented to the lower encryption layer whole. These requirements mean
added code to consolidate blocks as they are passed down.

When AES-GCM is negotiated as the cipher, its built-in MAC is
automatically used as the SSH MAC so further MAC negotiation is not
necessary.  The SSH negotiation is skipped when _libssh2_mac_override()
indicates that such a cipher is in use.  The virtual MAC configuration
block mac_method_hmac_aesgcm is then used as the MAC placeholder.

This work was sponsored by Anders Borum.

Integration-patches-by: Viktor Szakats

* fix checksrc errors
* fix openssl.c warning
* fix transport.c warnings
* switch to `LIBSSH2_MIN/MAX()` from `MIN()`/`MAX()`
* fix indent
* fix libgcrypt unused warning
* fix mbedtls unused warning
* fix wincng unused warning
* fix old openssl unused variable warnings
* delete blank lines
* updates to help merging with the ETM patch
2023-04-20 15:46:44 +02:00
Viktor Szakats
857e431648 crypto: add/fix algo guards and extend NO options
Add new guard `LIBSSH2_RSA_SHA1`. Add missing guards for `LIBSSH2_RSA`,
`LIBSSH2_DSA`.

Fix warnings when all options are disabled.

This is still not complete and it's possible to break a build with
certain crypto backends (e.g. mbedTLS) and/or combination of options.
It's not guaranteed that all bits everywhere get disabled by these
settings. Consider this a "best effort".

Add these new options to disable certain crypto elements:
- `LIBSSH2_NO_3DES`
- `LIBSSH2_NO_AES_CTR`
- `LIBSSH2_NO_BLOWFISH`
- `LIBSSH2_NO_CAST`
- `LIBSSH2_NO_ECDSA`
- `LIBSSH2_NO_RC4`
- `LIBSSH2_NO_RSA_SHA1`
- `LIBSSH2_NO_RSA`

The goal is to offer a way to disable legacy/obsolete/insecure ones.

See also: 146a25a06d `LIBSSH2_NO_HMAC_RIPEMD`
See also: 38015f4e46 `LIBSSH2_NO_DSA`
See also: be31457f30 `LIBSSH2_NO_MD5`

Closes #986
2023-04-20 09:44:56 +00:00
Viktor Szakats
d5438f4ba9 src: fix indentation of macro definitions
And some comment cleanup.

Closes #958
2023-04-13 23:39:01 +00:00
monnerat
6dc42e9d62 Make OS/400 implementation work again (#953)
* os400: support QADRT development files in a non-standard directory

This enables the possibility to compile libssh2 even if the ascii
runtime development files are not installed system-wide.

* userauth_kbd_packet: fix a pointer target type mismatch.

A temporary variable matching the parameter type is used before copying
to the real target and checking for overflow (that should not occur!).

* os400qc3: move and fix big number procedures

A bug added by a previous code style cleaning is fixed.
_libssh2_random() now checks and return the success status.

* os400qc3: fix cipher definition block lengths

They were wrongly set to the key size.

* Diffie-Hellman min/max modulus sizes are dependent of crypto-backend

In particular, os400qc3 limits the maximum group size to 2048-bits.
Move definitions of these parameters to crypto backend header files.

* kex: return an error if Diffie-Hellman key pair generation fails

* os400: add an ascii assert.h header file

* os400qc3: implement RSA SHA2 256/512
2023-04-13 14:08:12 +02:00
Viktor Szakats
73d95a055c build: be friendly with 3rd-party build tools
After recent build changes, 3rd party build that took the list of
C source to compile them as-is, stopped working as expected, due to
`blowfish.c` and crypto-backend C sources no longer expected to compile
separately but via `bcrypt_pbkdf.c` and `crypto.c`, respectively.

This patch ensures that compiling these files directly result in an
empty object instead of redundant code and duplicated symbols.

Also:
- add a compile-time error if none of the supported crypto backends
  are enabled.
- fix `libssh2_crypto_engine()` for wolfSSL and os400qc3.
  Rearrange code to avoid a hard-to-find copy of crypto-backend
  selection guards.

Follow-up to 4f0f4bff5a
Follow-up to ff3c774e03

Closes #951
2023-04-12 09:17:10 +00:00
Viktor Szakats
da0584534f wolfssl: add workaround for HMAC_Update() len arg difference (#897)
It's `int` in wolfSSL. `size_t` in OpenSSL/quictls/LibreSSL/BoringSSL.

Ref: ba47562d18/wolfssl/openssl/hmac.h (L60-L61)

/cc @wolfSSL
2023-03-28 23:46:58 +02:00
Viktor Szakats
5a96f494ee src: silence compiler warnings 3 (change types)
Apply type changes to avoid casts and warnings. In most cases this
means changing to a larger type, usually `size_t` or `ssize_t`.

Change signedness in a few places.

Also introduce new variables to avoid reusing them for multiple
purposes, to avoid casts and warnings.

- add FIXME for public `libssh2_sftp_readdir_ex()` return type.

- fix `_libssh2_mbedtls_rsa_sha2_verify()` to verify if `sig_len`
  is large enough.

- fix `_libssh2_dh_key_pair()` in `wincng.c` to return error if
  `group_order` input is negative.

  Maybe we should also reject zero?

- bump `_libssh2_random()` size type `int` -> `size_t`. Add checks
  for WinCNG and OpenSSL to return error if requested more than they
  support (`ULONG_MAX`, `INT_MAX` respectively).

- change `_libssh2_ntohu32()` return value `unsigned int` -> `uint32_t`.

- fix `_libssh2_mbedtls_bignum_random()` to check for a negative `top`
  input.

- size down `_libssh2_wincng_key_sha_verify()` `hashlen` to match
  Windows'.

- fix `session_disconnect()` to limit length of `lang_len`
  (to 256 bytes).

- fix bad syntax in an `assert()`.

- add a few `const` to casts.

- `while(1)` -> `for(;;)`.

- add casts that didn't fit into #876.

- update `docs/HACKING-CRYPTO` with new sizes.

May need review for OS400QC3: /cc @monnerat @jonrumsey

See warning details in the PR's individual commits.

Cherry-picked from #846
Closes #879
2023-03-26 22:42:04 +00:00
Viktor Szakats
02f2700a61 src: silence compiler warnings 1
Most of the changes aim to silence warnings by adding casts.

An assortment of other issues, mainly compiler warnings, resolved:

- unreachable code fixed by using `goto` in
  `publickey_response_success()` in `publickey.c`.

- potentially uninitialized variable in `sftp_open()`.

- MSVS-specific bogus warnings with `nid_type` in `kex.c`.

- check result of `kex_session_ecdh_curve_type()`.

- add missing function declarations.

- type changes to fit values without casts:
  - `cmd_len` in `scp_recv()` and `scp_send()`: `int` -> `size_t`
  - `Blowfish_expandstate()`, `Blowfish_expand0state()` loop counters:
    `uint16_t` -> `int`
  - `RECV_SEND_ALL()`: `int` -> `ssize_t`
  - `shell_quotearg()` -> `unsigned` -> `size_t`
  - `sig_len` in `_libssh2_mbedtls_rsa_sha2_sign()`:
    `unsigned` -> `size_t`
  - `prefs_len` in `libssh2_session_method_pref()`: `int` -> `size_t`
  - `firstsec` in `_libssh2_debug_low()`: `int` -> `long`
  - `method_len` in `libssh2_session_method_pref()`: `int` -> `size_t`

- simplify `_libssh2_ntohu64()`.

- fix `LIBSSH2_INT64_T_FORMAT` for MinGW.

- fix gcc warning by not using a bit field for
  `burn_optimistic_kexinit`.

- fix unused variable warning in `_libssh2_cipher_crypt()` in
  `libgcrypt.c`.

- fix unused variables with `HAVE_DISABLED_NONBLOCKING`.

- avoid const stripping with `BIO_new_mem_buf()` and OpenSSL 1.0.2 and
  newer.

- add a missing const in `wincng.h`.

- FIXME added for public:
  - `libssh2_channel_window_read_ex()` `read_avail` argument type.
  - `libssh2_base64_decode()` `datalen` argument type.

- fix possible overflow in `sftp_read()`.

  Ref: 4552c73cd5

- formatting in `wincng.h`.

See warning details in the PR's individual commits.

Cherry-picked from #846
Closes #876
2023-03-26 09:34:26 +00:00
Viktor Szakats
ec0a51db1f openssl: require EVP_aes_128_ctr() support
libssh2 built with OpenSSL and without its `EVP_aes_128_ctr()`, aka
`HAVE_EVP_AES_128_CTR`, option are working incorrectly. This option
wasn't always auto-detected by autotools up until recently (#811).
Non-cmake, non-autotools build methods never enabled it automatically.

OpenSSL supports this options since at least v1.0.2, which is already
EOLed and considered obsolete. OpenSSL forks (LibreSSL, BoringSSL)
supported it all along.

In this patch we enable this option unconditionally, now requiring
OpenSSL supporting this function, or one of its forks.

Also modernize OpenSSL lib references to what 1.0.2 and newer versions
have been using.

Fixes #739
2023-03-20 09:30:40 +00:00
Viktor Szakats
509c84e3c5 openssl: fix possible compiler warning in macro condition (#839)
Building with wolfSSL or pre-OpenSSL v1.1.1 triggered it.

```
../src/openssl.h:130:5: warning: 'LIBRESSL_VERSION_NUMBER' is not defined, evaluates to 0 [-Wundef]
    LIBRESSL_VERSION_NUMBER >= 0x3070000fL
    ^
```

Regression from 2e2812dde8
2023-03-11 11:08:42 +01:00
Will Cosgrove
45d33da3c7 Disable deprecated warnings for OpenSSL 3 #805 (#806)
Disable deprecated warnings (for now) when building against OpenSSL 3 for a clean build.

Reported:
Daniel Stenberg
2023-02-27 11:46:47 -08:00
Viktor Szakats
2e2812dde8 openssl.h: enable ed25519 for LibreSSL 3.7.0 (#778)
This brings LibreSSL libssh2 builds on par with OpenSSL.
2022-12-13 22:11:13 +01:00
Viktor Szakats
b952674f12 Openssl: add support for LibreSSL 3.5.x (#700)
LibreSSL 3.5.0 made more structures opaque, so let's enable existing
support for that when building against these LibreSSL versions.

Ref: https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.5.0-relnotes.txt

Credit:
Viktor Szakats
2022-05-19 09:35:16 -07:00
Harry Sintonen
b95e758239 Fix build since openssl 1.1.0 when ECDSA and/or RIPEMD are disabled (#666)
File: openssl.h

Notes:
In openssl 1.1.0 and later openssl decided to change some of the defines used to check if certain features are not compiled in the libraries. This updates the define checks.

Credit:
Harry Sintonen
Co-authored-by: Harry Sintonen <sintonen@iki.fi>
2022-04-04 17:00:04 -07:00
Hayden Roche
17c9c1fcdf Add support for a wolfSSL crypto backend. (#629)
It uses wolfSSL's OpenSSL compatibility layer, so rather than introduce new
wolfssl.h/c files, the new backend just reuses openssl.h/c. Additionally,
replace EVP_Cipher() calls with EVP_CipherUpdate(), since EVP_Cipher() is not
recommended.

Credit: Hayden Roche
2022-01-06 10:25:34 -08:00
Will Cosgrove
64a555d6f5 RSA SHA2 256/512 key upgrade support RFC 8332 #536 (#626)
Notes:
* Host Key RSA 256/512 support #536
* Client side key hash upgrading for RFC 8332
* Support for server-sig-algs, ext-info-c server messages
* Customizing preferred server-sig-algs via the preference LIBSSH2_METHOD_SIGN_ALGO

Credit: Anders Borum, Will Cosgrove
2022-01-06 09:50:58 -08:00
Paul Capron
b3a8a6d27c Fix _libssh2_random() silently discarding errors (#520)
Notes:
* Make _libssh2_random return code consistent

Previously, _libssh2_random was advertized in HACKING.CRYPTO as
returning `void` (and was implemented that way in os400qc3.c), but that
was in other crypto backends a lie; _libssh2_random is (a macro
expanding) to an int-value expression or function.

Moreover, that returned code was:
  — 0 or success, -1 on error for the MbedTLS & WinCNG crypto backends
But also:
  — 1 on success, -1 or 0 on error for the OpenSSL backend!
  – 1 on success, error cannot happen for libgcrypt!

This commit makes explicit that _libssh2_random can fail (because most of
the underlying crypto functions can indeed fail!), and it makes its result
code consistent: 0 on success, -1 on error.

This is related to issue #519 https://github.com/libssh2/libssh2/issues/519
It fixes the first half of it.

* Don't silent errors of _libssh2_random

Make sure to check the returned code of _libssh2_random(), and
propagates any failure.

A new LIBSSH_ERROR_RANDGEN constant is added to libssh2.h
None of the existing error constants seemed fit.

This commit is related to d74285b684
and to https://github.com/libssh2/libssh2/issues/519 (see the issue
for more info.)  It closes #519.

Credit:
Paul Capron
2021-05-11 14:06:18 -07:00
David Benjamin
1a61d0c3ca openssl.c: clean up curve25519 code (#499)
File: openssl.c, openssl.h, crypto.h, kex.c

Notes:
This cleans up a few things in the curve25519 implementation:

- There is no need to create X509_PUBKEYs or PKCS8_PRIV_KEY_INFOs to
  extract key material. EVP_PKEY_get_raw_private_key and
  EVP_PKEY_get_raw_public_key work fine.

- libssh2_x25519_ctx was never used (and occasionally mis-typedefed to
  libssh2_ed25519_ctx). Remove it. The _libssh2_curve25519_new and
  _libssh2_curve25519_gen_k interfaces use the bytes. Note, if it needs
  to be added back, there is no need to roundtrip through
  EVP_PKEY_new_raw_private_key. EVP_PKEY_keygen already generated an
  EVP_PKEY.

- Add some missing error checks.

Credit:
David Benjamin
2020-07-10 10:47:48 -07:00
Marc Hoersken
ffab6960b5 src: add new and align include guards in header files (#480)
Make sure all include guards exist and follow the same format.
2020-05-31 23:08:15 +02:00
Zenju
24fd419bde ssh-ed25519: Support PKIX + calc pubkey from private (#416)
Files: openssl.c/h
Author: Zenju
Notes:
Adds support for PKIX key reading by fixing:

_libssh2_pub_priv_keyfile() is missing the code to extract the ed25519 public key from a given private key

_libssh2_ed25519_new_private_frommemory is only parsing the openssh key format but does not understand PKIX (as retrieved via PEM_read_bio_PrivateKey)
2019-12-13 13:35:00 -08:00
axjowa
ff2bce3057 openssl.h : Use of ifdef where if should be used (#389)
File : openssl.h

Notes : 
LIBSSH2_ECDSA and LIBSSH2_ED25519 are always defined so the #ifdef
checks would never be false.

This change makes it possible to build libssh2 against OpenSSL built
without EC support.

Change-Id: I0a2f07c2d80178314dcb7d505d1295d19cf15afd

Credit : axjowa
2019-07-12 09:55:09 -07:00
Daniel Stenberg
12bddb0d45 code style: unify code style
Indent-level: 4
Max columns: 79
No spaces after if/for/while
Unified brace positions
Unified white spaces
2019-03-20 14:21:38 +01:00
Daniel Stenberg
bd5a620d1a lib: fix various compiler warnings 2019-03-17 14:33:24 +01:00
Will Cosgrove
097448107a Replaced malloc with calloc #295 2019-02-21 09:55:42 -08:00
Will Cosgrove
53aba03fef Fix memory dealloc impedance mis-match #292 (#293)
When using ed25519 host keys and a custom memory allocator.
2019-02-20 12:00:44 -08:00
Will Cosgrove
dd1b8be51a Added conditional around engine.h include 2018-08-07 08:46:47 -07:00
Will Cosgrove
0309229259 ED25519 Key Support #39 (#248)
OpenSSH Key and ED25519 support #39
Added _libssh2_explicit_zero() to explicitly zero sensitive data in memory #120

* ED25519 Key file support - Requires OpenSSL 1.1.1 or later
* OpenSSH Key format reading support - Supports RSA/DSA/ECDSA/ED25519 types
* New string buffer reading functions - These add build-in bounds checking and convenance methods. Used for OpenSSL PEM file reading.
* Added new tests for OpenSSH formatted Keys
2018-08-02 14:00:25 -07:00
Tseng Jun
d04f9b2bd3 Fix the EVP cipher meth memory leakage problem (#244)
* Fix the EVP cipher meth memory leakage problem

Looks good, thanks for the fixes.
2018-04-18 10:08:09 -07:00
Etienne Samson
54bef4c5da A collection of small fixes (#198)
* tests: Remove if-pyramids

* tests: Switch run_command arguments

* tests: Make run_command a vararg function

* tests: Xcode doesn't obey CMake's test working directory

* openssl: move manual AES-CTR cipher into crypto init

* cmake: Move our include dir before all other include paths
2018-03-20 16:58:13 -07:00
Will Cosgrove
aba34f5f56 Add support for ECDSA keys and host keys (#41)
This commit lands full ECDSA key support when using the OpenSSL
backend. Which includes:

New KEX methods:
ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521

Can now read OpenSSL formatted ECDSA key files.

Now supports known host keys of type ecdsa-sha2-nistp256.

New curve types:
NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1

Default host key preferred ordering is now nistp256, nistp384,
nistp521, rsa, dss.

Ref: https://github.com/libssh2/libssh2/issues/41

Closes https://github.com/libssh2/libssh2/pull/206
2018-03-09 19:28:38 +00:00
Will Cosgrove
6762664e7e Fix for #188 (#189)
* Update openssl.c

* Create openssl.h
2017-06-09 14:59:18 -07:00
Marcel Raad
c423b543ca openssl: fix build with OpenSSL 1.1 API (#176)
When building with OPENSSL_API_COMPAT=0x10100000L, OpenSSL_add_all_algorithms
and OpenSSL_add_all_ciphers don't exist. The corresponding functionality is
handled automatically with OpenSSL 1.1.
2017-05-24 10:21:22 -07:00
Will Cosgrove
97518ca8bd Fix memory leak of crypt_ctx->h using openSSL 1.1+ (#177)
Need to use EVP_CIPHER_CTX_free instead of EVP_CIPHER_CTX_reset.
2017-05-12 16:34:26 -07:00
monnerat
f7daf3185a Implement Diffie-Hellman computations in crypto backends. (#149)
Not all backends feature the low level API needed to compute a Diffie-Hellman
secret, but some of them directly implement Diffie-Hellman support with opaque
private data. The later approach is now generalized and backends are
responsible for all Diffie Hellman computations.
As a side effect, procedures/macros _libssh2_bn_rand and _libssh2_bn_mod_exp
are no longer needed outside the backends.
2016-11-27 18:39:00 +00:00
monnerat
c8c1b4a050 Make libssh2 work again on os400. (#118)
* os400: minimum supported OS version is now V6R1.
Do not log compiler informational messages.

* Implement crypto backend specific Diffie-Hellman computation.

This feature is now needed on os400 because the QC3 library does not
implement bn_mod_exp() natively. Up to now, this function was emulated using
an RSA encryption, but commits ca5222ea81 and
7934c9ce2a (CVE-2016-0787) broke the emulation
because QC3 only supports RSA exponents up to 512 bits.

Happily, QC3 supports a native API for Diffie-Hellman computation, with
opaque random value: this commit implements the use of this API and, as a
side effect, enables support of this feature for any other crypto backend that
would use it.

A "generic" Diffie-Hellman computation internal API supports crypto backends
not implementing their own: this generic API uses the same functions as before.

* Fix typos in docs/HACKING.CRYPTO.
2016-11-12 18:15:49 +00:00
Viktor Szakats
0ffb3bfafe openssl: fix LibreSSL support after OpenSSL 1.1.0-pre1/2 support 2016-02-16 00:08:08 +01:00
Patrick Monnerat
f915a31a4d Feature an optional crypto-specific macro to rsa sign a data fragment vector
OS/400 crypto library is unable to sign a precomputed SHA1 hash: however
it does support a procedure that hashes data fragments and rsa signs.
If defined, the new macro _libssh2_rsa_sha1_signv() implements this function
and disables use of _libssh2_rsa_sha1_sign().

The function described above requires that the struct iovec unused slacks are
cleared: for this reason, macro libssh2_prepare_iovec() has been introduced.
It should be defined as empty for crypto backends that are not sensitive
to struct iovec unused slack values.
2016-01-18 13:35:28 +01:00
Viktor Szakats
ed2c3c8d28 add OpenSSL-1.1.0-pre2 compatibility
Closes #70
2016-01-17 17:10:45 +01:00
Viktor Szakats
73930e6577 add OpenSSL 1.1.0-pre1 compatibility
* close https://github.com/libssh2/libssh2/issues/69
* sync a declaration with the rest of similar ones
* handle EVP_MD_CTX_new() returning NULL with OpenSSL 1.1.0
* fix potential memory leak with OpenSSL 1.1.0 in
  _libssh2_*_init() functions, when EVP_MD_CTX_new() succeeds,
  but EVP_DigestInit() fails.
2016-01-17 17:10:32 +01:00
Will Cosgrove
d441da3086 added engine.h include to fix warning 2015-10-05 10:52:52 +02:00
Will Cosgrove
fc4a969a05 kex: Added diffie-hellman-group-exchange-sha256 support
... and fixed HMAC_Init depricated usage

Closes #48
2015-09-29 09:43:30 +02:00
brian m. carlson
a53cebba34 Add support for HMAC-SHA-256 and HMAC-SHA-512.
Implement support for these algorithms and wire them up to the libgcrypt
and OpenSSL backends.  Increase the maximum MAC buffer size to 64 bytes
to prevent buffer overflows.  Prefer HMAC-SHA-256 over HMAC-SHA-512, and
that over HMAC-SHA-1, as OpenSSH does.

Closes #40
2015-09-16 09:32:19 +02:00
Mizunashi Mana
f4b5947d6d openssl.h: adjust the rsa/dsa includes
... to work when built without DSA support.

Closes #36
2015-08-07 00:34:36 +02:00
Daniel Stenberg
e9536edede openssl: make libssh2_sha1 return error code
- use the internal prefix _libssh2_ for non-exported functions

- removed libssh2_md5() since it wasn't used

Reported-by: Kamil Dudka
2015-06-12 10:53:18 +02:00
Hannes Domani
09c5e59933 kex: fix libgcrypt memory leaks of bignum
Fixes #168.
2015-04-03 17:39:15 +01:00
LarsNordin-LNdata
983ceafe58 Use correct no-blowfish #define with OpenSSL.
The OpenSSL define is OPENSSL_NO_BF, not OPENSSL_NO_BLOWFISH.
2015-04-01 23:03:28 +01:00
Marc Hoersken
7ca44fbd94 kex: do not ignore failure of libssh2_sha1_init()
Based upon 43b730ce56.
Fixes ticket 290. Thanks for the suggestion, mstrsn.
2015-03-23 22:25:50 +01:00
Will Cosgrove
14d9ee01bc Must init HMAC_CTX before using it.
Must init ctx before using it or openssl will reuse the hmac which is not thread safe and causes a crash.
Added libssh2_hmac_ctx_init macro.
2015-03-15 00:16:46 +00:00
Mark McPherson
61df22c460 openssl: initialise the digest context before calling EVP_DigestInit()
When using the OpenSSL libraries in FIPS mode, the function call
EVP_DigestInit() is actually #defined to FIPS_digestinit().
Unfortunately wheres EVP_DigestInit() initialises the context and then
calls EVP_DigestInit_ex(), this function assumes that the context has
been pre-initialised and crashes when it isn't.

Bug: https://trac.libssh2.org/ticket/279

Fixes #279
2013-11-21 11:35:12 +01:00