mar_private.h (2929B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MAR_PRIVATE_H__ 8 #define MAR_PRIVATE_H__ 9 10 #include <assert.h> // for C11 static_assert 11 #include "limits.h" 12 #include <stdint.h> 13 14 #define BLOCKSIZE 4096 15 #define ROUND_UP(n, incr) (((n) / (incr) + 1) * (incr)) 16 17 #define MAR_ID "MAR1" 18 #define MAR_ID_SIZE 4 19 20 /* The signature block comes directly after the header block 21 which is 16 bytes */ 22 #define SIGNATURE_BLOCK_OFFSET 16 23 24 /* Make sure the file is less than 500MB. We do this to protect against 25 invalid MAR files. */ 26 #define MAX_SIZE_OF_MAR_FILE ((int64_t)524288000) 27 28 /* Existing code makes assumptions that the file size is 29 smaller than LONG_MAX. */ 30 static_assert(MAX_SIZE_OF_MAR_FILE < ((int64_t)LONG_MAX), 31 "max mar file size is too big"); 32 33 /* We store at most the size up to the signature block + 4 34 bytes per BLOCKSIZE bytes */ 35 static_assert(sizeof(BLOCKSIZE) < (SIGNATURE_BLOCK_OFFSET + sizeof(uint32_t)), 36 "BLOCKSIZE is too big"); 37 38 /* The maximum size of any signature supported by current and future 39 implementations of the signmar program. */ 40 #define MAX_SIGNATURE_LENGTH 2048 41 42 /* Each additional block has a unique ID. 43 The product information block has an ID of 1. */ 44 #define PRODUCT_INFO_BLOCK_ID 1 45 46 #define MAR_ITEM_SIZE(namelen) (3 * sizeof(uint32_t) + (namelen) + 1) 47 48 /* Product Information Block (PIB) constants */ 49 #define PIB_MAX_MAR_CHANNEL_ID_SIZE 63 50 #define PIB_MAX_PRODUCT_VERSION_SIZE 31 51 52 /* The mar program is compiled as a host bin so we don't have access to NSPR at 53 runtime. For that reason we use ntohl, htonl, and define HOST_TO_NETWORK64 54 instead of the NSPR equivalents. */ 55 #ifdef XP_WIN 56 # include <winsock2.h> 57 # ifdef __MINGW32__ 58 /* Include stdio.h before redefining ftello and fseeko to avoid clobbering 59 the ftello() and fseeko() function declarations in MinGW's stdio.h. */ 60 # include <stdio.h> 61 # endif 62 # define ftello _ftelli64 63 # define fseeko _fseeki64 64 #else 65 # define _FILE_OFFSET_BITS 64 66 # include <netinet/in.h> 67 # include <unistd.h> 68 #endif 69 70 #define HOST_TO_NETWORK64(x) \ 71 (((((uint64_t)x) & 0xFF) << 56) | ((((uint64_t)x) >> 8) & 0xFF) << 48) | \ 72 (((((uint64_t)x) >> 16) & 0xFF) << 40) | \ 73 (((((uint64_t)x) >> 24) & 0xFF) << 32) | \ 74 (((((uint64_t)x) >> 32) & 0xFF) << 24) | \ 75 (((((uint64_t)x) >> 40) & 0xFF) << 16) | \ 76 (((((uint64_t)x) >> 48) & 0xFF) << 8) | (((uint64_t)x) >> 56) 77 #define NETWORK_TO_HOST64 HOST_TO_NETWORK64 78 79 #endif /* MAR_PRIVATE_H__ */