| | 749 | |
|---|
| | 750 | |
|---|
| | 751 | ops_pk_session_key_t *ops_create_pk_session_key(const ops_key_data_t *key) |
|---|
| | 752 | { |
|---|
| | 753 | ops_pk_session_key_t *session_key=ops_mallocz(sizeof *session_key); |
|---|
| | 754 | |
|---|
| | 755 | session_key->version=OPS_PKSK_V3; |
|---|
| | 756 | memcpy(session_key->key_id, key->key_id, sizeof session_key->key_id); |
|---|
| | 757 | // XXX: finish filling in the structure |
|---|
| | 758 | return session_key; |
|---|
| | 759 | } |
|---|
| | 760 | |
|---|
| | 761 | // XXX: should these be common and just be called ops_crypt_*? |
|---|
| | 762 | typedef struct _ops_encrypt_t ops_encrypt_t; |
|---|
| | 763 | typedef void ops_encrypt_set_iv_t(ops_encrypt_t *encrypt, |
|---|
| | 764 | const unsigned char *iv); |
|---|
| | 765 | typedef void ops_encrypt_init_t(ops_encrypt_t *encrypt); |
|---|
| | 766 | typedef void ops_encrypt_resync_t(ops_encrypt_t *encrypt); |
|---|
| | 767 | typedef void ops_encrypt_block_encrypt_t(ops_encrypt_t *encrypt,void *out, |
|---|
| | 768 | const void *in); |
|---|
| | 769 | typedef void ops_encrypt_finish_t(ops_encrypt_t *encrypt); |
|---|
| | 770 | |
|---|
| | 771 | /** _ops_encrypt_t */ |
|---|
| | 772 | struct _ops_encrypt_t |
|---|
| | 773 | { |
|---|
| | 774 | ops_symmetric_algorithm_t algorithm; |
|---|
| | 775 | size_t blocksize; |
|---|
| | 776 | size_t keysize; |
|---|
| | 777 | // ops_encrypt_set_iv_t *set_iv; /* Call this before init! */ |
|---|
| | 778 | ops_encrypt_set_iv_t *set_key; /* Call this before init! */ |
|---|
| | 779 | ops_encrypt_init_t *base_init; /* Once the key is set, call this */ |
|---|
| | 780 | ops_encrypt_resync_t *resync; |
|---|
| | 781 | // ops_decrypt_decrypt_t *decrypt; |
|---|
| | 782 | ops_encrypt_block_encrypt_t *block_encrypt; |
|---|
| | 783 | ops_encrypt_finish_t *finish; |
|---|
| | 784 | unsigned char iv[OPS_MAX_BLOCK_SIZE]; |
|---|
| | 785 | unsigned char civ[OPS_MAX_BLOCK_SIZE]; |
|---|
| | 786 | unsigned char siv[OPS_MAX_BLOCK_SIZE]; /* Needed for weird v3 resync */ |
|---|
| | 787 | unsigned char key[OPS_MAX_KEY_SIZE]; |
|---|
| | 788 | size_t num; |
|---|
| | 789 | void *data; |
|---|
| | 790 | }; |
|---|
| | 791 | |
|---|
| | 792 | typedef struct |
|---|
| | 793 | { |
|---|
| | 794 | ops_encrypt_t *encrypter; |
|---|
| | 795 | } encrypted_arg_t; |
|---|
| | 796 | |
|---|
| | 797 | |
|---|
| | 798 | /* dummy function */ |
|---|
| | 799 | |
|---|
| | 800 | #ifndef ATTRIBUTE_UNUSED |
|---|
| | 801 | #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) |
|---|
| | 802 | #endif /* ATTRIBUTE_UNUSED */ |
|---|
| | 803 | |
|---|
| | 804 | void ops_write_pk_session_key(ops_create_info_t *info ATTRIBUTE_UNUSED, ops_pk_session_key_t *session_key ATTRIBUTE_UNUSED) |
|---|
| | 805 | { |
|---|
| | 806 | /* \todo write ops_write_pk_session_key() */ |
|---|
| | 807 | assert(0); |
|---|
| | 808 | } |
|---|
| | 809 | |
|---|
| | 810 | static ops_boolean_t encrypted_writer(const unsigned char *src ATTRIBUTE_UNUSED, |
|---|
| | 811 | unsigned length ATTRIBUTE_UNUSED, |
|---|
| | 812 | ops_error_t **errors ATTRIBUTE_UNUSED, |
|---|
| | 813 | ops_writer_info_t *winfo ATTRIBUTE_UNUSED |
|---|
| | 814 | ) |
|---|
| | 815 | { |
|---|
| | 816 | /* \todo */ |
|---|
| | 817 | assert(0); |
|---|
| | 818 | } |
|---|
| | 819 | |
|---|
| | 820 | static ops_boolean_t encrypted_finaliser(ops_error_t **errors ATTRIBUTE_UNUSED, |
|---|
| | 821 | ops_writer_info_t *winfo ATTRIBUTE_UNUSED) |
|---|
| | 822 | { |
|---|
| | 823 | /* \todo */ |
|---|
| | 824 | assert(0); |
|---|
| | 825 | } |
|---|
| | 826 | |
|---|
| | 827 | void encrypted_destroyer (ops_writer_info_t *winfo ATTRIBUTE_UNUSED) |
|---|
| | 828 | |
|---|
| | 829 | { |
|---|
| | 830 | /* \todo */ |
|---|
| | 831 | assert(0); |
|---|
| | 832 | } |
|---|
| | 833 | |
|---|
| | 834 | /* end of dummy code */ |
|---|
| | 835 | |
|---|
| | 836 | void ops_writer_push_encrypt(ops_create_info_t *info, |
|---|
| | 837 | const ops_key_data_t *key) |
|---|
| | 838 | { |
|---|
| | 839 | ops_pk_session_key_t *session_key; |
|---|
| | 840 | encrypted_arg_t *arg=ops_mallocz(sizeof *arg); |
|---|
| | 841 | |
|---|
| | 842 | session_key=ops_create_pk_session_key(key); |
|---|
| | 843 | ops_write_pk_session_key(info,session_key); |
|---|
| | 844 | |
|---|
| | 845 | ops_write_ptag(OPS_PTAG_CT_SE_DATA,info); |
|---|
| | 846 | ops_writer_push(info,encrypted_writer,encrypted_finaliser, |
|---|
| | 847 | encrypted_destroyer,arg); |
|---|
| | 848 | } |
|---|