/proc/crypto
カーネルが知っているアルゴリズムの単なるリストです。これはPAMとは何の関係もありません。
PAMに直接クエリを実行して、サポートできるハッシュを見つける方法はありません。もちろん、これは内部的に認識されていますが、パブリックAPIによって公開されることはありません。
実行できることの1つはcrypt
、さまざまなIDタイプでパスをハッシュして、基本的にPAMをプローブすることです(より正確には、PAMがシャドウパスワードに使用するlibcの暗号をプローブします)。簡単な例:
#include <unistd.h>
#include <stdio.h>
#include <string>
bool test_crypt_method(const char* id)
{
const std::string salt =
std::string("$") + id + "$" + "testsalt$";
std::string crypt_result = ::crypt("password", salt.c_str());
/*
* If the hash ID is not supported, glibc unfortunately
* then treats it as a old-style DES crypt rather than
* failing; find this situation.
*/
if(crypt_result.size() == 13 &&
crypt_result[0] == '$' &&
crypt_result.find('$', 1) == std::string::npos)
return false;
return true;
}
int main()
{
if(test_crypt_method("1"))
printf("md5 ");
if(test_crypt_method("2a"))
printf("blowfish ");
if(test_crypt_method("4")) // test for false positives
printf("undefined ");
if(test_crypt_method("5"))
printf("sha256 ");
if(test_crypt_method("6"))
printf("sha512 ");
printf("\n");
}