TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptPkcs5Pbkdf2.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <mbedtls/pkcs5.h>
11
37BOOLEAN
38EFIAPI
40 IN UINTN PasswordLength,
41 IN CONST CHAR8 *Password,
42 IN UINTN SaltLength,
43 IN CONST UINT8 *Salt,
44 IN UINTN IterationCount,
45 IN UINTN DigestSize,
46 IN UINTN KeyLength,
47 OUT UINT8 *OutKey
48 )
49{
50 mbedtls_md_type_t HashAlg;
51
52 //
53 // Parameter Checking.
54 //
55 if ((Password == NULL) || (Salt == NULL) || (OutKey == NULL)) {
56 return FALSE;
57 }
58
59 if ((PasswordLength == 0) || (PasswordLength > INT_MAX) ||
60 (SaltLength == 0) || (SaltLength > INT_MAX) ||
61 (KeyLength == 0) || (KeyLength > INT_MAX) ||
62 (IterationCount < 1) || (IterationCount > INT_MAX))
63 {
64 return FALSE;
65 }
66
67 //
68 // Make sure the digest algorithm is supported.
69 //
70 switch (DigestSize) {
72 HashAlg = MBEDTLS_MD_SHA1;
73 break;
75 HashAlg = MBEDTLS_MD_SHA256;
76 break;
77 default:
78 return FALSE;
79 break;
80 }
81
82 //
83 // Perform password-based key derivation routines.
84 //
85 if (mbedtls_pkcs5_pbkdf2_hmac_ext (
86 HashAlg,
87 (CONST UINT8 *)Password,
88 (int)PasswordLength,
89 (CONST UINT8 *)Salt,
90 (int)SaltLength,
91 (int)IterationCount,
92 (int)KeyLength,
93 (UINT8 *)OutKey
94 ) != 0)
95 {
96 return FALSE;
97 } else {
98 return TRUE;
99 }
100}
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 TRUE
Definition: Base.h:301
#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)