xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/nsmb_preauth.c (revision fb217153ae25423b48522eea4456af6b24de0a3c)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2021-2025 RackTop Systems, Inc.
14  */
15 
16 #include <sys/types.h>
17 
18 #include <netsmb/smb_conn.h>
19 #include <netsmb/nsmb_kcrypt.h>
20 
21 #include <netsmb/mchain.h>
22 
23 /*
24  * SMB 3.1.1 Preauth Integrity
25  */
26 
27 /*
28  * (called from smb2_negotiate_common)
29  */
30 int
nsmb_preauth_init(smb_vc_t * vcp)31 nsmb_preauth_init(smb_vc_t *vcp)
32 {
33 	int rc;
34 
35 	rc = nsmb_sha512_getmech(&vcp->vc3_preauthmech);
36 	if (rc != 0) {
37 		return (EAUTH);
38 	}
39 
40 	return (rc);
41 }
42 
43 /* ARGSUSED */
44 int
nsmb_preauth_calc(smb_vc_t * vcp,mblk_t * mb,uint8_t * in_hashval,uint8_t * out_hashval)45 nsmb_preauth_calc(smb_vc_t *vcp, mblk_t *mb,
46     uint8_t *in_hashval, uint8_t *out_hashval)
47 {
48 	smb_sign_ctx_t ctx = 0;
49 	int rc;
50 
51 	if ((rc = nsmb_sha512_init(&ctx, &vcp->vc3_preauthmech)) != 0)
52 		return (rc);
53 
54 	/* Digest current hashval */
55 	rc = nsmb_sha512_update(ctx, in_hashval, SHA512_DIGEST_LENGTH);
56 	if (rc != 0)
57 		return (rc);
58 
59 	while (mb != NULL) {
60 		size_t len = MBLKL(mb);
61 
62 		rc = nsmb_sha512_update(ctx, mb->b_rptr, len);
63 		if (rc != 0)
64 			return (rc);
65 		mb = mb->b_cont;
66 	}
67 
68 	rc = nsmb_sha512_final(ctx, out_hashval);
69 
70 	return (rc);
71 }
72