1 | """ |
---|
2 | Define input parameters for test vector generation. |
---|
3 | |
---|
4 | :ivar CONVERGENCE_SECRETS: Convergence secrets. |
---|
5 | |
---|
6 | :ivar SEGMENT_SIZE: The single segment size that the Python implementation |
---|
7 | currently supports without a lot of refactoring. |
---|
8 | |
---|
9 | :ivar OBJECT_DESCRIPTIONS: Small objects with instructions which can be |
---|
10 | expanded into a possibly large byte string. These are intended to be used |
---|
11 | as plaintext inputs. |
---|
12 | |
---|
13 | :ivar ZFEC_PARAMS: Input parameters to ZFEC. |
---|
14 | |
---|
15 | :ivar FORMATS: Encoding/encryption formats. |
---|
16 | """ |
---|
17 | |
---|
18 | from __future__ import annotations |
---|
19 | |
---|
20 | from hashlib import sha256 |
---|
21 | |
---|
22 | from .model import MAX_SHARES |
---|
23 | from .vectors import Sample, SeedParam |
---|
24 | from ..util import CHK, SSK |
---|
25 | |
---|
26 | def digest(bs: bytes) -> bytes: |
---|
27 | """ |
---|
28 | Digest bytes to bytes. |
---|
29 | """ |
---|
30 | return sha256(bs).digest() |
---|
31 | |
---|
32 | |
---|
33 | def hexdigest(bs: bytes) -> str: |
---|
34 | """ |
---|
35 | Digest bytes to text. |
---|
36 | """ |
---|
37 | return sha256(bs).hexdigest() |
---|
38 | |
---|
39 | # Just a couple convergence secrets. The only thing we do with this value is |
---|
40 | # feed it into a tagged hash. It certainly makes a difference to the output |
---|
41 | # but the hash should destroy any structure in the input so it doesn't seem |
---|
42 | # like there's a reason to test a lot of different values. |
---|
43 | CONVERGENCE_SECRETS: list[bytes] = [ |
---|
44 | b"aaaaaaaaaaaaaaaa", |
---|
45 | digest(b"Hello world")[:16], |
---|
46 | ] |
---|
47 | |
---|
48 | SEGMENT_SIZE: int = 128 * 1024 |
---|
49 | |
---|
50 | # Exercise at least a handful of different sizes, trying to cover: |
---|
51 | # |
---|
52 | # 1. Some cases smaller than one "segment" (128k). |
---|
53 | # This covers shrinking of some parameters to match data size. |
---|
54 | # This includes one case of the smallest possible CHK. |
---|
55 | # |
---|
56 | # 2. Some cases right on the edges of integer segment multiples. |
---|
57 | # Because boundaries are tricky. |
---|
58 | # |
---|
59 | # 4. Some cases that involve quite a few segments. |
---|
60 | # This exercises merkle tree construction more thoroughly. |
---|
61 | # |
---|
62 | # See ``stretch`` for construction of the actual test data. |
---|
63 | OBJECT_DESCRIPTIONS: list[Sample] = [ |
---|
64 | # The smallest possible. 55 bytes and smaller are LIT. |
---|
65 | Sample(b"a", 56), |
---|
66 | Sample(b"a", 1024), |
---|
67 | Sample(b"c", 4096), |
---|
68 | Sample(digest(b"foo"), SEGMENT_SIZE - 1), |
---|
69 | Sample(digest(b"bar"), SEGMENT_SIZE + 1), |
---|
70 | Sample(digest(b"baz"), SEGMENT_SIZE * 16 - 1), |
---|
71 | Sample(digest(b"quux"), SEGMENT_SIZE * 16 + 1), |
---|
72 | Sample(digest(b"bazquux"), SEGMENT_SIZE * 32), |
---|
73 | Sample(digest(b"foobar"), SEGMENT_SIZE * 64 - 1), |
---|
74 | Sample(digest(b"barbaz"), SEGMENT_SIZE * 64 + 1), |
---|
75 | ] |
---|
76 | |
---|
77 | ZFEC_PARAMS: list[SeedParam] = [ |
---|
78 | SeedParam(1, 1), |
---|
79 | SeedParam(1, 3), |
---|
80 | SeedParam(2, 3), |
---|
81 | SeedParam(3, 10), |
---|
82 | SeedParam(71, 255), |
---|
83 | SeedParam(101, MAX_SHARES), |
---|
84 | ] |
---|
85 | |
---|
86 | FORMATS: list[CHK | SSK] = [ |
---|
87 | CHK(), |
---|
88 | |
---|
89 | # These start out unaware of a key but various keys will be supplied |
---|
90 | # during generation. |
---|
91 | SSK(name="sdmf", key=None), |
---|
92 | SSK(name="mdmf", key=None), |
---|
93 | ] |
---|