Lines Matching refs:f

120 static inline int verity_hash(fec_handle *f, const uint8_t *block,  in verity_hash()  argument
126 check(f); in verity_hash()
127 check(f->verity.salt); in verity_hash()
128 SHA256_Update(&ctx, f->verity.salt, f->verity.salt_size); in verity_hash()
140 bool verity_check_block(fec_handle *f, const uint8_t *expected, in verity_check_block() argument
143 check(f); in verity_check_block()
148 if (unlikely(verity_hash(f, block, hash) == -1)) { in verity_check_block()
159 static bool ecc_read_hashes(fec_handle *f, uint64_t hash_offset, in ecc_read_hashes() argument
162 check(f); in ecc_read_hashes()
164 if (hash && fec_pread(f, hash, SHA256_DIGEST_LENGTH, hash_offset) != in ecc_read_hashes()
173 if (fec_pread(f, data, FEC_BLOCKSIZE, data_offset) != FEC_BLOCKSIZE) { in ecc_read_hashes()
185 static int verify_tree(fec_handle *f, const uint8_t *root) in verify_tree() argument
190 check(f); in verify_tree()
193 verity_info *v = &f->verity; in verify_tree()
201 check(v->hash_start + v->hash_size <= f->data_size); in verify_tree()
209 if (!raw_pread(f, data, FEC_BLOCKSIZE, hash_offset) || in verify_tree()
210 !verity_check_block(f, root, data)) { in verify_tree()
212 if (!ecc_read_hashes(f, 0, NULL, hash_offset, data) || in verify_tree()
213 !verity_check_block(f, root, data)) { in verify_tree()
216 } else if (f->mode & O_RDWR && in verify_tree()
217 !raw_pwrite(f, data, FEC_BLOCKSIZE, hash_offset)) { in verify_tree()
247 check(v->hash_data_offset < f->data_size); in verify_tree()
249 f->data_size); in verify_tree()
254 new (std::nothrow) uint8_t[f->verity.hash_data_blocks * FEC_BLOCKSIZE]); in verify_tree()
270 if (!raw_pread(f, hash, SHA256_DIGEST_LENGTH, in verify_tree()
272 !raw_pread(f, data, FEC_BLOCKSIZE, in verify_tree()
278 if (!verity_check_block(f, hash, data)) { in verify_tree()
280 if (!ecc_read_hashes(f, in verify_tree()
283 !verity_check_block(f, hash, data)) { in verify_tree()
292 if (f->mode & O_RDWR) { in verify_tree()
293 if (!raw_pwrite(f, hash, SHA256_DIGEST_LENGTH, in verify_tree()
295 !raw_pwrite(f, data, FEC_BLOCKSIZE, in verify_tree()
322 static int parse_table(fec_handle *f, uint64_t offset, uint32_t size) in parse_table() argument
324 check(f); in parse_table()
330 verity_info *v = &f->verity; in parse_table()
338 if (fec_pread(f, table.get(), size, offset) != (ssize_t)size) { in parse_table()
369 if (parse_uint64(token.c_str(), f->data_size / FEC_BLOCKSIZE, in parse_table()
377 if (parse_uint64(token.c_str(), f->data_size / FEC_BLOCKSIZE, in parse_table()
425 check(v->hash_start < f->data_size); in parse_table()
436 if (!(f->flags & FEC_VERITY_DISABLE)) { in parse_table()
437 if (verify_tree(f, root) == -1) { in parse_table()
446 if (verity_hash(f, zero_block, v->zero_hash) == -1) { in parse_table()
456 static int rewrite_metadata(fec_handle *f, uint64_t offset) in rewrite_metadata() argument
458 check(f); in rewrite_metadata()
459 check(f->data_size > VERITY_METADATA_SIZE); in rewrite_metadata()
460 check(offset <= f->data_size - VERITY_METADATA_SIZE); in rewrite_metadata()
472 verity_info *v = &f->verity; in rewrite_metadata()
481 return raw_pwrite(f, metadata.get(), VERITY_METADATA_SIZE, offset); in rewrite_metadata()
484 static int validate_header(const fec_handle *f, const verity_header *header, in validate_header() argument
487 check(f); in validate_header()
515 } else if (offset + header->length >= f->data_size) { in validate_header()
525 int verity_parse_header(fec_handle *f, uint64_t offset) in verity_parse_header() argument
527 check(f); in verity_parse_header()
528 check(f->data_size > VERITY_METADATA_SIZE); in verity_parse_header()
530 if (offset > f->data_size - VERITY_METADATA_SIZE) { in verity_parse_header()
536 verity_info *v = &f->verity; in verity_parse_header()
537 uint64_t errors = f->errors; in verity_parse_header()
539 if (!raw_pread(f, &v->header, sizeof(v->header), offset)) { in verity_parse_header()
552 if (fec_pread(f, &v->ecc_header, sizeof(v->ecc_header), offset) != in verity_parse_header()
558 if (validate_header(f, &v->header, offset)) { in verity_parse_header()
562 if (validate_header(f, &v->ecc_header, offset)) { in verity_parse_header()
592 if (parse_table(f, offset + sizeof(v->header), v->header.length) == -1) { in verity_parse_header()
598 if (f->mode & O_RDWR && f->errors > errors && in verity_parse_header()
599 rewrite_metadata(f, offset) < 0) { in verity_parse_header()
604 f->data_size = v->metadata_start; in verity_parse_header()
606 f->data_size = v->hash_start; in verity_parse_header()
612 int fec_verity_set_status(struct fec_handle *f, bool enabled) in fec_verity_set_status() argument
614 check(f); in fec_verity_set_status()
616 if (!(f->mode & O_RDWR)) { in fec_verity_set_status()
622 verity_info *v = &f->verity; in fec_verity_set_status()
636 if (!raw_pwrite(f, &magic, sizeof(magic), v->metadata_start)) { in fec_verity_set_status()