简体   繁体   English

如何在Mac OS X中获得与Linux gcc / gnu crypt(3)相同的crypt(3)功能? Linux gcc crypt(3)有MD5和SHA512。 Apple Gcc crypt(3)*仅*使用DES

[英]How to get same crypt(3) function in Mac OS X as Linux gcc/gnu crypt(3)? Linux gcc crypt(3) has MD5 and SHA512. Apple Gcc crypt(3) *only* uses DES

I am migrating some c code from Linux to Mac OSX (yosemite). 我正在将一些c代码从Linux迁移到Mac OSX(优胜美地)。 The Mac OSX crypt() function (which is in unistd.h, as I have determined), is not the same as on gcc/gnu in Linux. Mac OSX crypt()函数(在我已经确定的unistd.h中)与Linux中的gcc / gnu不同。 I have test programs on Linux and Mac OSX, and the crypt() c-library function displays a 34-character string, if you display result using printf. 我在Linux和Mac OSX上有测试程序,如果使用printf显示结果,crypt()c-library函数会显示34个字符的字符串。 The same code on the Mac OSX, displays only a 13 char string. Mac OSX上的相同代码仅显示13个字符串。 A bit of research suggests that the difference is apparently the Linux crypt() library routine generates the hash from longer vectors on the gnu/gcc Linux side, using perhaps a different encryption algorithm. 一些研究表明,差异显然是Linux crypt()库例程使用可能不同的加密算法从gnu / gcc Linux端的较长向量生成哈希。 Some information also suggests that the Apple Mac OSX c-library crypt() function is only using DES to encrypt the original string plus the salt. 一些信息还表明Apple Mac OSX c-library crypt()函数仅使用DES来加密原始字符串加上salt。 I want to have my test code produce the same results, on both Linux and Mac OSX platforms. 我想让我的测试代码在Linux和Mac OSX平台上产生相同的结果。

Is there a proper crypt() function for Apple Mac OSX, isometric to the gnu/gcc Linux version, perhaps in some open-source encryption library? Apple Mac OSX是否有适当的crypt()函数,等同于gnu / gcc Linux版本,可能在某些开源加密库中?

Or is there a gnu/gcc equivalent crypt(3) function available for Apple Mac OSX somewhere in the Mac OSX development tools? 或者在Mac OSX开发工具中的某个地方是否有适用于Apple Mac OSX的gnu / gcc等效crypt(3)功能? (I am very new to Mac OSX). (我是Mac OSX的新手)。 I am using the clang compiler, part of the Xcode stuff downloaded from Apple, current for Yosemite 10.10.5, and I am guessing I am not the first person to encounter this anomaly. 我正在使用clang编译器,从Apple下载的Xcode东西的一部分,当前用于Yosemite 10.10.5,我猜我不是第一个遇到这种异常的人。 Thanx for any info. Thanx任何信息。

Ah. 啊。 just a little edit: The Apple MacOSX stuff is using DES algo, hence the 13-char result, when inspecting the hash. 只是一点点编辑:Apple MacOSX的东西正在使用DES算法,因此在检查哈希值时会产生13个字符的结果。 Gnu/gcc uses MD5 algo, hence the 34-char resulting hash. Gnu / gcc使用MD5算法,因此产生了34-char的哈希值。 This is explained here: http://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/crypt.html#crypt My refined question then; 这在这里解释: http ://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/crypt.html#crypt然后我提出了精炼的问题; is there a crypt(3) equivalent function for Mac OSX that uses MD5 (or SHA512) instead of DES? 是否有使用MD5(或SHA512)代替DES的Mac OSX的crypt(3)等效函数?

(*** 2nd edit Note: This is getting interesting. DES is poor, but MD5 can be cracked in Kali Linux, using "hashcat"? Recommendation is to go to SHA512 apparently. Details on academic test/verify re. MD5 cracking are here: https://uwnthesis.wordpress.com/2013/08/07/kali-how-to-crack-passwords-using-hashcat/ Still, my question remains. Is there MD5 crypt(3) function for Mac OSX somewhere?? Thx.) (***第二次编辑注意:这很有趣.DES很差,但MD5可以在Kali Linux中使用“hashcat”破解?建议明显转到SHA512。学术测试/验证的详细信息.MD5破解是这里: https//uwnthesis.wordpress.com/2013/08/07/kali-how-to-crack-passwords-using-hashcat/不过,我的问题仍然存在。是否有适用于Mac OSX的MD5 crypt(3)功能?? 谢谢。)

(Pls excuse my rank ignorance of protocol. Mac OS X LLVM/gcc based crypt() fuction is borked junk, hardwired to only use DES, a proven breakable hash, worse than MD5. (Call it with the salt string as $6$, and you will get back a 13 char DES hash. Unbelievable!) I have discovered numerous methods to create password hashes properly (ie. MD5 and SHA512) on Linux platforms (perl, python, etc.) They typically use either the "crypt" lib (same one you get using "-lcrypt" option in gcc on Linux), or "passlib" for python. But my MacBook, just updated to Yosemite 10.10.5 does not even have "passlib"! (My older Fedora box runs Python 2.5.1, current CentOS box runs Python 2.6.6. The nasty little Macbook indicates Python 2.7.10, using "python --version" command. I found this excellent post over at "ServerFault" site: https://serverfault.com/questions/330069/how-to-create-an-sha-512-hashed-password-for-shadow?newreg=df160746fbcd47878d600cbe76ec8b7f (请原谅我对协议的无知.Mac OS X LLVM /基于gcc的crypt()函数是borked垃圾,硬连线使用DES,一个经过验证的易碎哈希,比MD5差。(用盐字符串称为$ 6 $,你会得到一个13 char DES哈希。令人难以置信!)我发现了很多方法可以在Linux平台(perl,python等)上正确创建密码哈希(即MD5和SHA512)。它们通常使用“crypt” lib(在Linux上使用gcc中的“-lcrypt”选项使用同一个),或者使用python的“passlib”。但我的MacBook,刚刚更新到Yosemite 10.10.5甚至没有“passlib”!(我的旧Fedora盒子运行Python 2.5.1,当前的CentOS框运行Python 2.6.6。令人讨厌的小Macbook使用“python --version”命令表示Python 2.7.10。我在“ServerFault”站点找到了这篇优秀文章: https:// serverfault .COM /问题/ 330069 /如何到创建-AN-SHA-512散列密码换影?newreg = df160746fbcd47878d600cbe76ec8b7f

The first python and the perl scripts work on Linux, since they are using glibc crypt(), I am guessing, but no "passlib.hash" seems to exist anywhere, Linux or Mac OS X. 第一个python和perl脚本在Linux上工作,因为他们正在使用glibc crypt(),我猜,但是没有“passlib.hash”似乎存在于任何地方,Linux或Mac OS X.

How the heck can I create a decent password hash on this MacBook thing? 我怎么能在这台MacBook上创建一个像样的密码哈希呢? I am a Mac OS X noob, and since I have confirmed that Apple is using SHA512 password hashes inside its .plist files, I am certain this fuctionality has to exist somewhere on this weird (but lovely) piece of alien hardware. 我是一个Mac OS X菜鸟,因为我已经确认Apple在其.plist文件中使用SHA512密码哈希,我确信这个功能必须存在于这个奇怪(但可爱)的外星硬件上。 In case one is curious, you can enter this to see your "ShadowHashData" on Yosemite, from the cmd line in terminal: (sorry, forgot reference for this, found it searching last nite, really helpful) 如果一个人好奇,你可以输入这个以在Yosemite上看到你的“ShadowHashData”,从终端的cmd行:(对不起,忘了参考这个,发现它搜索的最后一点,真的很有帮助)

sudo defaults read /var/db/dslocal/nodes/Default/users/<yourusername>.plist ShadowHashData | tr -dc 0-9a-f | xxd -r -p | plutil -convert xml1 - -o -

So it looks like Darwin/Yosemite is using ok encryption. 所以看起来Darwin / Yosemite正在使用ok加密。 I read some Apple documentation on common-crypto stuff, but there is scant info on how to tweak your gcc to actually point to the library containing this critical stuff. 我阅读了一些关于常见加密内容的Apple文档,但是关于如何调整你的gcc以实际指向包含这些关键内容的库的信息很少。 When I determine how to this, I will post the answer here. 当我确定如何做到这一点时,我会在这里发布答案。

OS X doesn't use its crypt function for much of anything. OS X不会将其crypt函数用于任何事情。 It has it for compatibility with POSIX, which doesn't define how it works, and different platforms have built different solutions over the years. 它具有与POSIX的兼容性,POSIX没有定义它的工作方式,并且不同的平台多年来已经构建了不同的解决方案。 Linux's isn't particularly "correct," it's just another vendor-specific solution. Linux并不是特别“正确”,它只是另一个供应商特定的解决方案。 Apple explains their rationale for crypt in crypt(1): Apple解释了他们在crypt中的crypt的基本原理(1):

This library (FreeSec 1.0) was developed outside the United States of America as an unencumbered replacement for the US-only libcrypt encryp- tion library. 该库(FreeSec 1.0)是在美国境外开发的,作为仅限美国的libcrypt加密库的无阻碍替代品。 Programs linked against the crypt() interface may be exported from the USA only if they use crypt() solely for authentication purposes and avoid use of the other programmer interfaces listed above. 只有当crypt()仅用于验证目的并且避免使用上面列出的其他程序员接口时,才能从美国导出与crypt()接口链接的程序。 Special care has been taken in the library so that programs which only use the crypt() interface do not pull in the other components. 库中已经特别小心,因此只使用crypt()接口的程序不会引入其他组件。

If you need cross-platform password hashing, then you need to implement it with a known algorithm, which crypt doesn't provide. 如果您需要跨平台密码哈希,那么您需要使用已知算法实现它,而crypt不提供。 In general that means you're going to need to generate your own format, because there really isn't a standard one. 一般来说,这意味着您将需要生成自己的格式,因为实际上没有标准格式。 I recommend using PBKDF2 rather than just salted SHA2, since it includes stretching as well as salting. 我建议使用PBKDF2而不仅仅是盐渍SHA2,因为它包括拉伸和盐渍。 Cracking weak SHA512 passwords with John the Ripper is still very fast and easy. 使用John the Ripper破解弱的SHA512密码仍然非常快速和简单。 With good stretching, even fairly weak passwords can be protected. 通过良好的拉伸,甚至可以保护相当弱的密码。 (From the description of Linux's crypt they seem to be doing something similar to PKBDF2; possibly exactly PBKDF2 without naming it.) Similar algorithms include scrypt and bcrypt . (根据Linux的crypt的描述,他们似乎做了类似于PKBDF2的事情;可能完全没有命名它的PBKDF2。)类似的算法包括scryptbcrypt I like PBKDF2 because it's so ubiquitous and recommended by NIST (even though there are very reasonable arguments that bcrypt and scrypt are stronger). 我喜欢PBKDF2因为它无处不在并且被NIST推荐(即使有非常合理的论据认为bcrypt和scrypt更强)。

The pieces of PKBDF2 aren't all that complicated, and there are some good implementations of the pieces you need in C with permissive licenses. PKBDF2的部分并不是那么复杂,并且在C中使用许可许可证有一些很好的实现。 See MGCryptor for one example that has all the pieces you would require in simple ANSI C with an MIT license. 有关一个示例,请参阅MGCryptor ,其中包含使用MIT许可证的简单ANSI C中所需的所有部分。 Look particularly at pkcs5_pbkdf2() which may be exactly what you want. 特别pkcs5_pbkdf2() ,这可能正是你想要的。

PBKDF2 is widely available on many platforms and languages. PBKDF2在许多平台和语言上广泛使用。 OS X provides it through Common Crypto. OS X通过Common Crypto提供它。

You of course could implement your own version of Linux's crypt using Common Crypto as well. 您当然可以使用Common Crypto实现您自己的Linux crypt版本。 But you'll have to be very careful not to copy any (L)GPL code in the process unless you plan to use a compatible license. 但除非您打算使用兼容许可,否则您必须非常小心,不要在此过程中复制任何(L)GPL代码。 Personally, I would build a PBKDF2-based solution. 就个人而言,我会构建一个基于PBKDF2的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM