Lines Matching refs:epayload
270 static char *datablob_format(struct encrypted_key_payload *epayload, in datablob_format() argument
274 u8 *iv = epayload->iv; in datablob_format()
285 len = sprintf(ascii_buf, "%s %s %s ", epayload->format, in datablob_format()
286 epayload->master_desc, epayload->datalen); in datablob_format()
410 static struct key *request_master_key(struct encrypted_key_payload *epayload, in request_master_key() argument
415 if (!strncmp(epayload->master_desc, KEY_TRUSTED_PREFIX, in request_master_key()
417 mkey = request_trusted_key(epayload->master_desc + in request_master_key()
420 } else if (!strncmp(epayload->master_desc, KEY_USER_PREFIX, in request_master_key()
422 mkey = request_user_key(epayload->master_desc + in request_master_key()
433 epayload->master_desc); in request_master_key()
436 epayload->master_desc); in request_master_key()
446 static int derived_key_encrypt(struct encrypted_key_payload *epayload, in derived_key_encrypt() argument
458 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize); in derived_key_encrypt()
464 dump_decrypted_data(epayload); in derived_key_encrypt()
467 sg_set_buf(&sg_in[0], epayload->decrypted_data, in derived_key_encrypt()
468 epayload->decrypted_datalen); in derived_key_encrypt()
472 sg_set_buf(sg_out, epayload->encrypted_data, encrypted_datalen); in derived_key_encrypt()
474 memcpy(iv, epayload->iv, sizeof(iv)); in derived_key_encrypt()
483 dump_encrypted_data(epayload, encrypted_datalen); in derived_key_encrypt()
488 static int datablob_hmac_append(struct encrypted_key_payload *epayload, in datablob_hmac_append() argument
499 digest = epayload->format + epayload->datablob_len; in datablob_hmac_append()
501 epayload->format, epayload->datablob_len); in datablob_hmac_append()
510 static int datablob_hmac_verify(struct encrypted_key_payload *epayload, in datablob_hmac_verify() argument
524 len = epayload->datablob_len; in datablob_hmac_verify()
526 p = epayload->master_desc; in datablob_hmac_verify()
527 len -= strlen(epayload->format) + 1; in datablob_hmac_verify()
529 p = epayload->format; in datablob_hmac_verify()
534 ret = crypto_memneq(digest, epayload->format + epayload->datablob_len, in datablob_hmac_verify()
539 epayload->format + epayload->datablob_len, in datablob_hmac_verify()
548 static int derived_key_decrypt(struct encrypted_key_payload *epayload, in derived_key_decrypt() argument
566 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize); in derived_key_decrypt()
571 dump_encrypted_data(epayload, encrypted_datalen); in derived_key_decrypt()
575 sg_set_buf(sg_in, epayload->encrypted_data, encrypted_datalen); in derived_key_decrypt()
576 sg_set_buf(&sg_out[0], epayload->decrypted_data, in derived_key_decrypt()
577 epayload->decrypted_datalen); in derived_key_decrypt()
580 memcpy(iv, epayload->iv, sizeof(iv)); in derived_key_decrypt()
588 dump_decrypted_data(epayload); in derived_key_decrypt()
600 struct encrypted_key_payload *epayload = NULL; in encrypted_key_alloc() local
644 epayload = kzalloc(sizeof(*epayload) + payload_datalen + in encrypted_key_alloc()
646 if (!epayload) in encrypted_key_alloc()
649 epayload->payload_datalen = payload_datalen; in encrypted_key_alloc()
650 epayload->decrypted_datalen = decrypted_datalen; in encrypted_key_alloc()
651 epayload->datablob_len = datablob_len; in encrypted_key_alloc()
652 return epayload; in encrypted_key_alloc()
655 static int encrypted_key_decrypt(struct encrypted_key_payload *epayload, in encrypted_key_decrypt() argument
668 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize); in encrypted_key_decrypt()
674 ret = hex2bin(epayload->iv, hex_encoded_iv, ivsize); in encrypted_key_decrypt()
677 ret = hex2bin(epayload->encrypted_data, hex_encoded_data, in encrypted_key_decrypt()
682 hmac = epayload->format + epayload->datablob_len; in encrypted_key_decrypt()
688 mkey = request_master_key(epayload, &master_key, &master_keylen); in encrypted_key_decrypt()
692 ret = datablob_hmac_verify(epayload, format, master_key, master_keylen); in encrypted_key_decrypt()
702 ret = derived_key_decrypt(epayload, derived_key, sizeof derived_key); in encrypted_key_decrypt()
712 static void __ekey_init(struct encrypted_key_payload *epayload, in __ekey_init() argument
719 epayload->format = epayload->payload_data + epayload->payload_datalen; in __ekey_init()
720 epayload->master_desc = epayload->format + format_len + 1; in __ekey_init()
721 epayload->datalen = epayload->master_desc + strlen(master_desc) + 1; in __ekey_init()
722 epayload->iv = epayload->datalen + strlen(datalen) + 1; in __ekey_init()
723 epayload->encrypted_data = epayload->iv + ivsize + 1; in __ekey_init()
724 epayload->decrypted_data = epayload->payload_data; in __ekey_init()
727 memcpy(epayload->format, key_format_default, format_len); in __ekey_init()
730 epayload->decrypted_data = in __ekey_init()
731 ecryptfs_get_auth_tok_key((struct ecryptfs_auth_tok *)epayload->payload_data); in __ekey_init()
733 memcpy(epayload->format, format, format_len); in __ekey_init()
736 memcpy(epayload->master_desc, master_desc, strlen(master_desc)); in __ekey_init()
737 memcpy(epayload->datalen, datalen, strlen(datalen)); in __ekey_init()
746 static int encrypted_init(struct encrypted_key_payload *epayload, in encrypted_init() argument
758 ecryptfs_fill_auth_tok((struct ecryptfs_auth_tok *)epayload->payload_data, in encrypted_init()
762 __ekey_init(epayload, format, master_desc, datalen); in encrypted_init()
764 get_random_bytes(epayload->iv, ivsize); in encrypted_init()
766 get_random_bytes(epayload->decrypted_data, in encrypted_init()
767 epayload->decrypted_datalen); in encrypted_init()
769 ret = encrypted_key_decrypt(epayload, format, hex_encoded_iv); in encrypted_init()
784 struct encrypted_key_payload *epayload = NULL; in encrypted_instantiate() local
806 epayload = encrypted_key_alloc(key, format, master_desc, in encrypted_instantiate()
808 if (IS_ERR(epayload)) { in encrypted_instantiate()
809 ret = PTR_ERR(epayload); in encrypted_instantiate()
812 ret = encrypted_init(epayload, key->description, format, master_desc, in encrypted_instantiate()
815 kfree_sensitive(epayload); in encrypted_instantiate()
819 rcu_assign_keypointer(key, epayload); in encrypted_instantiate()
827 struct encrypted_key_payload *epayload; in encrypted_rcu_free() local
829 epayload = container_of(rcu, struct encrypted_key_payload, rcu); in encrypted_rcu_free()
830 kfree_sensitive(epayload); in encrypted_rcu_free()
844 struct encrypted_key_payload *epayload = key->payload.data[0]; in encrypted_update() local
867 ret = valid_master_desc(new_master_desc, epayload->master_desc); in encrypted_update()
871 new_epayload = encrypted_key_alloc(key, epayload->format, in encrypted_update()
872 new_master_desc, epayload->datalen); in encrypted_update()
878 __ekey_init(new_epayload, epayload->format, new_master_desc, in encrypted_update()
879 epayload->datalen); in encrypted_update()
881 memcpy(new_epayload->iv, epayload->iv, ivsize); in encrypted_update()
882 memcpy(new_epayload->payload_data, epayload->payload_data, in encrypted_update()
883 epayload->payload_datalen); in encrypted_update()
886 call_rcu(&epayload->rcu, encrypted_rcu_free); in encrypted_update()
903 struct encrypted_key_payload *epayload; in encrypted_read() local
912 epayload = dereference_key_locked(key); in encrypted_read()
915 asciiblob_len = epayload->datablob_len + ivsize + 1 in encrypted_read()
916 + roundup(epayload->decrypted_datalen, blksize) in encrypted_read()
922 mkey = request_master_key(epayload, &master_key, &master_keylen); in encrypted_read()
930 ret = derived_key_encrypt(epayload, derived_key, sizeof derived_key); in encrypted_read()
934 ret = datablob_hmac_append(epayload, master_key, master_keylen); in encrypted_read()
938 ascii_buf = datablob_format(epayload, asciiblob_len); in encrypted_read()