175
* @fnek An allocated char array into which the generated
176
* passphrase is written; ECRYPTFS_MAX_PASSPHRASE_BYTES bytes should be
179
* @passphrase A NULL-terminated char array
183
* @passphrase_sig An allocated char array into which the generated
184
* signature is written; PASSWORD_SIG_SIZE bytes should be allocated
188
generate_fnek(char *fnek, char *salt, char *passphrase)
190
char salt_and_passphrase[ECRYPTFS_MAX_PASSPHRASE_BYTES
191
+ ECRYPTFS_SALT_SIZE];
194
int alg = SEC_OID_SHA512;
196
int alg = GCRY_MD_SHA512;
197
#endif /* #ifdef ENABLE_NSS */
198
int dig_len = SHA512_DIGEST_LENGTH;
199
char buf[SHA512_DIGEST_LENGTH];
200
int hash_iterations = ECRYPTFS_DEFAULT_NUM_FNEK_HASH_ITERATIONS;
203
passphrase_size = strlen(passphrase);
204
if (passphrase_size > ECRYPTFS_MAX_PASSPHRASE_BYTES) {
206
syslog(LOG_ERR, "Passphrase too large (%d bytes)\n",
210
memcpy(salt_and_passphrase, salt, ECRYPTFS_SALT_SIZE);
211
memcpy((salt_and_passphrase + ECRYPTFS_SALT_SIZE), passphrase,
213
if ((rc = do_hash(salt_and_passphrase,
214
(ECRYPTFS_SALT_SIZE + passphrase_size), buf, alg))) {
218
while (hash_iterations--) {
219
if ((rc = do_hash(buf, dig_len, buf, alg))) {
223
if ((rc = do_hash(buf, dig_len, buf, alg))) {
226
to_hex(fnek, buf, ECRYPTFS_MAX_KEY_BYTES/4);
231
175
* @return Zero on success