Exemple #1
0
//Test method for 'bcrypt_salt()'
int test_salt(int rounds)
{
	std::cout << "bcrypt_salt ";
	for (int i = 0; i < 20; i++) {
		std::cerr << ".";
		std::string plain = test_data[i][0];
		std::string salt = bcrypt_salt(rounds);
		std::string hashed1 = bcrypt_hash(plain, salt);
		std::string hashed2 = bcrypt_hash(plain, hashed1);

		if (hashed1 != hashed2) {
			std::cerr << std::endl << "hash[" << hashed1 << "] != expected[" << hashed2 << "]" << std::endl;
			return 1;
		}
	}
	std::cerr << "Ok" << std::endl;
	return 0;
}
Exemple #2
0
//Test for correct hashing of non-US-ASCII passwords
int test_international_chars(int rounds)
{
	std::cout << "bcrypt_hash w/ international chars ";

	std::string pw1 = "ππππππππ";
	std::string pw2 = "????????";

	std::string h1 = bcrypt_hash(pw1, bcrypt_salt(rounds));
	if (pw2 == h1) {
		std::cerr<<"hash[" << pw2 << "] == expected[" << h1 << "]" << std::endl;
		return 1;                   
	}

	std::string h2 = bcrypt_hash(pw2, bcrypt_salt(rounds));
	if (pw1 == h2) {
		std::cerr<<"hash[" << pw1 << "] == expected[" << h2 << "]" << std::endl;
		return 1;
	}
	std::cerr << "Ok" << std::endl;
	return 0;
}
Exemple #3
0
//Test method for 'bcrypt_hash(string, string)'
int test_hash()
{
	std::cout << "bcrypt_hash ";
	for (int i = 0; i < 20; i++) {
		std::cerr << ".";
		std::string hashed = bcrypt_hash( test_data[i][0], test_data[i][1] );

		if (hashed != test_data[i][2]) {
			std::cerr << std::endl << "hash[" << hashed << "] != expected[" << test_data[i][2] << "]" << std::endl;
			return 1;
		}
	}
	std::cerr << "Ok" << std::endl;
	return 0;
}
Exemple #4
0
void bcrypt_genblock(int counter,
                     const unsigned char hashed_passphrase[64],
                     const unsigned char *salt, int saltbytes,
                     unsigned char output[32])
{
    unsigned char hashed_salt[64];

    /* Hash the input salt with the counter value optionally suffixed
     * to get our real 32-byte salt */
    ssh_hash *h = ssh_hash_new(&ssh_sha512);
    put_data(h, salt, saltbytes);
    if (counter)
        put_uint32(h, counter);
    ssh_hash_final(h, hashed_salt);

    bcrypt_hash(hashed_passphrase, 64, hashed_salt, 64, output);

    smemclr(&hashed_salt, sizeof(hashed_salt));
}