mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-03-04 20:48:18 +01:00
akwizgran created page: BSP
28
BSP.markdown
28
BSP.markdown
@@ -12,19 +12,19 @@ We use || to denote concatenation, double quotes to denote an ASCII string, int(
|
||||
|
||||
BSP uses a cryptographic hash function, H(m), with an output length of HASH_LEN bytes, and a random number generator, R(n), with an output length of n bytes. R(n) may be a true random number generator or a cryptographically secure pseudo-random number generator. We use H(m) to define a multi-argument hash function:
|
||||
|
||||
HASH(x_1, ..., x_n) == H(len(x_1) || x_1 || ... || len(x_n) || x_n)
|
||||
* `HASH(x_1, ..., x_n) == H(len(x_1) || x_1 || ... || len(x_n) || x_n)`
|
||||
|
||||
|
||||
### Channel identifiers
|
||||
|
||||
Each channel has a unique identifier HASH_LEN bytes long. This identifier is supplied by the application and is not interpreted by BSP. However, to prevent collisions between applications, BSP specifies how channel identifiers may be generated. The channel identifier may be random:
|
||||
|
||||
channel_id = R(HASH_LEN)
|
||||
* `channel_id = R(HASH_LEN)`
|
||||
|
||||
Alternatively, the channel identifier may be the hash of a random application identifier HASH_LEN bytes long and an application data structure describing the channel:
|
||||
|
||||
app_id = R(HASH_LEN)
|
||||
channel_id = HASH(app_id, app_data_structure)
|
||||
* `app_id = R(HASH_LEN)`
|
||||
* `channel_id = HASH(app_id, app_data_structure)`
|
||||
|
||||
Including the application identifier in the hash prevents collisions between applications with similar data structures.
|
||||
|
||||
@@ -32,26 +32,26 @@ Including the application identifier in the hash prevents collisions between app
|
||||
|
||||
Each message consists of one or more blocks. Each block is BLOCK_LEN bytes long, except the last block of the message, which may be shorter. (We require that BLOCK_LEN <= 2^15 .)
|
||||
|
||||
message = block_1 || ... || block_n
|
||||
* `message = block_1 || ... || block_n`
|
||||
|
||||
The blocks form the leaves of a binary hash tree. Each parent node consists of the concatenated hashes of its children. If the number of blocks in the message is not a power of two, some parent nodes will only have one child. The hash of the root node is called the root hash of the tree.
|
||||
The blocks form the leaves of a binary hash tree. Each parent node consists of the concatenated hashes of its children. If the number of blocks in the message is not a power of two, some parent nodes will only have one child. The hash of the root node is called the root hash.
|
||||
|
||||
block_hash = HASH("BLOCK", block)
|
||||
parent_node = only_child_hash
|
||||
parent_node = left_child_hash || right_child_hash
|
||||
parent_hash = HASH("TREE", parent_node)
|
||||
* `block_hash = HASH("BLOCK", block)`
|
||||
* `parent_node = only_child_hash`
|
||||
* `parent_node = left_child_hash || right_child_hash`
|
||||
* `parent_hash = HASH("TREE", parent_node)`
|
||||
|
||||
The message's unique identifier is calculated by hashing a message header and the root hash. The message header consists of the channel identifier, a timestamp, the message length and the message type.
|
||||
|
||||
message_header = channel_id || timestamp || message_length || message_type
|
||||
message_id = HASH(message_header, root_hash)
|
||||
* `message_header = channel_id || timestamp || message_length || message_type`
|
||||
* `message_id = HASH("MESSAGE_ID", message_header, root_hash)`
|
||||
|
||||
The timestamp is a 64-bit integer representing seconds since the Unix epoch. (All integers in BSP are big-endian.) The message length is a 64-bit integer representing the length of the message in bytes. The message type is a single byte that is supplied by the application and is not interpreted by BSP.
|
||||
|
||||
Each block has a unique identifier, which is calculated by hashing the message header, a block header and the hash of the block itself. The block header consists of the block number and a list of hashes called the path.
|
||||
|
||||
block_header = block_number || path_1 || ... || path_n
|
||||
block_id = HASH("BLOCK_ID", message_header, block_header, block_hash)
|
||||
* `block_header = block_number || path_1 || ... || path_n`
|
||||
* `block_id = HASH("BLOCK_ID", message_header, block_header, block_hash)`
|
||||
|
||||
The block number is a 64-bit integer starting from zero for the first block of the message. The path consists of the hashes of the siblings of the block's ancestors in the hash tree. If the number of blocks in the message is not a power of two, some of the block's ancestors may not have siblings. The positions of any such ancestors can be calculated from the message length and the block number.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user