PQS: Post Quantum Shell Protocol 1.1.0.0a (A2)
A quantum secure secure shell protocol
pqsxfer.h
Go to the documentation of this file.
1/* 2025-2026 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE:
5 * This software and all accompanying materials are the exclusive property of
6 * Quantum Resistant Cryptographic Solutions Corporation (QRCS). The intellectual
7 * and technical concepts contained herein are proprietary to QRCS and are
8 * protected under applicable Canadian, U.S., and international copyright,
9 * patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC ALGORITHMS AND IMPLEMENTATIONS:
12 * - This software includes implementations of cryptographic primitives and
13 * algorithms that are standardized or in the public domain, such as AES
14 * and SHA-3, which are not proprietary to QRCS.
15 * - This software also includes cryptographic primitives, constructions, and
16 * algorithms designed by QRCS, including but not limited to RCS, SCB, CSX, QMAC, and
17 * related components, which are proprietary to QRCS.
18 * - All source code, implementations, protocol compositions, optimizations,
19 * parameter selections, and engineering work contained in this software are
20 * original works of QRCS and are protected under this license.
21 *
22 * LICENSE AND USE RESTRICTIONS:
23 * - This software is licensed under the Quantum Resistant Cryptographic Solutions
24 * Public Research and Evaluation License (QRCS-PREL), 2025-2026.
25 * - Permission is granted solely for non-commercial evaluation, academic research,
26 * cryptographic analysis, interoperability testing, and feasibility assessment.
27 * - Commercial use, production deployment, commercial redistribution, or
28 * integration into products or services is strictly prohibited without a
29 * separate written license agreement executed with QRCS.
30 * - Licensing and authorized distribution are solely at the discretion of QRCS.
31 *
32 * EXPERIMENTAL CRYPTOGRAPHY NOTICE:
33 * Portions of this software may include experimental, novel, or evolving
34 * cryptographic designs. Use of this software is entirely at the user's risk.
35 *
36 * DISCLAIMER:
37 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
39 * FOR A PARTICULAR PURPOSE, SECURITY, OR NON-INFRINGEMENT. QRCS DISCLAIMS ALL
40 * LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
41 * ARISING FROM THE USE OR MISUSE OF THIS SOFTWARE.
42 *
43 * FULL LICENSE:
44 * This software is subject to the Quantum Resistant Cryptographic Solutions
45 * Public Research and Evaluation License (QRCS-PREL), 2025-2026. The complete license terms
46 * are provided in the accompanying LICENSE file or at https://www.qrcscorp.ca.
47 *
48 * Written by: John G. Underhill
49 * Contact: contact@qrcscorp.ca
50 */
51
52#ifndef PQS_XFER_H
53#define PQS_XFER_H
54
55#include "pqscommon.h"
56#include <stdio.h>
57
62
73
84typedef bool (*pqs_xfer_walk_callback)(pqs_xfer_walk_events event, const char* localpath, const char* relative, void* context);
85
94PQS_EXPORT_API size_t pqs_xfer_payload_size(const uint8_t* message, size_t msglen);
95
99PQS_EXPORT_API void pqs_xfer_join_path(char* output, size_t outlen, const char* first, const char* second);
100
104PQS_EXPORT_API void pqs_xfer_join_remote(char* output, size_t outlen, const char* first, const char* second);
105
109PQS_EXPORT_API bool pqs_xfer_local_path_is_directory(const char* path);
110
114PQS_EXPORT_API bool pqs_xfer_create_parent_directories(const char* fpath);
115
119PQS_EXPORT_API bool pqs_xfer_make_local_recursive_path(char* output, size_t outlen, const char* root, const char* relative);
120
132PQS_EXPORT_API bool pqs_xfer_walk_directory(const char* localroot, const char* remoteroot, size_t maxdepth, pqs_xfer_walk_callback callback, void* context);
133
144PQS_EXPORT_API bool pqs_xfer_make_path(char* output, size_t outlen, const char* root, const char* relative);
145
156PQS_EXPORT_API bool pqs_xfer_extract_relative(char* output, size_t outlen, const uint8_t* message, size_t msglen);
157
167PQS_EXPORT_API bool pqs_xfer_path_is_confined(const char* root, const char* path, bool existing);
168
176PQS_EXPORT_API bool pqs_xfer_path_is_safe(const char* relative);
177
188PQS_EXPORT_API bool pqs_xfer_make_user_root(char* output, size_t outlen, const char* root, const char* username);
189
198PQS_EXPORT_API FILE* pqs_xfer_open_read_confined(const char* root, const char* relative);
199
208PQS_EXPORT_API FILE* pqs_xfer_open_write_confined(const char* root, const char* relative);
209
222PQS_EXPORT_API bool pqs_xfer_make_temporary_path(char* output, size_t outlen, const char* relative);
223
232PQS_EXPORT_API bool pqs_xfer_remove_confined(const char* root, const char* relative);
233
242PQS_EXPORT_API bool pqs_xfer_make_directory_confined(const char* root, const char* relative);
243
253PQS_EXPORT_API bool pqs_xfer_publish_temporary_file(const char* root, const char* temporary, const char* relative);
254
265PQS_EXPORT_API bool pqs_xfer_hash_file(const char* fpath, char* hexhash, size_t hexlen, size_t* filesize);
266
277PQS_EXPORT_API bool pqs_xfer_format_metadata(char* output, size_t outlen, size_t filesize, const char* hexhash);
278
289PQS_EXPORT_API bool pqs_xfer_parse_metadata(const char* metadata, size_t* filesize, char* hexhash, size_t hexlen);
290
291
303PQS_EXPORT_API bool pqs_xfer_format_file_metadata(char* output, size_t outlen, const char* relative, size_t filesize, const char* hexhash);
304
317PQS_EXPORT_API bool pqs_xfer_parse_file_metadata(const char* metadata, char* relative, size_t relen, size_t* filesize, char* hexhash, size_t hexlen);
318
326PQS_EXPORT_API bool pqs_xfer_path_is_symlink(const char* path);
327
328#endif
PQS_EXPORT_API bool pqs_xfer_parse_metadata(const char *metadata, size_t *filesize, char *hexhash, size_t hexlen)
Parse file-transfer metadata text.
Definition pqsxfer.c:1107
PQS_EXPORT_API bool pqs_xfer_walk_directory(const char *localroot, const char *remoteroot, size_t maxdepth, pqs_xfer_walk_callback callback, void *context)
Walk a local directory tree and report PQS transfer paths through a callback.
Definition pqsxfer.c:672
PQS_EXPORT_API bool pqs_xfer_format_file_metadata(char *output, size_t outlen, const char *relative, size_t filesize, const char *hexhash)
Format recursive file-transfer metadata text.
Definition pqsxfer.c:1141
PQS_EXPORT_API bool pqs_xfer_remove_confined(const char *root, const char *relative)
Remove a confined file inside the configured transfer root.
Definition pqsxfer.c:939
PQS_EXPORT_API size_t pqs_xfer_payload_size(const uint8_t *message, size_t msglen)
Return the plaintext payload length carried after the PQS application message header.
Definition pqsxfer.c:546
PQS_EXPORT_API bool pqs_xfer_publish_temporary_file(const char *root, const char *temporary, const char *relative)
Publish a staged temporary upload as its final confined file.
Definition pqsxfer.c:966
PQS_EXPORT_API bool pqs_xfer_make_local_recursive_path(char *output, size_t outlen, const char *root, const char *relative)
Build a local path for a recursive transfer member.
Definition pqsxfer.c:655
bool(* pqs_xfer_walk_callback)(pqs_xfer_walk_events event, const char *localpath, const char *relative, void *context)
File-transfer directory walk callback.
Definition pqsxfer.h:84
PQS_EXPORT_API bool pqs_xfer_local_path_is_directory(const char *path)
Test whether a local path is a directory.
Definition pqsxfer.c:594
PQS_EXPORT_API bool pqs_xfer_hash_file(const char *fpath, char *hexhash, size_t hexlen, size_t *filesize)
Compute the SHA3-256 hash of a local file.
Definition pqsxfer.c:1031
PQS_EXPORT_API void pqs_xfer_join_remote(char *output, size_t outlen, const char *first, const char *second)
Join two remote transfer path components using the PQS remote delimiter.
Definition pqsxfer.c:573
PQS_EXPORT_API bool pqs_xfer_path_is_symlink(const char *path)
Test whether a file-system path is a symbolic link or reparse point.
Definition pqsxfer.c:1208
PQS_EXPORT_API bool pqs_xfer_extract_relative(char *output, size_t outlen, const uint8_t *message, size_t msglen)
Extract a bounded relative path from a file-transfer application message.
Definition pqsxfer.c:700
PQS_EXPORT_API bool pqs_xfer_path_is_confined(const char *root, const char *path, bool existing)
Test whether a local path resolves inside the configured root.
Definition pqsxfer.c:725
PQS_EXPORT_API FILE * pqs_xfer_open_read_confined(const char *root, const char *relative)
Open a confined transfer file for binary reading.
Definition pqsxfer.c:1007
PQS_EXPORT_API bool pqs_xfer_path_is_safe(const char *relative)
Test whether a remote file-transfer path is safe.
Definition pqsxfer.c:691
PQS_EXPORT_API bool pqs_xfer_make_user_root(char *output, size_t outlen, const char *root, const char *username)
Build a per-user transfer root path.
Definition pqsxfer.c:852
PQS_EXPORT_API bool pqs_xfer_parse_file_metadata(const char *metadata, char *relative, size_t relen, size_t *filesize, char *hexhash, size_t hexlen)
Parse recursive file-transfer metadata text.
Definition pqsxfer.c:1160
PQS_EXPORT_API bool pqs_xfer_make_directory_confined(const char *root, const char *relative)
Create a confined directory inside the configured transfer root.
Definition pqsxfer.c:913
PQS_EXPORT_API FILE * pqs_xfer_open_write_confined(const char *root, const char *relative)
Open a confined transfer file for binary writing.
Definition pqsxfer.c:1019
PQS_EXPORT_API bool pqs_xfer_format_metadata(char *output, size_t outlen, size_t filesize, const char *hexhash)
Format file-transfer metadata text.
Definition pqsxfer.c:1088
PQS_EXPORT_API void pqs_xfer_join_path(char *output, size_t outlen, const char *first, const char *second)
Join two local file-system path components.
Definition pqsxfer.c:560
pqs_xfer_walk_events
File-transfer directory walk event types.
Definition pqsxfer.h:68
@ pqs_xfer_walk_event_directory_end
Definition pqsxfer.h:71
@ pqs_xfer_walk_event_file
Definition pqsxfer.h:70
@ pqs_xfer_walk_event_directory_begin
Definition pqsxfer.h:69
PQS_EXPORT_API bool pqs_xfer_make_temporary_path(char *output, size_t outlen, const char *relative)
Build a confined temporary upload path from a relative target path.
Definition pqsxfer.c:886
PQS_EXPORT_API bool pqs_xfer_create_parent_directories(const char *fpath)
Create all parent directories for a local output path.
Definition pqsxfer.c:619
PQS_EXPORT_API bool pqs_xfer_make_path(char *output, size_t outlen, const char *root, const char *relative)
Build a confined absolute path from a transfer root and a relative remote path.
Definition pqsxfer.c:821