39
39
,"signature" / Bytes (64 )
40
40
);
41
41
42
+ '''
43
+ ------------- 4-bytes / 32 bits -------------
44
+ +------------++-------------++--------------+
45
+ |SECTION TYPE||SECTION FLAGS||SECTION LENGTH|
46
+ |(UINT8=0xFF)|| (UINT8) || (UINT16) |
47
+ +------------++-------------++--------------+
48
+ ------------ 16-bytes / 128 bits ------------
49
+ +------------------++-----------------------+
50
+ | TAI64N Timestamp || Random Nonce |
51
+ | (12 bytes) || (UINT32) |
52
+ +------------------++-----------------------+
53
+ ------------ 32-bytes / 256-bits ------------
54
+ +-------------------------------------------+
55
+ | SIGNER PUBLIC KEY |
56
+ | Ed25519(256-bits) |
57
+ +-------------------------------------------+
58
+ ------------ 64-bytes / 512-bits ------------
59
+ +-------------------------------------------+
60
+ | Signature of file up to this point |
61
+ | Ed25519(512-bits) |
62
+ +-------------------------------------------+
63
+ '''
64
+
65
+ _SN_SECTION_CHECKPOINT = Struct (
66
+ "header" / Struct (
67
+ "type" / Int8ub
68
+ ,"flags" / Int8ub
69
+ ,"length" / Const (112 , Int16ub )
70
+ )
71
+ ,"timestamp" / Bytes (12 )
72
+ ,"nonce" / Bytes (4 )
73
+ ,"publickey" / Bytes (32 )
74
+ ,"checkpoint_sig" / Bytes (64 )
75
+ )
76
+
42
77
_SIX_MONTH_IN_SECONDS = 15778463
43
78
44
79
'''
@@ -113,6 +148,18 @@ def sn__generate_init():
113
148
return {"data" : data + signature .digest (), "signature" : signature .hexdigest ()}
114
149
115
150
151
+ def sn__checkpoint_apply (blob , skpk ):
152
+ checkpoint = blob + _SN_SECTION_CHECKPOINT .build (dict (
153
+ header = dict (type = 0xFF , flags = 0x0 )
154
+ ,timestamp = "*" * 12
155
+ ,nonce = os .urandom (4 )
156
+ ,publickey = skpk [1 ].to_bytes ()
157
+ ,checkpoint_sig = "\x00 " * 64
158
+ ))
159
+
160
+ signature = skpk [0 ].sign ( checkpoint [:- 64 ] )
161
+ return checkpoint [:- 64 ] + signature
162
+
116
163
snote = sn__generate_init ()
117
164
118
165
print len (snote ['data' ])
@@ -121,5 +168,6 @@ def sn__generate_init():
121
168
122
169
print _SN_SECTION_INIT .parse ( snote ['data' ] )
123
170
124
-
171
+ print "CHECKPOINT"
172
+ print repr ( sn__checkpoint_apply (snote ['data' ], KEYPAIR__CENTRAL_MINT ) )
125
173
0 commit comments