Files
nsis-plugin-ns7zip/versions/26.00/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp
T
Simone d074cc7c07 chore: initial commit (extracted from Launchers monorepo)
Plugin: ns7zip v2.0.0
Architectures: x86-ansi, x86-unicode, amd64-unicode
License: LGPL-2.1-or-later
2026-04-29 14:07:51 +02:00

49 lines
931 B
C++

// Pbkdf2HmacSha1.cpp
#include "StdAfx.h"
#include <string.h>
#include "../../../C/CpuArch.h"
#include "HmacSha1.h"
#include "Pbkdf2HmacSha1.h"
namespace NCrypto {
namespace NSha1 {
void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize,
const Byte *salt, size_t saltSize,
UInt32 numIterations,
Byte *key, size_t keySize)
{
MY_ALIGN (16)
CHmac baseCtx;
baseCtx.SetKey(pwd, pwdSize);
for (UInt32 i = 1; keySize != 0; i++)
{
MY_ALIGN (16)
CHmac ctx;
ctx = baseCtx;
ctx.Update(salt, saltSize);
MY_ALIGN (16)
UInt32 u[kNumDigestWords];
SetBe32(u, i)
ctx.Update((const Byte *)u, 4);
ctx.Final((Byte *)u);
ctx = baseCtx;
ctx.GetLoopXorDigest1((void *)u, numIterations - 1);
const unsigned curSize = (keySize < kDigestSize) ? (unsigned)keySize : kDigestSize;
memcpy(key, (const Byte *)u, curSize);
key += curSize;
keySize -= curSize;
}
}
}}