• Home
  • Raw
  • Download

Lines Matching refs:c

30 int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *node,  in __ubifs_node_calc_hash()  argument
34 SHASH_DESC_ON_STACK(shash, c->hash_tfm); in __ubifs_node_calc_hash()
37 shash->tfm = c->hash_tfm; in __ubifs_node_calc_hash()
53 static int ubifs_hash_calc_hmac(const struct ubifs_info *c, const u8 *hash, in ubifs_hash_calc_hmac() argument
56 SHASH_DESC_ON_STACK(shash, c->hmac_tfm); in ubifs_hash_calc_hmac()
59 shash->tfm = c->hmac_tfm; in ubifs_hash_calc_hmac()
61 err = crypto_shash_digest(shash, hash, c->hash_len, hmac); in ubifs_hash_calc_hmac()
78 int ubifs_prepare_auth_node(struct ubifs_info *c, void *node, in ubifs_prepare_auth_node() argument
85 hash = kmalloc(crypto_shash_descsize(c->hash_tfm), GFP_NOFS); in ubifs_prepare_auth_node()
90 SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm); in ubifs_prepare_auth_node()
92 hash_desc->tfm = c->hash_tfm; in ubifs_prepare_auth_node()
93 ubifs_shash_copy_state(c, inhash, hash_desc); in ubifs_prepare_auth_node()
100 err = ubifs_hash_calc_hmac(c, hash, auth->hmac); in ubifs_prepare_auth_node()
105 ubifs_prepare_node(c, auth, ubifs_auth_node_sz(c), 0); in ubifs_prepare_auth_node()
114 static struct shash_desc *ubifs_get_desc(const struct ubifs_info *c, in ubifs_get_desc() argument
120 if (!ubifs_authenticated(c)) in ubifs_get_desc()
145 struct shash_desc *__ubifs_hash_get_desc(const struct ubifs_info *c) in __ubifs_hash_get_desc() argument
147 return ubifs_get_desc(c, c->hash_tfm); in __ubifs_hash_get_desc()
161 void ubifs_bad_hash(const struct ubifs_info *c, const void *node, const u8 *hash, in ubifs_bad_hash() argument
164 int len = min(c->hash_len, 20); in ubifs_bad_hash()
165 int cropped = len != c->hash_len; in ubifs_bad_hash()
170 __ubifs_node_calc_hash(c, node, calc); in ubifs_bad_hash()
172 ubifs_err(c, "hash mismatch on node at LEB %d:%d", lnum, offs); in ubifs_bad_hash()
173 ubifs_err(c, "hash expected: %*ph%s", len, hash, cont); in ubifs_bad_hash()
174 ubifs_err(c, "hash calculated: %*ph%s", len, calc, cont); in ubifs_bad_hash()
187 int __ubifs_node_check_hash(const struct ubifs_info *c, const void *node, in __ubifs_node_check_hash() argument
193 err = __ubifs_node_calc_hash(c, node, calc); in __ubifs_node_check_hash()
197 if (ubifs_check_hash(c, expected, calc)) in __ubifs_node_check_hash()
215 int ubifs_sb_verify_signature(struct ubifs_info *c, in ubifs_sb_verify_signature() argument
223 sleb = ubifs_scan(c, UBIFS_SB_LNUM, UBIFS_SB_NODE_SZ, c->sbuf, 0); in ubifs_sb_verify_signature()
230 ubifs_err(c, "Unable to find signature node"); in ubifs_sb_verify_signature()
238 ubifs_err(c, "Signature node is of wrong type"); in ubifs_sb_verify_signature()
246 ubifs_err(c, "invalid signature len %d", le32_to_cpu(signode->len)); in ubifs_sb_verify_signature()
252 ubifs_err(c, "Signature type %d is not supported\n", in ubifs_sb_verify_signature()
264 ubifs_err(c, "Failed to verify signature"); in ubifs_sb_verify_signature()
266 ubifs_msg(c, "Successfully verified super block signature"); in ubifs_sb_verify_signature()
280 int ubifs_init_authentication(struct ubifs_info *c) in ubifs_init_authentication() argument
287 if (!c->auth_hash_name) { in ubifs_init_authentication()
288 ubifs_err(c, "authentication hash name needed with authentication"); in ubifs_init_authentication()
292 c->auth_hash_algo = match_string(hash_algo_name, HASH_ALGO__LAST, in ubifs_init_authentication()
293 c->auth_hash_name); in ubifs_init_authentication()
294 if ((int)c->auth_hash_algo < 0) { in ubifs_init_authentication()
295 ubifs_err(c, "Unknown hash algo %s specified", in ubifs_init_authentication()
296 c->auth_hash_name); in ubifs_init_authentication()
301 c->auth_hash_name); in ubifs_init_authentication()
303 keyring_key = request_key(&key_type_logon, c->auth_key_name, NULL); in ubifs_init_authentication()
306 ubifs_err(c, "Failed to request key: %ld", in ubifs_init_authentication()
314 ubifs_err(c, "key type must be logon"); in ubifs_init_authentication()
326 c->hash_tfm = crypto_alloc_shash(c->auth_hash_name, 0, 0); in ubifs_init_authentication()
327 if (IS_ERR(c->hash_tfm)) { in ubifs_init_authentication()
328 err = PTR_ERR(c->hash_tfm); in ubifs_init_authentication()
329 ubifs_err(c, "Can not allocate %s: %d", in ubifs_init_authentication()
330 c->auth_hash_name, err); in ubifs_init_authentication()
334 c->hash_len = crypto_shash_digestsize(c->hash_tfm); in ubifs_init_authentication()
335 if (c->hash_len > UBIFS_HASH_ARR_SZ) { in ubifs_init_authentication()
336 ubifs_err(c, "hash %s is bigger than maximum allowed hash size (%d > %d)", in ubifs_init_authentication()
337 c->auth_hash_name, c->hash_len, UBIFS_HASH_ARR_SZ); in ubifs_init_authentication()
342 c->hmac_tfm = crypto_alloc_shash(hmac_name, 0, 0); in ubifs_init_authentication()
343 if (IS_ERR(c->hmac_tfm)) { in ubifs_init_authentication()
344 err = PTR_ERR(c->hmac_tfm); in ubifs_init_authentication()
345 ubifs_err(c, "Can not allocate %s: %d", hmac_name, err); in ubifs_init_authentication()
349 c->hmac_desc_len = crypto_shash_digestsize(c->hmac_tfm); in ubifs_init_authentication()
350 if (c->hmac_desc_len > UBIFS_HMAC_ARR_SZ) { in ubifs_init_authentication()
351 ubifs_err(c, "hmac %s is bigger than maximum allowed hmac size (%d > %d)", in ubifs_init_authentication()
352 hmac_name, c->hmac_desc_len, UBIFS_HMAC_ARR_SZ); in ubifs_init_authentication()
357 err = crypto_shash_setkey(c->hmac_tfm, ukp->data, ukp->datalen); in ubifs_init_authentication()
361 c->authenticated = true; in ubifs_init_authentication()
363 c->log_hash = ubifs_hash_get_desc(c); in ubifs_init_authentication()
364 if (IS_ERR(c->log_hash)) in ubifs_init_authentication()
371 crypto_free_shash(c->hmac_tfm); in ubifs_init_authentication()
374 crypto_free_shash(c->hash_tfm); in ubifs_init_authentication()
388 void __ubifs_exit_authentication(struct ubifs_info *c) in __ubifs_exit_authentication() argument
390 if (!ubifs_authenticated(c)) in __ubifs_exit_authentication()
393 crypto_free_shash(c->hmac_tfm); in __ubifs_exit_authentication()
394 crypto_free_shash(c->hash_tfm); in __ubifs_exit_authentication()
395 kfree(c->log_hash); in __ubifs_exit_authentication()
410 static int ubifs_node_calc_hmac(const struct ubifs_info *c, const void *node, in ubifs_node_calc_hmac() argument
413 SHASH_DESC_ON_STACK(shash, c->hmac_tfm); in ubifs_node_calc_hmac()
414 int hmac_len = c->hmac_desc_len; in ubifs_node_calc_hmac()
417 ubifs_assert(c, ofs_hmac > 8); in ubifs_node_calc_hmac()
418 ubifs_assert(c, ofs_hmac + hmac_len < len); in ubifs_node_calc_hmac()
420 shash->tfm = c->hmac_tfm; in ubifs_node_calc_hmac()
454 int __ubifs_node_insert_hmac(const struct ubifs_info *c, void *node, int len, in __ubifs_node_insert_hmac() argument
457 return ubifs_node_calc_hmac(c, node, len, ofs_hmac, node + ofs_hmac); in __ubifs_node_insert_hmac()
470 int __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *node, in __ubifs_node_verify_hmac() argument
473 int hmac_len = c->hmac_desc_len; in __ubifs_node_verify_hmac()
481 err = ubifs_node_calc_hmac(c, node, len, ofs_hmac, hmac); in __ubifs_node_verify_hmac()
497 int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src, in __ubifs_shash_copy_state() argument
531 int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac) in ubifs_hmac_wkm() argument
533 SHASH_DESC_ON_STACK(shash, c->hmac_tfm); in ubifs_hmac_wkm()
537 if (!ubifs_authenticated(c)) in ubifs_hmac_wkm()
540 shash->tfm = c->hmac_tfm; in ubifs_hmac_wkm()
565 bool ubifs_hmac_zero(struct ubifs_info *c, const u8 *hmac) in ubifs_hmac_zero() argument
567 return !memchr_inv(hmac, 0, c->hmac_desc_len); in ubifs_hmac_zero()