ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
smb2.h File Reference

SMB2 client wire codec (MS-SMB2), PROTOCORE_ENABLE_SMB - increment 1: the transport frame, the 64-byte sync packet header, and the NEGOTIATE exchange. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  Smb2Header
 Parsed SMB2 sync header. More...
 
struct  Smb2NegotiateContexts
 Parsed SMB 3.1.1 NEGOTIATE-response negotiate contexts (MS-SMB2 §2.2.4 / §2.2.3.1). More...
 
struct  Smb2NegotiateResp
 Parsed NEGOTIATE response (MS-SMB2 §2.2.4). More...
 
struct  SmbPreauth
 The SMB 3.1.1 preauth-integrity hash value (MS-SMB2 §3.1.5.2): a running SHA-512 chained over every NEGOTIATE and SESSION_SETUP message of the handshake. Its final value binds the whole pre-authentication exchange and feeds the 3.1.1 signing / encryption key derivation. More...
 
struct  Smb2SessionSetupResp
 Parsed SESSION_SETUP response (MS-SMB2 §2.2.6). More...
 
struct  Smb2TreeConnectResp
 Parsed TREE_CONNECT response (MS-SMB2 §2.2.10). The TreeId is in the response header. More...
 
struct  Smb2CreateResp
 Parsed CREATE response (MS-SMB2 §2.2.14). More...
 
struct  Smb2CloseResp
 Parsed CLOSE response (MS-SMB2 §2.2.16). More...
 
struct  Smb2ReadResp
 Parsed READ response (MS-SMB2 §2.2.20). More...
 
struct  Smb2WriteResp
 Parsed WRITE response (MS-SMB2 §2.2.22). More...
 
struct  Smb2Ns
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Macros

#define PROTOCORE_SMB2_HEADER_SIZE   64
 Fixed SMB2 sync header size (MS-SMB2 §2.2.1).
 
#define SMB2_NEGOTIATE_SIGNING_ENABLED   0x0001
 NEGOTIATE / SESSION_SETUP SecurityMode flags (MS-SMB2 §2.2.3).
 
#define SMB2_NEGOTIATE_SIGNING_REQUIRED   0x0002
 
#define SMB2_FLAGS_SERVER_TO_REDIR   0x00000001
 SMB2 header Flags field (MS-SMB2 §2.2.1.2).
 
#define SMB2_FLAGS_SIGNED   0x00000008
 the message carries an HMAC signature
 
#define SMB2_SESSION_FLAG_IS_GUEST   0x0001
 SESSION_SETUP response SessionFlags (MS-SMB2 §2.2.6).
 
#define SMB2_SESSION_FLAG_IS_NULL   0x0002
 
#define SMB2_SESSION_FLAG_ENCRYPT_DATA   0x0004
 
#define SMB2_STATUS_SUCCESS   0x00000000
 NT status values seen in the SMB2 header during the SESSION_SETUP exchange.
 
#define SMB2_STATUS_MORE_PROCESSING_REQUIRED   0xC0000016
 server wants the next round
 
#define SMB2_STATUS_END_OF_FILE   0xC0000011
 a READ at/past end of file
 
#define SMB2_SHARE_TYPE_DISK   0x01
 TREE_CONNECT response ShareType (MS-SMB2 §2.2.10).
 
#define SMB2_SHARE_TYPE_PIPE   0x02
 
#define SMB2_SHARE_TYPE_PRINT   0x03
 
#define SMB2_FILE_READ_DATA   0x00000001
 CREATE DesiredAccess masks (MS-DTYP ACCESS_MASK; the common file rights).
 
#define SMB2_FILE_WRITE_DATA   0x00000002
 
#define SMB2_FILE_APPEND_DATA   0x00000004
 
#define SMB2_FILE_READ_ATTRIBUTES   0x00000080
 
#define SMB2_FILE_GENERIC_READ   0x00120089
 RC|SYNC|READ_ATTR|READ_EA|READ_DATA.
 
#define SMB2_FILE_GENERIC_WRITE   0x00120116
 RC|SYNC|WRITE_ATTR|WRITE_EA|APPEND|WRITE.
 
#define SMB2_FILE_SHARE_READ   0x01
 CREATE ShareAccess (MS-SMB2 §2.2.13).
 
#define SMB2_FILE_SHARE_WRITE   0x02
 
#define SMB2_FILE_SHARE_DELETE   0x04
 
#define SMB2_FILE_SUPERSEDE   0
 CREATE CreateDisposition (MS-SMB2 §2.2.13).
 
#define SMB2_FILE_OPEN   1
 open an existing file, fail if absent
 
#define SMB2_FILE_CREATE   2
 create, fail if it exists
 
#define SMB2_FILE_OPEN_IF   3
 open, create if absent
 
#define SMB2_FILE_OVERWRITE   4
 open + truncate, fail if absent
 
#define SMB2_FILE_OVERWRITE_IF   5
 
#define SMB2_FILE_DIRECTORY_FILE   0x00000001
 CREATE CreateOptions (MS-SMB2 §2.2.13; the two we set).
 
#define SMB2_FILE_NON_DIRECTORY_FILE   0x00000040
 
#define SMB2_PREAUTH_INTEGRITY_CAPABILITIES   0x0001
 SMB 3.1.1 negotiate-context types (MS-SMB2 §2.2.3.1).
 
#define SMB2_ENCRYPTION_CAPABILITIES   0x0002
 
#define SMB2_COMPRESSION_CAPABILITIES   0x0003
 
#define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID   0x0005
 
#define SMB2_TRANSPORT_CAPABILITIES   0x0006
 
#define SMB2_RDMA_TRANSFORM_CAPABILITIES   0x0007
 
#define SMB2_SIGNING_CAPABILITIES   0x0008
 
#define SMB2_PREAUTH_INTEGRITY_SHA512   0x0001
 Preauth-integrity hash algorithm IDs (MS-SMB2 §2.2.3.1.1).
 
#define SMB2_SIGNING_HMAC_SHA256   0x0000
 Signing algorithm IDs (MS-SMB2 §2.2.3.1.7).
 
#define SMB2_SIGNING_AES_CMAC   0x0001
 
#define SMB2_SIGNING_AES_GMAC   0x0002
 
#define SMB2_GLOBAL_CAP_ENCRYPTION   0x00000040
 NEGOTIATE request/response Capabilities flags (MS-SMB2 §2.2.3 / §2.2.4). A client that supports transport encryption MUST advertise SMB2_GLOBAL_CAP_ENCRYPTION here, or a server (e.g. Samba with smb encrypt = required) will not negotiate a cipher and will reject the unencrypted session (§3.2.4.2.2).
 
#define SMB2_ENCRYPTION_AES128_CCM   0x0001
 Encryption cipher IDs (MS-SMB2 §2.2.3.1.2).
 
#define SMB2_ENCRYPTION_AES128_GCM   0x0002
 
#define SMB2_ENCRYPTION_AES256_CCM   0x0003
 
#define SMB2_ENCRYPTION_AES256_GCM   0x0004
 
#define PROTOCORE_SMB2_MAX_OFFER_CIPHERS   4
 Max encryption ciphers a NEGOTIATE request can advertise (the four SMB 3.1.1 ciphers).
 
#define PROTOCORE_SMB2_PREAUTH_HASH_LEN   64
 Length of the SMB 3.1.1 preauth-integrity hash (SHA-512 digest size).
 
#define SMB2_SHAREFLAG_ENCRYPT_DATA   0x00008000
 TREE_CONNECT response ShareFlags of interest (MS-SMB2 §2.2.10).
 
#define PROTOCORE_SMB2_TRANSFORM_HDR_LEN   52
 TRANSFORM_HEADER size: ProtocolId(4)+Signature(16)+Nonce(16)+OriginalMessageSize(4)+Reserved(2)+ Flags(2)+SessionId(8) = 52 bytes (MS-SMB2 §2.2.41).
 
#define PROTOCORE_SMB2_TRANSFORM_PROTOCOL_ID   0x424D53FDu
 TRANSFORM_HEADER ProtocolId 0xFD 'S' 'M' 'B' as a little-endian u32.
 
#define PROTOCORE_SMB2_NONCE_FIELD_LEN   16
 The TRANSFORM_HEADER Nonce field width (MS-SMB2 §2.2.41). The AEAD uses the leading protocore_smb2_cipher_nonce_len() bytes; the rest are zero.
 
#define PROTOCORE_SMB2_GCM_NONCE_LEN   12
 AES-GCM nonce length used within the 16-byte Nonce field.
 
#define PROTOCORE_SMB2_CCM_NONCE_LEN   11
 AES-CCM nonce length used within the 16-byte Nonce field (MS-SMB2 §3.1.4.3).
 
#define PROTOCORE_SMB2_MAX_CIPHER_KEY_LEN   32
 Largest cipher key length across the four SMB 3.1.1 ciphers (AES-256), for buffer sizing.
 

Typedefs

typedef enum PROTO_ENUM_PACKED Smb2Command
 SMB2 command codes (MS-SMB2 §2.2.1.2).
 
typedef enum PROTO_ENUM_PACKED Smb2Dialect
 SMB2 dialect revision numbers (MS-SMB2 §2.2.4).
 
typedef enum PROTO_ENUM_PACKED Smb2SignAlgo
 The per-session message-signing algorithm the client selects from the negotiated dialect.
 

Enumerations

enum  PROTO_ENUM_PACKED {
  SMB2_NEGOTIATE = 0x0000 , SMB2_SESSION_SETUP = 0x0001 , SMB2_LOGOFF = 0x0002 , SMB2_TREE_CONNECT = 0x0003 ,
  SMB2_TREE_DISCONNECT = 0x0004 , SMB2_CREATE = 0x0005 , SMB2_CLOSE = 0x0006 , SMB2_READ = 0x0008 ,
  SMB2_WRITE = 0x0009 , SMB2_DIALECT_0202 = 0x0202 , SMB2_DIALECT_0210 = 0x0210 , SMB2_DIALECT_0300 = 0x0300 ,
  SMB2_DIALECT_0302 = 0x0302 , SMB2_DIALECT_0311 = 0x0311 , SMB2_SIGN_ALGO_HMAC_SHA256 = 0 , SMB2_SIGN_ALGO_AES_CMAC = 1
}
 SMB2 command codes (MS-SMB2 §2.2.1.2). More...
 
enum  PROTO_ENUM_PACKED {
  SMB2_NEGOTIATE = 0x0000 , SMB2_SESSION_SETUP = 0x0001 , SMB2_LOGOFF = 0x0002 , SMB2_TREE_CONNECT = 0x0003 ,
  SMB2_TREE_DISCONNECT = 0x0004 , SMB2_CREATE = 0x0005 , SMB2_CLOSE = 0x0006 , SMB2_READ = 0x0008 ,
  SMB2_WRITE = 0x0009 , SMB2_DIALECT_0202 = 0x0202 , SMB2_DIALECT_0210 = 0x0210 , SMB2_DIALECT_0300 = 0x0300 ,
  SMB2_DIALECT_0302 = 0x0302 , SMB2_DIALECT_0311 = 0x0311 , SMB2_SIGN_ALGO_HMAC_SHA256 = 0 , SMB2_SIGN_ALGO_AES_CMAC = 1
}
 SMB2 dialect revision numbers (MS-SMB2 §2.2.4). More...
 
enum  PROTO_ENUM_PACKED {
  SMB2_NEGOTIATE = 0x0000 , SMB2_SESSION_SETUP = 0x0001 , SMB2_LOGOFF = 0x0002 , SMB2_TREE_CONNECT = 0x0003 ,
  SMB2_TREE_DISCONNECT = 0x0004 , SMB2_CREATE = 0x0005 , SMB2_CLOSE = 0x0006 , SMB2_READ = 0x0008 ,
  SMB2_WRITE = 0x0009 , SMB2_DIALECT_0202 = 0x0202 , SMB2_DIALECT_0210 = 0x0210 , SMB2_DIALECT_0300 = 0x0300 ,
  SMB2_DIALECT_0302 = 0x0302 , SMB2_DIALECT_0311 = 0x0311 , SMB2_SIGN_ALGO_HMAC_SHA256 = 0 , SMB2_SIGN_ALGO_AES_CMAC = 1
}
 The per-session message-signing algorithm the client selects from the negotiated dialect. More...
 

Functions

 PROTOCORE_NS_LAYOUT (Smb2Ns, transport_frame, transport_len, build_header, parse_header, build_negotiate, parse_negotiate_response, build_negotiate_311, parse_negotiate_contexts, preauth_init, preauth_update, build_session_setup, parse_session_setup_response, build_tree_connect, parse_tree_connect_response, build_create, parse_create_response, build_close, parse_close_response, build_read, parse_read_response, build_write, parse_write_response, sign, verify, sign_cmac, verify_cmac, derive_signing_key, derive_encryption_keys, encrypt, decrypt)
 
size_t protocore_smb2_transport_frame (uint8_t *work, uint8_t *out, size_t cap, const uint8_t *msg, size_t msg_len)
 Prefix an SMB2 message with the 4-byte Direct-TCP transport header .
 
uint32_t protocore_smb2_transport_len (uint8_t *work, const uint8_t *buf, size_t len)
 Read the Direct-TCP transport length prefix.
 
size_t protocore_smb2_build_header (uint8_t *work, uint8_t *buf, size_t cap, Smb2Command command, uint16_t credit_request, uint64_t message_id, uint32_t tree_id, uint64_t session_id)
 Build a 64-byte SMB2 sync header into buf.
 
proto_bool protocore_smb2_parse_header (uint8_t *work, const uint8_t *buf, size_t len, Smb2Header *out)
 Parse a 64-byte SMB2 sync header (validates ProtocolId + .
 
size_t protocore_smb2_build_negotiate (uint8_t *work, uint8_t *buf, size_t cap, const uint8_t *client_guid, uint16_t security_mode)
 Build a NEGOTIATE request (header + body) offering SMB 2.0.2 / 2.1 .
 
proto_bool protocore_smb2_parse_negotiate_response (uint8_t *work, const uint8_t *msg, size_t len, Smb2NegotiateResp *out)
 Parse a NEGOTIATE response message (the SMB2 header + §2.2.4 body).
 
size_t protocore_smb2_build_negotiate_311 (uint8_t *work, uint8_t *buf, size_t cap, const uint8_t *client_guid, uint16_t security_mode, const uint8_t *salt, size_t salt_len, const uint16_t *ciphers, size_t cipher_count)
 Build an SMB 3.1.1 NEGOTIATE request: the dialect list SMB 2.0.2 .. .
 
proto_bool protocore_smb2_parse_negotiate_contexts (uint8_t *work, const uint8_t *msg, size_t len, Smb2NegotiateContexts *out)
 Walk the negotiate-context list of a 3.1.1 NEGOTIATE response .
 
void protocore_smb2_preauth_init (uint8_t *work, SmbPreauth *p)
 Seed the preauth-integrity hash with 64 zero bytes (the initial .
 
void protocore_smb2_preauth_update (uint8_t *work, uint8_t *crypto_work, SmbPreauth *p, const uint8_t *msg, size_t len)
 Fold one handshake message into the preauth-integrity hash: hash = .
 
size_t protocore_smb2_build_session_setup (uint8_t *work, uint8_t *buf, size_t cap, uint64_t message_id, uint64_t session_id, uint8_t security_mode, const uint8_t *sec_buf, size_t sec_len)
 Build a SESSION_SETUP request (header + §2.2.5 body) carrying a .
 
proto_bool protocore_smb2_parse_session_setup_response (uint8_t *work, const uint8_t *msg, size_t len, Smb2SessionSetupResp *out)
 Parse a SESSION_SETUP response message (the SMB2 header + §2.2.6 .
 
size_t protocore_smb2_build_tree_connect (uint8_t *work, uint8_t *buf, size_t cap, uint64_t message_id, uint64_t session_id, const uint8_t *path_utf16, size_t path_len)
 Build a TREE_CONNECT request (header + §2.2.9 body) for a share path.
 
proto_bool protocore_smb2_parse_tree_connect_response (uint8_t *work, const uint8_t *msg, size_t len, Smb2TreeConnectResp *out)
 Parse a TREE_CONNECT response message (validates command + .
 
size_t protocore_smb2_build_create (uint8_t *work, uint8_t *buf, size_t cap, uint64_t message_id, uint64_t session_id, uint32_t tree_id, uint32_t desired_access, uint32_t share_access, uint32_t create_disposition, uint32_t create_options, const uint8_t *name_utf16, size_t name_len)
 Build a CREATE request (header + §2.2.13 body) to open/create a .
 
proto_bool protocore_smb2_parse_create_response (uint8_t *work, const uint8_t *msg, size_t len, Smb2CreateResp *out)
 Parse a CREATE response message (validates command + StructureSize .
 
size_t protocore_smb2_build_close (uint8_t *work, uint8_t *buf, size_t cap, uint64_t message_id, uint64_t session_id, uint32_t tree_id, const uint8_t *file_id)
 Build a CLOSE request (header + §2.2.15 body) for an open FileId.
 
proto_bool protocore_smb2_parse_close_response (uint8_t *work, const uint8_t *msg, size_t len, Smb2CloseResp *out)
 Parse a CLOSE response message (validates command + StructureSize .
 
size_t protocore_smb2_build_read (uint8_t *work, uint8_t *buf, size_t cap, uint64_t message_id, uint64_t session_id, uint32_t tree_id, const uint8_t *file_id, uint32_t length, uint64_t offset)
 Build a READ request (header + §2.2.19 body) for length bytes at .
 
proto_bool protocore_smb2_parse_read_response (uint8_t *work, const uint8_t *msg, size_t len, Smb2ReadResp *out)
 Parse a READ response message (validates command + StructureSize .
 
size_t protocore_smb2_build_write (uint8_t *work, uint8_t *buf, size_t cap, uint64_t message_id, uint64_t session_id, uint32_t tree_id, const uint8_t *file_id, const uint8_t *data, size_t data_len, uint64_t offset)
 Build a WRITE request (header + §2.2.21 body) writing data at .
 
proto_bool protocore_smb2_parse_write_response (uint8_t *work, const uint8_t *msg, size_t len, Smb2WriteResp *out)
 Parse a WRITE response message (validates command + StructureSize .
 
void protocore_smb2_sign (uint8_t *work, uint8_t *crypto_work, const uint8_t *key, uint8_t *msg, size_t msg_len)
 Sign an SMB2 message in place (MS-SMB2 §3.1.4.1, SMB 2.x). Sets .
 
proto_bool protocore_smb2_verify (uint8_t *work, uint8_t *crypto_work, const uint8_t *key, uint8_t *msg, size_t msg_len)
 Verify an SMB2 message's signature (MS-SMB2 §3.1.5.1). Recomputes .
 
void protocore_smb2_sign_cmac (uint8_t *work, uint8_t *crypto_work, const uint8_t *key, uint8_t *msg, size_t msg_len)
 Sign an SMB2 message in place with AES-128-CMAC (MS-SMB2 §3.1.4.1, .
 
proto_bool protocore_smb2_verify_cmac (uint8_t *work, uint8_t *crypto_work, const uint8_t *key, uint8_t *msg, size_t msg_len)
 Verify an AES-128-CMAC-signed SMB2 message (MS-SMB2 §3.1.5.1, SMB .
 
proto_bool protocore_smb2_derive_signing_key (uint8_t *work, const uint8_t *session_key, uint16_t dialect, const uint8_t *preauth, uint8_t *out_key)
 Derive the 16-byte SMB 3.x signing key from the NTLM session key .
 
proto_bool protocore_smb2_derive_encryption_keys (uint8_t *work, const uint8_t *session_key, uint16_t dialect, const uint8_t *preauth, size_t key_len, uint8_t *out_c2s, uint8_t *out_s2c)
 Derive the two SMB 3.x cipher keys from the NTLM session key .
 
size_t protocore_smb2_encrypt (uint8_t *work, uint16_t cipher, const uint8_t *key, const uint8_t *nonce, uint64_t session_id, const uint8_t *msg, size_t msg_len, uint8_t *out, size_t out_cap)
 Encrypt one SMB2 message into a TRANSFORM_HEADER-wrapped blob .
 
size_t protocore_smb2_decrypt (uint8_t *work, uint16_t cipher, const uint8_t *key, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_cap)
 Decrypt a TRANSFORM_HEADER-wrapped SMB2 message (MS-SMB2 §3.1.4.4): .
 

Variables

PROTOCORE_NS Smb2Ns Smb2 PROTOCORE_UNUSED
 Module namespace.
 

Detailed Description

SMB2 client wire codec (MS-SMB2), PROTOCORE_ENABLE_SMB - increment 1: the transport frame, the 64-byte sync packet header, and the NEGOTIATE exchange.

Windows-share program storage is a common CNC file path (Fanuc / Haas / Mazak / Heidenhain expose one), so a device can read/write .nc files over SMB2. This is the pure wire layer: build the little-endian SMB2 messages and parse the responses; the TCP socket is the application's. All fields are little-endian (SMB2 is a little-endian protocol).

A client speaks SMB2 over Direct TCP (port 445): each message is prefixed by a 4-byte transport header (0x00 + a 24-bit big-endian length), then the 64-byte SMB2 sync header (MS-SMB2 §2.2.1.2), then the per-command body. The exchange begins with NEGOTIATE (§2.2.3 request / §2.2.4 response): the client offers a dialect list, the server picks one and returns the SPNEGO security token that seeds authentication.

Shipped: the NEGOTIATE exchange; the NTLM crypto (smb_md / ntlm / ntlmssp); the SPNEGO wrapping (spnego); the SESSION_SETUP request/response framing that carries those tokens; and the TREE_CONNECT / CREATE / CLOSE / READ / WRITE file commands - the full read/write-a-file-on-a-share client; SMB 2.x message signing (protocore_smb2_sign / protocore_smb2_verify, HMAC-SHA256) wired into the client's SigningRequired path; and the SMB 3.1.1 negotiate-context codec (protocore_smb2_build_negotiate_311 / protocore_smb2_parse_negotiate_contexts - preauth-integrity SHA-512, signing, and encryption capabilities); and the SP800-108 counter-mode KDF (protocore_kdf_ctr_hmac_sha256 in src/crypto/kdf, NIST-CAVP-verified) that SMB 3.x uses to derive its keys. SMB 3.1.1 runs end to end: the client offers 2.0.2 .. 3.1.1, chains the preauth-integrity hash (protocore_smb_preauth_*) across NEGOTIATE + both SESSION_SETUP rounds, derives the signing key (derive_signing_key), and signs the session with AES-128-CMAC (protocore_smb2_sign_cmac / _verify_cmac; crypto/aes_cmac) - the KDF assembly + CMAC cross-checked byte-for-byte against impacket.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file smb2.h.

Macro Definition Documentation

◆ PROTOCORE_SMB2_HEADER_SIZE

#define PROTOCORE_SMB2_HEADER_SIZE   64

Fixed SMB2 sync header size (MS-SMB2 §2.2.1).

Definition at line 52 of file smb2.h.

◆ SMB2_NEGOTIATE_SIGNING_ENABLED

#define SMB2_NEGOTIATE_SIGNING_ENABLED   0x0001

NEGOTIATE / SESSION_SETUP SecurityMode flags (MS-SMB2 §2.2.3).

Definition at line 55 of file smb2.h.

◆ SMB2_NEGOTIATE_SIGNING_REQUIRED

#define SMB2_NEGOTIATE_SIGNING_REQUIRED   0x0002

Definition at line 56 of file smb2.h.

◆ SMB2_FLAGS_SERVER_TO_REDIR

#define SMB2_FLAGS_SERVER_TO_REDIR   0x00000001

SMB2 header Flags field (MS-SMB2 §2.2.1.2).

set on a response (server -> client)

Definition at line 59 of file smb2.h.

◆ SMB2_FLAGS_SIGNED

#define SMB2_FLAGS_SIGNED   0x00000008

the message carries an HMAC signature

Definition at line 60 of file smb2.h.

◆ SMB2_SESSION_FLAG_IS_GUEST

#define SMB2_SESSION_FLAG_IS_GUEST   0x0001

SESSION_SETUP response SessionFlags (MS-SMB2 §2.2.6).

Definition at line 63 of file smb2.h.

◆ SMB2_SESSION_FLAG_IS_NULL

#define SMB2_SESSION_FLAG_IS_NULL   0x0002

Definition at line 64 of file smb2.h.

◆ SMB2_SESSION_FLAG_ENCRYPT_DATA

#define SMB2_SESSION_FLAG_ENCRYPT_DATA   0x0004

Definition at line 65 of file smb2.h.

◆ SMB2_STATUS_SUCCESS

#define SMB2_STATUS_SUCCESS   0x00000000

NT status values seen in the SMB2 header during the SESSION_SETUP exchange.

Definition at line 68 of file smb2.h.

◆ SMB2_STATUS_MORE_PROCESSING_REQUIRED

#define SMB2_STATUS_MORE_PROCESSING_REQUIRED   0xC0000016

server wants the next round

Definition at line 69 of file smb2.h.

◆ SMB2_STATUS_END_OF_FILE

#define SMB2_STATUS_END_OF_FILE   0xC0000011

a READ at/past end of file

Definition at line 70 of file smb2.h.

◆ SMB2_SHARE_TYPE_DISK

#define SMB2_SHARE_TYPE_DISK   0x01

TREE_CONNECT response ShareType (MS-SMB2 §2.2.10).

Definition at line 73 of file smb2.h.

◆ SMB2_SHARE_TYPE_PIPE

#define SMB2_SHARE_TYPE_PIPE   0x02

Definition at line 74 of file smb2.h.

◆ SMB2_SHARE_TYPE_PRINT

#define SMB2_SHARE_TYPE_PRINT   0x03

Definition at line 75 of file smb2.h.

◆ SMB2_FILE_READ_DATA

#define SMB2_FILE_READ_DATA   0x00000001

CREATE DesiredAccess masks (MS-DTYP ACCESS_MASK; the common file rights).

Definition at line 78 of file smb2.h.

◆ SMB2_FILE_WRITE_DATA

#define SMB2_FILE_WRITE_DATA   0x00000002

Definition at line 79 of file smb2.h.

◆ SMB2_FILE_APPEND_DATA

#define SMB2_FILE_APPEND_DATA   0x00000004

Definition at line 80 of file smb2.h.

◆ SMB2_FILE_READ_ATTRIBUTES

#define SMB2_FILE_READ_ATTRIBUTES   0x00000080

Definition at line 81 of file smb2.h.

◆ SMB2_FILE_GENERIC_READ

#define SMB2_FILE_GENERIC_READ   0x00120089

RC|SYNC|READ_ATTR|READ_EA|READ_DATA.

Definition at line 82 of file smb2.h.

◆ SMB2_FILE_GENERIC_WRITE

#define SMB2_FILE_GENERIC_WRITE   0x00120116

RC|SYNC|WRITE_ATTR|WRITE_EA|APPEND|WRITE.

Definition at line 83 of file smb2.h.

◆ SMB2_FILE_SHARE_READ

#define SMB2_FILE_SHARE_READ   0x01

CREATE ShareAccess (MS-SMB2 §2.2.13).

Definition at line 86 of file smb2.h.

◆ SMB2_FILE_SHARE_WRITE

#define SMB2_FILE_SHARE_WRITE   0x02

Definition at line 87 of file smb2.h.

◆ SMB2_FILE_SHARE_DELETE

#define SMB2_FILE_SHARE_DELETE   0x04

Definition at line 88 of file smb2.h.

◆ SMB2_FILE_SUPERSEDE

#define SMB2_FILE_SUPERSEDE   0

CREATE CreateDisposition (MS-SMB2 §2.2.13).

Definition at line 91 of file smb2.h.

◆ SMB2_FILE_OPEN

#define SMB2_FILE_OPEN   1

open an existing file, fail if absent

Definition at line 92 of file smb2.h.

◆ SMB2_FILE_CREATE

#define SMB2_FILE_CREATE   2

create, fail if it exists

Definition at line 93 of file smb2.h.

◆ SMB2_FILE_OPEN_IF

#define SMB2_FILE_OPEN_IF   3

open, create if absent

Definition at line 94 of file smb2.h.

◆ SMB2_FILE_OVERWRITE

#define SMB2_FILE_OVERWRITE   4

open + truncate, fail if absent

Definition at line 95 of file smb2.h.

◆ SMB2_FILE_OVERWRITE_IF

#define SMB2_FILE_OVERWRITE_IF   5

Definition at line 96 of file smb2.h.

◆ SMB2_FILE_DIRECTORY_FILE

#define SMB2_FILE_DIRECTORY_FILE   0x00000001

CREATE CreateOptions (MS-SMB2 §2.2.13; the two we set).

Definition at line 99 of file smb2.h.

◆ SMB2_FILE_NON_DIRECTORY_FILE

#define SMB2_FILE_NON_DIRECTORY_FILE   0x00000040

Definition at line 100 of file smb2.h.

◆ SMB2_PREAUTH_INTEGRITY_CAPABILITIES

#define SMB2_PREAUTH_INTEGRITY_CAPABILITIES   0x0001

SMB 3.1.1 negotiate-context types (MS-SMB2 §2.2.3.1).

Definition at line 103 of file smb2.h.

◆ SMB2_ENCRYPTION_CAPABILITIES

#define SMB2_ENCRYPTION_CAPABILITIES   0x0002

Definition at line 104 of file smb2.h.

◆ SMB2_COMPRESSION_CAPABILITIES

#define SMB2_COMPRESSION_CAPABILITIES   0x0003

Definition at line 105 of file smb2.h.

◆ SMB2_NETNAME_NEGOTIATE_CONTEXT_ID

#define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID   0x0005

Definition at line 106 of file smb2.h.

◆ SMB2_TRANSPORT_CAPABILITIES

#define SMB2_TRANSPORT_CAPABILITIES   0x0006

Definition at line 107 of file smb2.h.

◆ SMB2_RDMA_TRANSFORM_CAPABILITIES

#define SMB2_RDMA_TRANSFORM_CAPABILITIES   0x0007

Definition at line 108 of file smb2.h.

◆ SMB2_SIGNING_CAPABILITIES

#define SMB2_SIGNING_CAPABILITIES   0x0008

Definition at line 109 of file smb2.h.

◆ SMB2_PREAUTH_INTEGRITY_SHA512

#define SMB2_PREAUTH_INTEGRITY_SHA512   0x0001

Preauth-integrity hash algorithm IDs (MS-SMB2 §2.2.3.1.1).

Definition at line 112 of file smb2.h.

◆ SMB2_SIGNING_HMAC_SHA256

#define SMB2_SIGNING_HMAC_SHA256   0x0000

Signing algorithm IDs (MS-SMB2 §2.2.3.1.7).

Definition at line 115 of file smb2.h.

◆ SMB2_SIGNING_AES_CMAC

#define SMB2_SIGNING_AES_CMAC   0x0001

Definition at line 116 of file smb2.h.

◆ SMB2_SIGNING_AES_GMAC

#define SMB2_SIGNING_AES_GMAC   0x0002

Definition at line 117 of file smb2.h.

◆ SMB2_GLOBAL_CAP_ENCRYPTION

#define SMB2_GLOBAL_CAP_ENCRYPTION   0x00000040

NEGOTIATE request/response Capabilities flags (MS-SMB2 §2.2.3 / §2.2.4). A client that supports transport encryption MUST advertise SMB2_GLOBAL_CAP_ENCRYPTION here, or a server (e.g. Samba with smb encrypt = required) will not negotiate a cipher and will reject the unencrypted session (§3.2.4.2.2).

Definition at line 122 of file smb2.h.

◆ SMB2_ENCRYPTION_AES128_CCM

#define SMB2_ENCRYPTION_AES128_CCM   0x0001

Encryption cipher IDs (MS-SMB2 §2.2.3.1.2).

Definition at line 125 of file smb2.h.

◆ SMB2_ENCRYPTION_AES128_GCM

#define SMB2_ENCRYPTION_AES128_GCM   0x0002

Definition at line 126 of file smb2.h.

◆ SMB2_ENCRYPTION_AES256_CCM

#define SMB2_ENCRYPTION_AES256_CCM   0x0003

Definition at line 127 of file smb2.h.

◆ SMB2_ENCRYPTION_AES256_GCM

#define SMB2_ENCRYPTION_AES256_GCM   0x0004

Definition at line 128 of file smb2.h.

◆ PROTOCORE_SMB2_MAX_OFFER_CIPHERS

#define PROTOCORE_SMB2_MAX_OFFER_CIPHERS   4

Max encryption ciphers a NEGOTIATE request can advertise (the four SMB 3.1.1 ciphers).

Definition at line 131 of file smb2.h.

◆ PROTOCORE_SMB2_PREAUTH_HASH_LEN

#define PROTOCORE_SMB2_PREAUTH_HASH_LEN   64

Length of the SMB 3.1.1 preauth-integrity hash (SHA-512 digest size).

Definition at line 134 of file smb2.h.

◆ SMB2_SHAREFLAG_ENCRYPT_DATA

#define SMB2_SHAREFLAG_ENCRYPT_DATA   0x00008000

TREE_CONNECT response ShareFlags of interest (MS-SMB2 §2.2.10).

the share mandates SMB3 encryption

Definition at line 137 of file smb2.h.

◆ PROTOCORE_SMB2_TRANSFORM_HDR_LEN

#define PROTOCORE_SMB2_TRANSFORM_HDR_LEN   52

TRANSFORM_HEADER size: ProtocolId(4)+Signature(16)+Nonce(16)+OriginalMessageSize(4)+Reserved(2)+ Flags(2)+SessionId(8) = 52 bytes (MS-SMB2 §2.2.41).

Definition at line 141 of file smb2.h.

◆ PROTOCORE_SMB2_TRANSFORM_PROTOCOL_ID

#define PROTOCORE_SMB2_TRANSFORM_PROTOCOL_ID   0x424D53FDu

TRANSFORM_HEADER ProtocolId 0xFD 'S' 'M' 'B' as a little-endian u32.

Definition at line 144 of file smb2.h.

◆ PROTOCORE_SMB2_NONCE_FIELD_LEN

#define PROTOCORE_SMB2_NONCE_FIELD_LEN   16

The TRANSFORM_HEADER Nonce field width (MS-SMB2 §2.2.41). The AEAD uses the leading protocore_smb2_cipher_nonce_len() bytes; the rest are zero.

Definition at line 148 of file smb2.h.

◆ PROTOCORE_SMB2_GCM_NONCE_LEN

#define PROTOCORE_SMB2_GCM_NONCE_LEN   12

AES-GCM nonce length used within the 16-byte Nonce field.

Definition at line 151 of file smb2.h.

◆ PROTOCORE_SMB2_CCM_NONCE_LEN

#define PROTOCORE_SMB2_CCM_NONCE_LEN   11

AES-CCM nonce length used within the 16-byte Nonce field (MS-SMB2 §3.1.4.3).

Definition at line 154 of file smb2.h.

◆ PROTOCORE_SMB2_MAX_CIPHER_KEY_LEN

#define PROTOCORE_SMB2_MAX_CIPHER_KEY_LEN   32

Largest cipher key length across the four SMB 3.1.1 ciphers (AES-256), for buffer sizing.

Definition at line 157 of file smb2.h.

Typedef Documentation

◆ Smb2Command

SMB2 command codes (MS-SMB2 §2.2.1.2).

◆ Smb2Dialect

SMB2 dialect revision numbers (MS-SMB2 §2.2.4).

◆ Smb2SignAlgo

The per-session message-signing algorithm the client selects from the negotiated dialect.

Enumeration Type Documentation

◆ PROTO_ENUM_PACKED [1/3]

SMB2 command codes (MS-SMB2 §2.2.1.2).

Enumerator
SMB2_NEGOTIATE 
SMB2_SESSION_SETUP 
SMB2_LOGOFF 
SMB2_TREE_CONNECT 
SMB2_TREE_DISCONNECT 
SMB2_CREATE 
SMB2_CLOSE 
SMB2_READ 
SMB2_WRITE 
SMB2_DIALECT_0202 

SMB 2.0.2.

SMB2_DIALECT_0210 

SMB 2.1.

SMB2_DIALECT_0300 

SMB 3.0.

SMB2_DIALECT_0302 

SMB 3.0.2.

SMB2_DIALECT_0311 

SMB 3.1.1.

SMB2_SIGN_ALGO_HMAC_SHA256 

SMB 2.0.2 / 2.1 (key = the NTLMv2 session key)

SMB2_SIGN_ALGO_AES_CMAC 

SMB 3.0 / 3.0.2 / 3.1.1 (key = the SP800-108-derived signing key)

Definition at line 160 of file smb2.h.

◆ PROTO_ENUM_PACKED [2/3]

SMB2 dialect revision numbers (MS-SMB2 §2.2.4).

Enumerator
SMB2_NEGOTIATE 
SMB2_SESSION_SETUP 
SMB2_LOGOFF 
SMB2_TREE_CONNECT 
SMB2_TREE_DISCONNECT 
SMB2_CREATE 
SMB2_CLOSE 
SMB2_READ 
SMB2_WRITE 
SMB2_DIALECT_0202 

SMB 2.0.2.

SMB2_DIALECT_0210 

SMB 2.1.

SMB2_DIALECT_0300 

SMB 3.0.

SMB2_DIALECT_0302 

SMB 3.0.2.

SMB2_DIALECT_0311 

SMB 3.1.1.

SMB2_SIGN_ALGO_HMAC_SHA256 

SMB 2.0.2 / 2.1 (key = the NTLMv2 session key)

SMB2_SIGN_ALGO_AES_CMAC 

SMB 3.0 / 3.0.2 / 3.1.1 (key = the SP800-108-derived signing key)

Definition at line 174 of file smb2.h.

◆ PROTO_ENUM_PACKED [3/3]

The per-session message-signing algorithm the client selects from the negotiated dialect.

Enumerator
SMB2_NEGOTIATE 
SMB2_SESSION_SETUP 
SMB2_LOGOFF 
SMB2_TREE_CONNECT 
SMB2_TREE_DISCONNECT 
SMB2_CREATE 
SMB2_CLOSE 
SMB2_READ 
SMB2_WRITE 
SMB2_DIALECT_0202 

SMB 2.0.2.

SMB2_DIALECT_0210 

SMB 2.1.

SMB2_DIALECT_0300 

SMB 3.0.

SMB2_DIALECT_0302 

SMB 3.0.2.

SMB2_DIALECT_0311 

SMB 3.1.1.

SMB2_SIGN_ALGO_HMAC_SHA256 

SMB 2.0.2 / 2.1 (key = the NTLMv2 session key)

SMB2_SIGN_ALGO_AES_CMAC 

SMB 3.0 / 3.0.2 / 3.1.1 (key = the SP800-108-derived signing key)

Definition at line 279 of file smb2.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( Smb2Ns  ,
transport_frame  ,
transport_len  ,
build_header  ,
parse_header  ,
build_negotiate  ,
parse_negotiate_response  ,
build_negotiate_311  ,
parse_negotiate_contexts  ,
preauth_init  ,
preauth_update  ,
build_session_setup  ,
parse_session_setup_response  ,
build_tree_connect  ,
parse_tree_connect_response  ,
build_create  ,
parse_create_response  ,
build_close  ,
parse_close_response  ,
build_read  ,
parse_read_response  ,
build_write  ,
parse_write_response  ,
sign  ,
verify  ,
sign_cmac  ,
verify_cmac  ,
derive_signing_key  ,
derive_encryption_keys  ,
encrypt  ,
decrypt   
)

◆ protocore_smb2_transport_frame()

size_t protocore_smb2_transport_frame ( uint8_t *  work,
uint8_t *  out,
size_t  cap,
const uint8_t *  msg,
size_t  msg_len 
)

Prefix an SMB2 message with the 4-byte Direct-TCP transport header .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
outOut
capCap
msgMsg
msg_lenMsg len
Returns
The size_t.

◆ protocore_smb2_transport_len()

uint32_t protocore_smb2_transport_len ( uint8_t *  work,
const uint8_t *  buf,
size_t  len 
)

Read the Direct-TCP transport length prefix.

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
lenLen
Returns
The uint32_t.

◆ protocore_smb2_build_header()

size_t protocore_smb2_build_header ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
Smb2Command  command,
uint16_t  credit_request,
uint64_t  message_id,
uint32_t  tree_id,
uint64_t  session_id 
)

Build a 64-byte SMB2 sync header into buf.

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
commandCommand
credit_requestCredit request
message_idMessage id
tree_idTree id
session_idSession id
Returns
The size_t.

◆ protocore_smb2_parse_header()

proto_bool protocore_smb2_parse_header ( uint8_t *  work,
const uint8_t *  buf,
size_t  len,
Smb2Header *  out 
)

Parse a 64-byte SMB2 sync header (validates ProtocolId + .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_build_negotiate()

size_t protocore_smb2_build_negotiate ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
const uint8_t *  client_guid,
uint16_t  security_mode 
)

Build a NEGOTIATE request (header + body) offering SMB 2.0.2 / 2.1 .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
client_guidthe 16-byte client GUID 16 bytes
security_modeSMB2_NEGOTIATE_SIGNING_ENABLED and/or _REQUIRED
Returns
The size_t.

◆ protocore_smb2_parse_negotiate_response()

proto_bool protocore_smb2_parse_negotiate_response ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2NegotiateResp *  out 
)

Parse a NEGOTIATE response message (the SMB2 header + §2.2.4 body).

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgthe SMB2 message (starting at the sync header, transport prefix already stripped)
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_build_negotiate_311()

size_t protocore_smb2_build_negotiate_311 ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
const uint8_t *  client_guid,
uint16_t  security_mode,
const uint8_t *  salt,
size_t  salt_len,
const uint16_t *  ciphers,
size_t  cipher_count 
)

Build an SMB 3.1.1 NEGOTIATE request: the dialect list SMB 2.0.2 .. .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
client_guid16 bytes
security_modeSecurity mode
saltthe preauth-integrity salt (a fresh random blob the client keeps for the hash chain)
salt_lensalt length in bytes (>= 1); a common choice is 32
cipherscipher ids to offer, most-preferred first (a server picks the first it supports, in this
cipher_countnumber of entries in ciphers (0 .. PROTOCORE_SMB2_MAX_OFFER_CIPHERS)
Returns
The size_t.

◆ protocore_smb2_parse_negotiate_contexts()

proto_bool protocore_smb2_parse_negotiate_contexts ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2NegotiateContexts *  out 
)

Walk the negotiate-context list of a 3.1.1 NEGOTIATE response .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgMsg
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_preauth_init()

void protocore_smb2_preauth_init ( uint8_t *  work,
SmbPreauth *  p 
)

Seed the preauth-integrity hash with 64 zero bytes (the initial .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
pP

◆ protocore_smb2_preauth_update()

void protocore_smb2_preauth_update ( uint8_t *  work,
uint8_t *  crypto_work,
SmbPreauth *  p,
const uint8_t *  msg,
size_t  len 
)

Fold one handshake message into the preauth-integrity hash: hash = .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
crypto_workCrypto work
pP
msgMsg
lenLen

◆ protocore_smb2_build_session_setup()

size_t protocore_smb2_build_session_setup ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
uint64_t  message_id,
uint64_t  session_id,
uint8_t  security_mode,
const uint8_t *  sec_buf,
size_t  sec_len 
)

Build a SESSION_SETUP request (header + §2.2.5 body) carrying a .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
message_idthe SMB2 MessageId (increments across the exchange)
session_id0 on the first round; the server-assigned SessionId on the second
security_modeSMB2_NEGOTIATE_SIGNING_ENABLED and/or _REQUIRED (one byte on the wire)
sec_bufSec buf
sec_lenSec len
Returns
The size_t.

◆ protocore_smb2_parse_session_setup_response()

proto_bool protocore_smb2_parse_session_setup_response ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2SessionSetupResp *  out 
)

Parse a SESSION_SETUP response message (the SMB2 header + §2.2.6 .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgthe SMB2 message (starting at the sync header, transport prefix already stripped)
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_build_tree_connect()

size_t protocore_smb2_build_tree_connect ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
uint64_t  message_id,
uint64_t  session_id,
const uint8_t *  path_utf16,
size_t  path_len 
)

Build a TREE_CONNECT request (header + §2.2.9 body) for a share path.

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
message_idMessage id
session_idSession id
path_utf16the UNC path \\server\share in UTF-16LE (no NUL); path_len its byte length
path_lenPath len
Returns
The size_t.

◆ protocore_smb2_parse_tree_connect_response()

proto_bool protocore_smb2_parse_tree_connect_response ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2TreeConnectResp *  out 
)

Parse a TREE_CONNECT response message (validates command + .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgMsg
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_build_create()

size_t protocore_smb2_build_create ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
uint64_t  message_id,
uint64_t  session_id,
uint32_t  tree_id,
uint32_t  desired_access,
uint32_t  share_access,
uint32_t  create_disposition,
uint32_t  create_options,
const uint8_t *  name_utf16,
size_t  name_len 
)

Build a CREATE request (header + §2.2.13 body) to open/create a .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
message_idMessage id
session_idSession id
tree_idTree id
desired_accesse.g. SMB2_FILE_GENERIC_READ / _WRITE
share_accessSMB2_FILE_SHARE_* bitmask
create_dispositionSMB2_FILE_OPEN / _CREATE / _OPEN_IF /
create_optionsSMB2_FILE_NON_DIRECTORY_FILE for a regular file
name_utf16the file name relative to the share root in UTF-16LE (no leading backslash, no NUL);
name_lenName len
Returns
The size_t.

◆ protocore_smb2_parse_create_response()

proto_bool protocore_smb2_parse_create_response ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2CreateResp *  out 
)

Parse a CREATE response message (validates command + StructureSize .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgMsg
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_build_close()

size_t protocore_smb2_build_close ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
uint64_t  message_id,
uint64_t  session_id,
uint32_t  tree_id,
const uint8_t *  file_id 
)

Build a CLOSE request (header + §2.2.15 body) for an open FileId.

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
message_idMessage id
session_idSession id
tree_idTree id
file_id16 bytes
Returns
The size_t.

◆ protocore_smb2_parse_close_response()

proto_bool protocore_smb2_parse_close_response ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2CloseResp *  out 
)

Parse a CLOSE response message (validates command + StructureSize .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgMsg
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_build_read()

size_t protocore_smb2_build_read ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
uint64_t  message_id,
uint64_t  session_id,
uint32_t  tree_id,
const uint8_t *  file_id,
uint32_t  length,
uint64_t  offset 
)

Build a READ request (header + §2.2.19 body) for length bytes at .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
message_idMessage id
session_idSession id
tree_idTree id
file_id16 bytes
lengthLength
offsetOffset
Returns
The size_t.

◆ protocore_smb2_parse_read_response()

proto_bool protocore_smb2_parse_read_response ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2ReadResp *  out 
)

Parse a READ response message (validates command + StructureSize .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgMsg
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_build_write()

size_t protocore_smb2_build_write ( uint8_t *  work,
uint8_t *  buf,
size_t  cap,
uint64_t  message_id,
uint64_t  session_id,
uint32_t  tree_id,
const uint8_t *  file_id,
const uint8_t *  data,
size_t  data_len,
uint64_t  offset 
)

Build a WRITE request (header + §2.2.21 body) writing data at .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
message_idMessage id
session_idSession id
tree_idTree id
file_id16 bytes
dataData
data_lenData len
offsetOffset
Returns
The size_t.

◆ protocore_smb2_parse_write_response()

proto_bool protocore_smb2_parse_write_response ( uint8_t *  work,
const uint8_t *  msg,
size_t  len,
Smb2WriteResp *  out 
)

Parse a WRITE response message (validates command + StructureSize .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
msgMsg
lenLen
outOut
Returns
PROTO_TRUE on success.

◆ protocore_smb2_sign()

void protocore_smb2_sign ( uint8_t *  work,
uint8_t *  crypto_work,
const uint8_t *  key,
uint8_t *  msg,
size_t  msg_len 
)

Sign an SMB2 message in place (MS-SMB2 §3.1.4.1, SMB 2.x). Sets .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
crypto_workCrypto work
keythe session signing key (16 octets; the NTLMv2 session key for SMB 2.x) 16 bytes
msgthe full message (header + body), modified in place; must be at least a 64-byte header
msg_lentotal message length. A message shorter than the header is left untouched

◆ protocore_smb2_verify()

proto_bool protocore_smb2_verify ( uint8_t *  work,
uint8_t *  crypto_work,
const uint8_t *  key,
uint8_t *  msg,
size_t  msg_len 
)

Verify an SMB2 message's signature (MS-SMB2 §3.1.5.1). Recomputes .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
crypto_workCrypto work
key16 bytes
msgMsg
msg_lenMsg len
Returns
PROTO_TRUE on success.

◆ protocore_smb2_sign_cmac()

void protocore_smb2_sign_cmac ( uint8_t *  work,
uint8_t *  crypto_work,
const uint8_t *  key,
uint8_t *  msg,
size_t  msg_len 
)

Sign an SMB2 message in place with AES-128-CMAC (MS-SMB2 §3.1.4.1, .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
crypto_workCrypto work
key16 bytes
msgMsg
msg_lenMsg len

◆ protocore_smb2_verify_cmac()

proto_bool protocore_smb2_verify_cmac ( uint8_t *  work,
uint8_t *  crypto_work,
const uint8_t *  key,
uint8_t *  msg,
size_t  msg_len 
)

Verify an AES-128-CMAC-signed SMB2 message (MS-SMB2 §3.1.5.1, SMB .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
crypto_workCrypto work
key16 bytes
msgMsg
msg_lenMsg len
Returns
PROTO_TRUE on success.

◆ protocore_smb2_derive_signing_key()

proto_bool protocore_smb2_derive_signing_key ( uint8_t *  work,
const uint8_t *  session_key,
uint16_t  dialect,
const uint8_t *  preauth,
uint8_t *  out_key 
)

Derive the 16-byte SMB 3.x signing key from the NTLM session key .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
session_keythe 16-byte NTLM ExportedSessionKey (SessionBaseKey for NTLMv2 with no key exch) 16 bytes
dialectthe negotiated DialectRevision (only 3.1.1 vs pre-3.1.1 matters here)
preauththe 64-byte final preauth-integrity hash; required iff dialect == 3.1.1, else ignored
out_keyreceives the 16-byte signing key 16 bytes
Returns
PROTO_TRUE on success.

◆ protocore_smb2_derive_encryption_keys()

proto_bool protocore_smb2_derive_encryption_keys ( uint8_t *  work,
const uint8_t *  session_key,
uint16_t  dialect,
const uint8_t *  preauth,
size_t  key_len,
uint8_t *  out_c2s,
uint8_t *  out_s2c 
)

Derive the two SMB 3.x cipher keys from the NTLM session key .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
session_key16 bytes
dialectDialect
preauthPreauth
key_lenKey len
out_c2sclient->server key (ENCRYPTS our requests); out_s2c server->client key (DECRYPTS
out_s2cOut s2c
Returns
PROTO_TRUE on success.

◆ protocore_smb2_encrypt()

size_t protocore_smb2_encrypt ( uint8_t *  work,
uint16_t  cipher,
const uint8_t *  key,
const uint8_t *  nonce,
uint64_t  session_id,
const uint8_t *  msg,
size_t  msg_len,
uint8_t *  out,
size_t  out_cap 
)

Encrypt one SMB2 message into a TRANSFORM_HEADER-wrapped blob .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
cipherone of Smb2Cipher; selects the key length and AEAD nonce length
keycipher key (protocore_smb2_cipher_key_len(cipher) bytes, i.e. the C2S key)
noncethe 16-byte Nonce field; the leading nonce-length bytes must be UNIQUE per key (caller
session_idechoed into the header; out needs >= PROTOCORE_SMB2_TRANSFORM_HDR_LEN + msg_len
msgMsg
msg_lenMsg len
outOut
out_capOut cap
Returns
The size_t.

◆ protocore_smb2_decrypt()

size_t protocore_smb2_decrypt ( uint8_t *  work,
uint16_t  cipher,
const uint8_t *  key,
const uint8_t *  in,
size_t  in_len,
uint8_t *  out,
size_t  out_cap 
)

Decrypt a TRANSFORM_HEADER-wrapped SMB2 message (MS-SMB2 §3.1.4.4): .

Parameters
workPROTOCORE_SMB2_BORROW bytes the caller took. Not held past the call.
cipherone of Smb2Cipher; key the S2C cipher key; out needs >= OriginalMessageSize
keyKey
inIn
in_lenIn len
outOut
out_capOut cap
Returns
The size_t.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS Smb2Ns Smb2 PROTOCORE_UNUSED

Module namespace.

Definition at line 713 of file smb2.h.