0


I would like to know if the openssl library include a function for openssl passwd command ?
For example I would like to create a hashed password using sha512 with a custom salt, corresponding command is openssl passwd -6 -salt xxxx password. I search in the documentation but I didn't find anything, always talking about the command but not about the library.
Thanks in advance

Mathis
  • 53
  • 7

1 Answers1

0

There is no one function in the library, if you want to know what the command is doing, it points you to it in the help:

-5 -6

Use the SHA256 / SHA512 based algorithms defined by Ulrich Drepper. See https://www.akkadia.org/drepper/SHA-crypt.txt.

So it's using the openssl library to implement the SHA512 algorithm by Ulrich Drepper.

You can check out the source code here to see how it's done. Look for the shacrypt function which is implementing the Ulrich Drepper algorithm using the openssl library.

Shane Powell
  • 13,698
  • 2
  • 49
  • 61
  • Perfect thanks, the shacrypt function is what I was looking for! So I tried to include it in my code but it uses the OPENSSL_zalloc function like so : `if ((p_bytes = OPENSSL_zalloc(passwd_len)) == NULL)` [line 665](https://github.com/openssl/openssl/blob/master/apps/passwd.c#L665) But in the [documentation](https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_zalloc.html) that function don't return anything so I have that error : _assigning to 'char *' from incompatible type 'void *'_. Any idea ? – Mathis Feb 19 '20 at 10:38
  • Sounds like you are compiling c code with a C++ compiler... You don't need to use OPENSSL_zalloc, you could just change it to new/delete. I would take this is a example of how to implement this with openssl. You should be able to simplify the code to just want you want to do removing openssl only code (like OPENSSL_zalloc for example). – Shane Powell Feb 19 '20 at 16:00
  • Yes that was exactly this, trying to compiling for c++ and not for c. It was because of the implicit conversion from `void*` to `char*` that is working in c but not in c++ (see [this](https://stackoverflow.com/a/7067956/11108779)). So I added a cast and it works perfectly, thanks! – Mathis Feb 20 '20 at 08:42