fs/ubifs/auth.c
Source file repositories/reference/linux-study-clean/fs/ubifs/auth.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ubifs/auth.c- Extension
.c- Size
- 13556 bytes
- Lines
- 531
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/verification.hcrypto/hash.hcrypto/utils.hkeys/user-type.hkeys/asymmetric-type.hubifs.h
Detected Declarations
function Copyrightfunction ubifs_hash_calc_hmacfunction ubifs_prepare_auth_nodefunction ubifs_bad_hashfunction __ubifs_node_check_hashfunction ubifs_sb_verify_signaturefunction ubifs_init_authenticationfunction __ubifs_exit_authenticationfunction ubifs_node_calc_hmacfunction __ubifs_node_insert_hmacfunction __ubifs_node_verify_hmacfunction __ubifs_shash_copy_statefunction ubifs_hmac_wkmfunction ubifs_hmac_zero
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* This file is part of UBIFS.
*
* Copyright (C) 2018 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
*/
/*
* This file implements various helper functions for UBIFS authentication support
*/
#include <linux/verification.h>
#include <crypto/hash.h>
#include <crypto/utils.h>
#include <keys/user-type.h>
#include <keys/asymmetric-type.h>
#include "ubifs.h"
/**
* __ubifs_node_calc_hash - calculate the hash of a UBIFS node
* @c: UBIFS file-system description object
* @node: the node to calculate a hash for
* @hash: the returned hash
*
* Returns 0 for success or a negative error code otherwise.
*/
int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *node,
u8 *hash)
{
const struct ubifs_ch *ch = node;
return crypto_shash_tfm_digest(c->hash_tfm, node, le32_to_cpu(ch->len),
hash);
}
/**
* ubifs_hash_calc_hmac - calculate a HMAC from a hash
* @c: UBIFS file-system description object
* @hash: the node to calculate a HMAC for
* @hmac: the returned HMAC
*
* Returns 0 for success or a negative error code otherwise.
*/
static int ubifs_hash_calc_hmac(const struct ubifs_info *c, const u8 *hash,
u8 *hmac)
{
return crypto_shash_tfm_digest(c->hmac_tfm, hash, c->hash_len, hmac);
}
/**
* ubifs_prepare_auth_node - Prepare an authentication node
* @c: UBIFS file-system description object
* @node: the node to calculate a hash for
* @inhash: input hash of previous nodes
*
* This function prepares an authentication node for writing onto flash.
* It creates a HMAC from the given input hash and writes it to the node.
*
* Returns 0 for success or a negative error code otherwise.
*/
int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
struct shash_desc *inhash)
{
struct ubifs_auth_node *auth = node;
u8 hash[UBIFS_HASH_ARR_SZ];
int err;
{
SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm);
hash_desc->tfm = c->hash_tfm;
ubifs_shash_copy_state(c, inhash, hash_desc);
err = crypto_shash_final(hash_desc, hash);
if (err)
return err;
}
err = ubifs_hash_calc_hmac(c, hash, auth->hmac);
if (err)
return err;
auth->ch.node_type = UBIFS_AUTH_NODE;
ubifs_prepare_node(c, auth, ubifs_auth_node_sz(c), 0);
return 0;
}
static struct shash_desc *ubifs_get_desc(const struct ubifs_info *c,
struct crypto_shash *tfm)
Annotation
- Immediate include surface: `linux/verification.h`, `crypto/hash.h`, `crypto/utils.h`, `keys/user-type.h`, `keys/asymmetric-type.h`, `ubifs.h`.
- Detected declarations: `function Copyright`, `function ubifs_hash_calc_hmac`, `function ubifs_prepare_auth_node`, `function ubifs_bad_hash`, `function __ubifs_node_check_hash`, `function ubifs_sb_verify_signature`, `function ubifs_init_authentication`, `function __ubifs_exit_authentication`, `function ubifs_node_calc_hmac`, `function __ubifs_node_insert_hmac`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.