summaryrefslogtreecommitdiffstats
path: root/crypto/ext4crypt/HashPassword.cpp
diff options
context:
space:
mode:
authorbig biff <bigbiff@teamw.in>2019-06-25 02:01:42 +0200
committerGerrit Code Review <gerrit2@gerrit.omnirom.org>2019-06-25 02:01:42 +0200
commit0bd7c590266a944f415cf05ea44c9715b4445dbb (patch)
tree1a9465b1885bbdc39a5ce56b2f4561f92957c57f /crypto/ext4crypt/HashPassword.cpp
parentBackup_Tar(): Properly localise string instead of using English. (diff)
parentext4crypt: support synthetic keys v3 on May update (diff)
downloadandroid_bootable_recovery-0bd7c590266a944f415cf05ea44c9715b4445dbb.tar
android_bootable_recovery-0bd7c590266a944f415cf05ea44c9715b4445dbb.tar.gz
android_bootable_recovery-0bd7c590266a944f415cf05ea44c9715b4445dbb.tar.bz2
android_bootable_recovery-0bd7c590266a944f415cf05ea44c9715b4445dbb.tar.lz
android_bootable_recovery-0bd7c590266a944f415cf05ea44c9715b4445dbb.tar.xz
android_bootable_recovery-0bd7c590266a944f415cf05ea44c9715b4445dbb.tar.zst
android_bootable_recovery-0bd7c590266a944f415cf05ea44c9715b4445dbb.zip
Diffstat (limited to 'crypto/ext4crypt/HashPassword.cpp')
-rw-r--r--crypto/ext4crypt/HashPassword.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/crypto/ext4crypt/HashPassword.cpp b/crypto/ext4crypt/HashPassword.cpp
index 817c984bd..07ecb1f7d 100644
--- a/crypto/ext4crypt/HashPassword.cpp
+++ b/crypto/ext4crypt/HashPassword.cpp
@@ -27,11 +27,13 @@
#include <string>
#include <stdlib.h>
#include <openssl/sha.h>
+#include <openssl/hmac.h>
#include "HashPassword.h"
#define PASS_PADDING_SIZE 128
#define SHA512_HEX_SIZE SHA512_DIGEST_LENGTH * 2
+#define SHA256_HEX_SIZE SHA256_DIGEST_LENGTH * 2
void* PersonalizedHashBinary(const char* prefix, const char* key, const size_t key_size) {
size_t size = PASS_PADDING_SIZE + key_size;
@@ -78,6 +80,37 @@ std::string PersonalizedHash(const char* prefix, const std::string& Password) {
return PersonalizedHash(prefix, Password.c_str(), Password.size());
}
+std::string PersonalizedHashSP800(const char* label, const char* context, const char* key, const size_t key_size) {
+ HMAC_CTX ctx;
+ HMAC_CTX_init(&ctx);
+ HMAC_Init_ex(&ctx, key, key_size, EVP_sha256(), NULL);
+ unsigned int counter = 1;
+ endianswap(&counter);
+ HMAC_Update(&ctx, (const unsigned char*)&counter, 4);
+ HMAC_Update(&ctx, (const unsigned char*)label, strlen(label));
+ const unsigned char divider = 0;
+ HMAC_Update(&ctx, &divider, 1);
+ HMAC_Update(&ctx, (const unsigned char*)context, strlen(context));
+ unsigned int contextDisambiguation = strlen(context) * 8;
+ endianswap(&contextDisambiguation);
+ HMAC_Update(&ctx, (const unsigned char*)&contextDisambiguation, 4);
+ unsigned int finalValue = 256;
+ endianswap(&finalValue);
+ HMAC_Update(&ctx, (const unsigned char*)&finalValue, 4);
+
+ unsigned char output[SHA256_DIGEST_LENGTH];
+ unsigned int out_size = 0;
+ HMAC_Final(&ctx, output, &out_size);
+
+ int index = 0;
+ char hex_hash[SHA256_HEX_SIZE + 1];
+ for(index = 0; index < SHA256_DIGEST_LENGTH; index++)
+ sprintf(hex_hash + (index * 2), "%02x", output[index]);
+ hex_hash[SHA256_HEX_SIZE] = 0;
+ std::string ret = hex_hash;
+ return ret;
+}
+
std::string HashPassword(const std::string& Password) {
const char* prefix = FBE_PERSONALIZATION;
return PersonalizedHash(prefix, Password);