TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptPkcs5Pbkdf2.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <openssl/evp.h>
11#include <openssl/hmac.h>
12
38BOOLEAN
39EFIAPI
41 IN UINTN PasswordLength,
42 IN CONST CHAR8 *Password,
43 IN UINTN SaltLength,
44 IN CONST UINT8 *Salt,
45 IN UINTN IterationCount,
46 IN UINTN DigestSize,
47 IN UINTN KeyLength,
48 OUT UINT8 *OutKey
49 )
50{
51 CONST EVP_MD *HashAlg;
52
53 HashAlg = NULL;
54
55 //
56 // Parameter Checking.
57 //
58 if ((Password == NULL) || (Salt == NULL) || (OutKey == NULL)) {
59 return FALSE;
60 }
61
62 if ((PasswordLength == 0) || (PasswordLength > INT_MAX) ||
63 (SaltLength == 0) || (SaltLength > INT_MAX) ||
64 (KeyLength == 0) || (KeyLength > INT_MAX) ||
65 (IterationCount < 1) || (IterationCount > INT_MAX))
66 {
67 return FALSE;
68 }
69
70 //
71 // Make sure the digest algorithm is supported.
72 //
73 switch (DigestSize) {
75 HashAlg = EVP_sha1 ();
76 break;
78 HashAlg = EVP_sha256 ();
79 break;
80 default:
81 return FALSE;
82 break;
83 }
84
85 //
86 // Perform password-based key derivation routines.
87 //
88 return (BOOLEAN)PKCS5_PBKDF2_HMAC (
89 (const char *)Password,
90 (int)PasswordLength,
91 (const unsigned char *)Salt,
92 (int)SaltLength,
93 (int)IterationCount,
94 HashAlg,
95 (int)KeyLength,
96 (unsigned char *)OutKey
97 );
98}
UINT64 UINTN
#define SHA1_DIGEST_SIZE
Definition: BaseCryptLib.h:39
#define SHA256_DIGEST_SIZE
Definition: BaseCryptLib.h:44
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI Pkcs5HashPassword(IN UINTN PasswordLength, IN CONST CHAR8 *Password, IN UINTN SaltLength, IN CONST UINT8 *Salt, IN UINTN IterationCount, IN UINTN DigestSize, IN UINTN KeyLength, OUT UINT8 *OutKey)