Path: blob/master/security/keys/encrypted-keys/ecryptfs_format.c
26424 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* ecryptfs_format.c: helper functions for the encrypted key type3*4* Copyright (C) 2006 International Business Machines Corp.5* Copyright (C) 2010 Politecnico di Torino, Italy6* TORSEC group -- https://security.polito.it7*8* Authors:9* Michael A. Halcrow <[email protected]>10* Tyler Hicks <[email protected]>11* Roberto Sassu <[email protected]>12*/1314#include <linux/export.h>15#include <linux/string.h>16#include "ecryptfs_format.h"1718u8 *ecryptfs_get_auth_tok_key(struct ecryptfs_auth_tok *auth_tok)19{20return auth_tok->token.password.session_key_encryption_key;21}22EXPORT_SYMBOL(ecryptfs_get_auth_tok_key);2324/*25* ecryptfs_get_versions()26*27* Source code taken from the software 'ecryptfs-utils' version 83.28*29*/30void ecryptfs_get_versions(int *major, int *minor, int *file_version)31{32*major = ECRYPTFS_VERSION_MAJOR;33*minor = ECRYPTFS_VERSION_MINOR;34if (file_version)35*file_version = ECRYPTFS_SUPPORTED_FILE_VERSION;36}37EXPORT_SYMBOL(ecryptfs_get_versions);3839/*40* ecryptfs_fill_auth_tok - fill the ecryptfs_auth_tok structure41*42* Fill the ecryptfs_auth_tok structure with required ecryptfs data.43* The source code is inspired to the original function generate_payload()44* shipped with the software 'ecryptfs-utils' version 83.45*46*/47int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok,48const char *key_desc)49{50int major, minor;5152ecryptfs_get_versions(&major, &minor, NULL);53auth_tok->version = (((uint16_t)(major << 8) & 0xFF00)54| ((uint16_t)minor & 0x00FF));55auth_tok->token_type = ECRYPTFS_PASSWORD;56strncpy((char *)auth_tok->token.password.signature, key_desc,57ECRYPTFS_PASSWORD_SIG_SIZE);58auth_tok->token.password.session_key_encryption_key_bytes =59ECRYPTFS_MAX_KEY_BYTES;60/*61* Removed auth_tok->token.password.salt and62* auth_tok->token.password.session_key_encryption_key63* initialization from the original code64*/65/* TODO: Make the hash parameterizable via policy */66auth_tok->token.password.flags |=67ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET;68/* The kernel code will encrypt the session key. */69auth_tok->session_key.encrypted_key[0] = 0;70auth_tok->session_key.encrypted_key_size = 0;71/* Default; subject to change by kernel eCryptfs */72auth_tok->token.password.hash_algo = PGP_DIGEST_ALGO_SHA512;73auth_tok->token.password.flags &= ~(ECRYPTFS_PERSISTENT_PASSWORD);74return 0;75}76EXPORT_SYMBOL(ecryptfs_fill_auth_tok);777879