modules/libmar/src/mar_private.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial