Lines Matching refs:epayload
276 static char *datablob_format(struct encrypted_key_payload *epayload, in datablob_format() argument
280 u8 *iv = epayload->iv; in datablob_format()
291 len = sprintf(ascii_buf, "%s %s %s ", epayload->format, in datablob_format()
292 epayload->master_desc, epayload->datalen); in datablob_format()
416 static struct key *request_master_key(struct encrypted_key_payload *epayload, in request_master_key() argument
421 if (!strncmp(epayload->master_desc, KEY_TRUSTED_PREFIX, in request_master_key()
423 mkey = request_trusted_key(epayload->master_desc + in request_master_key()
426 } else if (!strncmp(epayload->master_desc, KEY_USER_PREFIX, in request_master_key()
428 mkey = request_user_key(epayload->master_desc + in request_master_key()
439 epayload->master_desc); in request_master_key()
442 epayload->master_desc); in request_master_key()
452 static int derived_key_encrypt(struct encrypted_key_payload *epayload, in derived_key_encrypt() argument
464 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize); in derived_key_encrypt()
470 dump_decrypted_data(epayload); in derived_key_encrypt()
473 sg_set_buf(&sg_in[0], epayload->decrypted_data, in derived_key_encrypt()
474 epayload->decrypted_datalen); in derived_key_encrypt()
478 sg_set_buf(sg_out, epayload->encrypted_data, encrypted_datalen); in derived_key_encrypt()
480 memcpy(iv, epayload->iv, sizeof(iv)); in derived_key_encrypt()
489 dump_encrypted_data(epayload, encrypted_datalen); in derived_key_encrypt()
494 static int datablob_hmac_append(struct encrypted_key_payload *epayload, in datablob_hmac_append() argument
505 digest = epayload->format + epayload->datablob_len; in datablob_hmac_append()
507 epayload->format, epayload->datablob_len); in datablob_hmac_append()
516 static int datablob_hmac_verify(struct encrypted_key_payload *epayload, in datablob_hmac_verify() argument
530 len = epayload->datablob_len; in datablob_hmac_verify()
532 p = epayload->master_desc; in datablob_hmac_verify()
533 len -= strlen(epayload->format) + 1; in datablob_hmac_verify()
535 p = epayload->format; in datablob_hmac_verify()
540 ret = crypto_memneq(digest, epayload->format + epayload->datablob_len, in datablob_hmac_verify()
545 epayload->format + epayload->datablob_len, in datablob_hmac_verify()
554 static int derived_key_decrypt(struct encrypted_key_payload *epayload, in derived_key_decrypt() argument
572 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize); in derived_key_decrypt()
577 dump_encrypted_data(epayload, encrypted_datalen); in derived_key_decrypt()
581 sg_set_buf(sg_in, epayload->encrypted_data, encrypted_datalen); in derived_key_decrypt()
582 sg_set_buf(&sg_out[0], epayload->decrypted_data, in derived_key_decrypt()
583 epayload->decrypted_datalen); in derived_key_decrypt()
586 memcpy(iv, epayload->iv, sizeof(iv)); in derived_key_decrypt()
594 dump_decrypted_data(epayload); in derived_key_decrypt()
607 struct encrypted_key_payload *epayload = NULL; in encrypted_key_alloc() local
670 epayload = kzalloc(sizeof(*epayload) + payload_datalen + in encrypted_key_alloc()
672 if (!epayload) in encrypted_key_alloc()
675 epayload->payload_datalen = payload_datalen; in encrypted_key_alloc()
676 epayload->decrypted_datalen = decrypted_datalen; in encrypted_key_alloc()
677 epayload->datablob_len = datablob_len; in encrypted_key_alloc()
678 return epayload; in encrypted_key_alloc()
681 static int encrypted_key_decrypt(struct encrypted_key_payload *epayload, in encrypted_key_decrypt() argument
694 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize); in encrypted_key_decrypt()
700 ret = hex2bin(epayload->iv, hex_encoded_iv, ivsize); in encrypted_key_decrypt()
703 ret = hex2bin(epayload->encrypted_data, hex_encoded_data, in encrypted_key_decrypt()
708 hmac = epayload->format + epayload->datablob_len; in encrypted_key_decrypt()
714 mkey = request_master_key(epayload, &master_key, &master_keylen); in encrypted_key_decrypt()
718 ret = datablob_hmac_verify(epayload, format, master_key, master_keylen); in encrypted_key_decrypt()
728 ret = derived_key_decrypt(epayload, derived_key, sizeof derived_key); in encrypted_key_decrypt()
738 static void __ekey_init(struct encrypted_key_payload *epayload, in __ekey_init() argument
745 epayload->format = epayload->payload_data + epayload->payload_datalen; in __ekey_init()
746 epayload->master_desc = epayload->format + format_len + 1; in __ekey_init()
747 epayload->datalen = epayload->master_desc + strlen(master_desc) + 1; in __ekey_init()
748 epayload->iv = epayload->datalen + strlen(datalen) + 1; in __ekey_init()
749 epayload->encrypted_data = epayload->iv + ivsize + 1; in __ekey_init()
750 epayload->decrypted_data = epayload->payload_data; in __ekey_init()
753 memcpy(epayload->format, key_format_default, format_len); in __ekey_init()
756 epayload->decrypted_data = in __ekey_init()
757 ecryptfs_get_auth_tok_key((struct ecryptfs_auth_tok *)epayload->payload_data); in __ekey_init()
759 memcpy(epayload->format, format, format_len); in __ekey_init()
762 memcpy(epayload->master_desc, master_desc, strlen(master_desc)); in __ekey_init()
763 memcpy(epayload->datalen, datalen, strlen(datalen)); in __ekey_init()
773 static int encrypted_init(struct encrypted_key_payload *epayload, in encrypted_init() argument
785 ecryptfs_fill_auth_tok((struct ecryptfs_auth_tok *)epayload->payload_data, in encrypted_init()
789 __ekey_init(epayload, format, master_desc, datalen); in encrypted_init()
791 ret = encrypted_key_decrypt(epayload, format, hex_encoded_iv); in encrypted_init()
793 get_random_bytes(epayload->iv, ivsize); in encrypted_init()
794 ret = hex2bin(epayload->decrypted_data, decrypted_data, in encrypted_init()
795 epayload->decrypted_datalen); in encrypted_init()
797 get_random_bytes(epayload->iv, ivsize); in encrypted_init()
798 get_random_bytes(epayload->decrypted_data, epayload->decrypted_datalen); in encrypted_init()
816 struct encrypted_key_payload *epayload = NULL; in encrypted_instantiate() local
839 epayload = encrypted_key_alloc(key, format, master_desc, in encrypted_instantiate()
841 if (IS_ERR(epayload)) { in encrypted_instantiate()
842 ret = PTR_ERR(epayload); in encrypted_instantiate()
845 ret = encrypted_init(epayload, key->description, format, master_desc, in encrypted_instantiate()
848 kfree_sensitive(epayload); in encrypted_instantiate()
852 rcu_assign_keypointer(key, epayload); in encrypted_instantiate()
860 struct encrypted_key_payload *epayload; in encrypted_rcu_free() local
862 epayload = container_of(rcu, struct encrypted_key_payload, rcu); in encrypted_rcu_free()
863 kfree_sensitive(epayload); in encrypted_rcu_free()
877 struct encrypted_key_payload *epayload = key->payload.data[0]; in encrypted_update() local
900 ret = valid_master_desc(new_master_desc, epayload->master_desc); in encrypted_update()
904 new_epayload = encrypted_key_alloc(key, epayload->format, in encrypted_update()
905 new_master_desc, epayload->datalen, NULL); in encrypted_update()
911 __ekey_init(new_epayload, epayload->format, new_master_desc, in encrypted_update()
912 epayload->datalen); in encrypted_update()
914 memcpy(new_epayload->iv, epayload->iv, ivsize); in encrypted_update()
915 memcpy(new_epayload->payload_data, epayload->payload_data, in encrypted_update()
916 epayload->payload_datalen); in encrypted_update()
919 call_rcu(&epayload->rcu, encrypted_rcu_free); in encrypted_update()
936 struct encrypted_key_payload *epayload; in encrypted_read() local
945 epayload = dereference_key_locked(key); in encrypted_read()
948 asciiblob_len = epayload->datablob_len + ivsize + 1 in encrypted_read()
949 + roundup(epayload->decrypted_datalen, blksize) in encrypted_read()
955 mkey = request_master_key(epayload, &master_key, &master_keylen); in encrypted_read()
963 ret = derived_key_encrypt(epayload, derived_key, sizeof derived_key); in encrypted_read()
967 ret = datablob_hmac_append(epayload, master_key, master_keylen); in encrypted_read()
971 ascii_buf = datablob_format(epayload, asciiblob_len); in encrypted_read()