mirror of
https://github.com/hilch/Bcrypt.cpp.git
synced 2026-08-27 19:56:33 +02:00
changed interface
This commit is contained in:
+1
-1
@@ -34,5 +34,5 @@ bin
|
||||
obj
|
||||
|
||||
# IDE Files
|
||||
*.cbp
|
||||
*.layout
|
||||
|
||||
|
||||
@@ -11,22 +11,21 @@ Here an example how to use this wrapper class
|
||||
#include <string>
|
||||
|
||||
|
||||
using namespace bcrypt;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::string password = "top_secret";
|
||||
|
||||
std::string hash = BCrypt::generateHash(password);
|
||||
std::string hash = bcrypt::generateHash(password);
|
||||
|
||||
std::cout << "Hash: " << hash << std::endl;
|
||||
|
||||
std::cout << "\"" << password << "\" : " << BCrypt::validatePassword(password,hash) << std::endl;
|
||||
std::cout << "\"wrong\" : " << BCrypt::validatePassword("wrong",hash) << std::endl;
|
||||
std::cout << "\"" << password << "\" : " << bcrypt::validatePassword(password,hash) << std::endl;
|
||||
std::cout << "\"wrong\" : " << bcrypt::validatePassword("wrong",hash) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
output:
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="bcrypt" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="mingw64" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/bcrypt" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="mingw64" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
<Add directory="include" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/bcrypt" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="mingw64" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="include/bcrypt.h" />
|
||||
<Unit filename="src/bcrypt.cpp" />
|
||||
<Unit filename="src/blf.h" />
|
||||
<Unit filename="src/blowfish.cpp" />
|
||||
<Unit filename="src/openbsd.cpp" />
|
||||
<Unit filename="src/openbsd.h" />
|
||||
<Unit filename="test/main.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
+2
-10
@@ -6,16 +6,8 @@
|
||||
namespace bcrypt
|
||||
{
|
||||
|
||||
class BCrypt {
|
||||
public:
|
||||
static std::string generateHash(const std::string & password , unsigned rounds = 10 );
|
||||
static bool validatePassword(const std::string & password, const std::string & hash);
|
||||
|
||||
};
|
||||
|
||||
|
||||
int bcrypt_newhash(const char *pass, int log_rounds, char *hash, size_t hashlen);
|
||||
int bcrypt_checkpass(const char *pass, const char *goodhash);
|
||||
std::string generateHash(const std::string & password , unsigned rounds = 10 );
|
||||
bool validatePassword(const std::string & password, const std::string & hash);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+9
-7
@@ -45,8 +45,7 @@
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
namespace bcrypt
|
||||
{
|
||||
|
||||
|
||||
/* This implementation is adaptable to current computing power.
|
||||
* You can have up to 2^31 rounds which should be enough for some
|
||||
@@ -416,15 +415,18 @@ bcrypt_gensalt(uint8_t log_rounds)
|
||||
|
||||
bool init = false;
|
||||
|
||||
std::string BCrypt::generateHash(const std::string & password , unsigned rounds)
|
||||
namespace bcrypt
|
||||
{
|
||||
|
||||
std::string generateHash(const std::string & password, unsigned rounds)
|
||||
{
|
||||
if( !init )
|
||||
{
|
||||
arc4random_init();
|
||||
init = true;
|
||||
arc4random_init();
|
||||
init = true;
|
||||
}
|
||||
|
||||
char hash[61]={0};
|
||||
char hash[61]= {0};
|
||||
int result = bcrypt_newhash( password.c_str(), rounds, hash, sizeof(hash));
|
||||
|
||||
if( !result )
|
||||
@@ -433,7 +435,7 @@ std::string BCrypt::generateHash(const std::string & password , unsigned rounds)
|
||||
return("");
|
||||
}
|
||||
|
||||
bool BCrypt::validatePassword(const std::string & password, const std::string & hash)
|
||||
bool validatePassword(const std::string & password, const std::string & hash)
|
||||
{
|
||||
return !bcrypt_checkpass(password.c_str(), hash.c_str() );
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace bcrypt {
|
||||
|
||||
|
||||
/* Schneier states the maximum key length to be 56 bytes.
|
||||
@@ -88,6 +87,5 @@ void blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t);
|
||||
void blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
|
||||
void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
#include "blf.h"
|
||||
|
||||
namespace bcrypt {
|
||||
|
||||
/* Function for Feistel Networks */
|
||||
|
||||
@@ -674,4 +673,3 @@ blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+2
-3
@@ -3,8 +3,7 @@
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace bcrypt
|
||||
{
|
||||
|
||||
void arc4random_buf(void *buf, size_t nbytes)
|
||||
{
|
||||
for( size_t n = 0; n < nbytes; ++ n)
|
||||
@@ -22,4 +21,4 @@ void explicit_bzero(void *b, size_t len)
|
||||
dont_optimize = dont_optimize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -3,10 +3,9 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace bcrypt
|
||||
{
|
||||
|
||||
void arc4random_buf(void *buf, size_t nbytes);
|
||||
void explicit_bzero(void *b, size_t len);
|
||||
void arc4random_init(void);
|
||||
}
|
||||
|
||||
#endif // ARC4RANDOM_H_INCLUDED
|
||||
|
||||
+3
-4
@@ -2,19 +2,18 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace bcrypt;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::string password = "top_secret";
|
||||
|
||||
std::string hash = BCrypt::generateHash(password);
|
||||
std::string hash = bcrypt::generateHash(password);
|
||||
|
||||
std::cout << "Hash: " << hash << std::endl;
|
||||
|
||||
std::cout << "\"" << password << "\" : " << BCrypt::validatePassword(password,hash) << std::endl;
|
||||
std::cout << "\"wrong\" : " << BCrypt::validatePassword("wrong",hash) << std::endl;
|
||||
std::cout << "\"" << password << "\" : " << bcrypt::validatePassword(password,hash) << std::endl;
|
||||
std::cout << "\"wrong\" : " << bcrypt::validatePassword("wrong",hash) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user