Bug 2112

Summary: Android doesn't provide an implementation of crypt().
Product: Portable OpenSSH Reporter: Nathan Osman <nathan.osman>
Component: Build systemAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED FIXED    
Severity: minor CC: dtucker
Priority: P5    
Version: 6.2p1   
Hardware: Other   
OS: Linux   
Bug Depends on:    
Bug Blocks: 2076    
Attachments:
Description Flags
Use OpenSSL DES_crypt function as a drop-in replacement for crypt().
none
Use OpenSSL DES_crypt function as a drop-in replacement for crypt(). none

Description Nathan Osman 2013-06-02 05:28:50 AEST
Created attachment 2284 [details]
Use OpenSSL DES_crypt function as a drop-in replacement for crypt().

The Android platform does not provide a crypt() function (crypt.h does not exist) and therefore the following error is produced when attempting to link xcrypt.o from the openbsd-compat library:

  libopenbsd-compat.a(xcrypt.o): in function xcrypt:xcrypt.c:78: error: undefined reference to 'crypt'

However, OpenSSL includes an implementation of crypt in the libcrypto library. I have attached a small patch that:

 - checks if crypt.h is available
 - if not, checks if openssl is available
 - uses a #define to point crypt to DES_crypt
Comment 1 Nathan Osman 2013-06-02 05:31:10 AEST
Actually I made a mistake in describing my patch - the first two steps are reversed. First a check for OpenSSL is made and then DES_crypt is used only if crypt is missing.

I wasn't sure which order to do things in. I can reverse the '#if defined' lines if needed.
Comment 2 Darren Tucker 2013-06-02 05:53:21 AEST
Comment on attachment 2284 [details]
Use OpenSSL DES_crypt function as a drop-in replacement for crypt().

>+# if defined(HAVE_OPENSSL)

openssl is mandatory so there's no point checking for this (I'm not sure why configure even sets it).

>+#  if !defined(HAVE_CRYPT_H)

you don't really care whether or not crypt.h exists, what you really care about is whether or not you have a crypt function, so that's what you should be checking for.

I'll attach a modified patch shortly.
Comment 3 Darren Tucker 2013-06-02 06:07:14 AEST
Created attachment 2288 [details]
Use OpenSSL DES_crypt function as a drop-in replacement for crypt().

Please try this.  note that you'll need to run "autoreconf" to rebuild configure before running ./configure.
Comment 4 Nathan Osman 2013-06-02 06:24:12 AEST
I applied the patch on a clean copy of the OpenSSH source code and can confirm that it solves the problem.

Thanks!
Comment 5 Darren Tucker 2013-06-02 06:28:23 AEST
Patch applied, thanks.
Comment 6 Damien Miller 2015-08-11 23:05:35 AEST
Set all RESOLVED bugs to CLOSED with release of OpenSSH 7.1