*
* offset length
* +-------------------+
- * | sb_hash | 0 32
- * | sb_serial | 32 8
+ * | magic | 0 8
+ * | version | 8 8
+ * | sb_hash | 16 32
+ * | sb_serial | 48 8
* +-------------------+
- * | unused | 40 984
+ * | unused | 56 968
* +-------------------+
* | current | 1024 512
* +-------------------+
* offset length
* +-------------------+
* | global_iv | 0 32
- * +-------------------+
* | block_size | 32 1
+ * | nursery_size | 33 1
* +-------------------+
- * | unused | 33 478
+ * | unused | 34 477
* +-------------------+
* | reserved | 511 1
* +-------------------+
*/
struct cq_super default_super = {
- .current = {{0,},12},
- .desired = {{0,},12},
+ .current = {{0,},12,10},
+ .desired = {{0,},12,10},
.sb_serial = 0,
.sb_hash = {0,},
+ .version = COQUET_VERSION,
.from_b = 1
};
static void extract_config(uint8_t *data, struct cq_super_config *sc) {
memcpy(sc->global_iv,data,HASH_LEN);
sc->block_size = be_decode(data+32,1);
+ sc->nursery_size = be_decode(data+33,1);
}
static int extract_half(uint8_t *data, struct cq_super *super) {
struct sha2_ctx_t sha2;
uint8_t hash[HASH_LEN],cmp[HASH_LEN];
+ uint64_t magic;
/* extract */
+ magic = be_decode(data,8);
+ if(magic!=COQUET_MAGIC) {
+ return 0;
+ }
+ super->version = be_decode(data+8,8);
+ /* All versions are fine for now. */
memset(super->sb_hash,0,HASH_LEN);
- super->sb_serial = be_decode(data+32,8);
+ super->sb_serial = be_decode(data+48,8);
+
extract_config(data+1024,&(super->current));
extract_config(data+1536,&(super->desired));
/* verify */
- memcpy(hash,data,HASH_LEN);
- memset(data,0,HASH_LEN);
+ memcpy(hash,data+16,HASH_LEN);
+ memset(data+16,0,HASH_LEN);
sha2_init_hmac(&sha2, SHA2_VARIETY_512_256,
super->current.global_iv, GLOBAL_IV_LEN);
sha2_more(&sha2,data,HALF_BYTES);
struct cq_super_config *sc) {
memcpy(data,sc->global_iv,HASH_LEN);
be_encode(data+32,sc->block_size,1);
+ be_encode(data+33,sc->nursery_size,1);
}
static void intract(uint8_t *data, struct cq_super *super, uint64_t serial) {
struct sha2_ctx_t sha2;
/* intract */
- memset(data,0,HALF_BYTES);
- be_encode(data+32,serial,8);
+ memset(data,0,HASH_LEN);
+ be_encode(data,COQUET_MAGIC,8);
+ be_encode(data+8,COQUET_VERSION,8);
+ be_encode(data+48,serial,8);
+
intract_config(data+1024,&(super->current));
intract_config(data+1536,&(super->desired));
sha2_init_hmac(&sha2, SHA2_VARIETY_512_256,
super->current.global_iv, GLOBAL_IV_LEN);
sha2_more(&sha2,data,HALF_BYTES);
- sha2_finish(&sha2,data,HASH_LEN);
+ sha2_finish(&sha2,data+16,HASH_LEN);
}
static int super_write(coquet_t *cq, struct cq_super *super,