/* SPDX-License-Identifier: MIT */ /* * konpack.h * * Copyright (c) 2026 KonAki * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef KONPACK_H #define KONPACK_H #include #include #ifdef __cplusplus extern "C" { #endif /*** definition ***/ #define KON_PACK_KEY_SIZE 32 typedef struct kon_pack kon_pack_t; /* pass key as NULL for a pack that was made without one */ kon_pack_t *kon_packOpen(const char *path, const uint8_t *key); void kon_packClose(kon_pack_t *pack); int kon_packCount(const kon_pack_t *pack); const char *kon_packName(const kon_pack_t *pack, int index); uint32_t kon_packSize(const kon_pack_t *pack, int index); /* -1 if the name is not in the pack. names use / and are relative to the folder the pack was made from */ int kon_packFind(const kon_pack_t *pack, const char *name); /* returns a malloc'd copy of the file that you free, with one extra 0 byte after the end that is not counted in size. NULL if it fails, see kon_packError */ uint8_t *kon_packRead(kon_pack_t *pack, int index, size_t *size); const char *kon_packError(void); uint32_t kon_crc32(const uint8_t *data, size_t length); /* same call encrypts and decrypts, in and out can be the same buffer. nonce must never repeat for the same key */ void kon_chacha20Xor(const uint8_t key[KON_PACK_KEY_SIZE], const uint8_t nonce[12], uint32_t counter, const uint8_t *in, uint8_t *out, size_t length); #ifdef KONPACK_WRITER /* files are paths on disk, baseDir is cut off the front to make the names in the pack. key can be NULL for no encryption. returns 0 on success, otherwise see kon_packError */ int kon_packWrite(const char *outPath, const uint8_t *key, const char *baseDir, const char *const *files, int count); #endif #ifdef __cplusplus } #endif #endif