fs/smb/client/cifsencrypt.c
Source file repositories/reference/linux-study-clean/fs/smb/client/cifsencrypt.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/client/cifsencrypt.c- Extension
.c- Size
- 13439 bytes
- Lines
- 515
- 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/fs.hlinux/slab.hcifsglob.hcifs_debug.hcifs_unicode.hcifsproto.hntlmssp.hlinux/ctype.hlinux/random.hlinux/highmem.hlinux/fips.hlinux/iov_iter.hcrypto/aead.hcrypto/aes-cbc-macs.hcrypto/arc4.hcrypto/md5.hcrypto/sha2.h
Detected Declarations
function Copyrightfunction cifs_sig_finalfunction cifs_sig_iterfunction __cifs_calc_signaturefunction timefunction find_av_namefunction av_for_each_entryfunction authenticationfunction av_for_each_entryfunction calc_ntlmv2_hashfunction CalcNTLMv2_responsefunction SPNfunction setup_ntlmv2_rspfunction calc_seckeyfunction cifs_crypto_secmech_release
Annotated Snippet
if (!IS_ALIGNED(len, sizeof(__le16))) {
cifs_dbg(VFS | ONCE, "%s: bad length(%u) for type %u\n",
__func__, len, type);
continue;
}
nlen = len / sizeof(__le16);
if (nlen <= maxlen) {
++nlen;
*name = kmalloc(nlen, GFP_KERNEL);
if (!*name)
return -ENOMEM;
cifs_from_utf16(*name, AV_DATA_PTR(av), nlen,
len, nlsc, NO_MAP_UNI_RSVD);
break;
}
}
return 0;
}
/* Server has provided av pairs/target info in the type 2 challenge
* packet and we have plucked it and stored within smb session.
* We parse that blob here to find the server given timestamp
* as part of ntlmv2 authentication (or local current time as
* default in case of failure)
*/
static __le64 find_timestamp(struct cifs_ses *ses)
{
struct ntlmssp2_name *av;
struct timespec64 ts;
av_for_each_entry(ses, av) {
if (AV_TYPE(av) == NTLMSSP_AV_TIMESTAMP &&
AV_LEN(av) == sizeof(u64))
return *((__le64 *)AV_DATA_PTR(av));
}
ktime_get_real_ts64(&ts);
return cpu_to_le64(cifs_UnixTimeToNT(ts));
}
static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
const struct nls_table *nls_cp)
{
int len;
char nt_hash[CIFS_NTHASH_SIZE];
struct hmac_md5_ctx hmac_ctx;
__le16 *user;
wchar_t *domain;
wchar_t *server;
/* calculate md4 hash of password */
E_md4hash(ses->password, nt_hash, nls_cp);
hmac_md5_init_usingrawkey(&hmac_ctx, nt_hash, CIFS_NTHASH_SIZE);
/* convert ses->user_name to unicode */
len = ses->user_name ? strlen(ses->user_name) : 0;
user = kmalloc(2 + (len * 2), GFP_KERNEL);
if (user == NULL)
return -ENOMEM;
if (len) {
len = cifs_strtoUTF16(user, ses->user_name, len, nls_cp);
UniStrupr(user);
} else {
*(u16 *)user = 0;
}
hmac_md5_update(&hmac_ctx, (const u8 *)user, 2 * len);
kfree(user);
/* convert ses->domainName to unicode and uppercase */
if (ses->domainName) {
len = strlen(ses->domainName);
domain = kmalloc(2 + (len * 2), GFP_KERNEL);
if (domain == NULL)
return -ENOMEM;
len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len,
nls_cp);
hmac_md5_update(&hmac_ctx, (const u8 *)domain, 2 * len);
kfree(domain);
} else {
/* We use ses->ip_addr if no domain name available */
len = strlen(ses->ip_addr);
server = kmalloc(2 + (len * 2), GFP_KERNEL);
if (server == NULL)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/slab.h`, `cifsglob.h`, `cifs_debug.h`, `cifs_unicode.h`, `cifsproto.h`, `ntlmssp.h`, `linux/ctype.h`.
- Detected declarations: `function Copyright`, `function cifs_sig_final`, `function cifs_sig_iter`, `function __cifs_calc_signature`, `function time`, `function find_av_name`, `function av_for_each_entry`, `function authentication`, `function av_for_each_entry`, `function calc_ntlmv2_hash`.
- 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.