2 * Copyright (C) 2005-2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * @defgroup encryption_payload encryption_payload
20 * @{ @ingroup payloads
23 #ifndef ENCRYPTION_PAYLOAD_H_
24 #define ENCRYPTION_PAYLOAD_H_
26 typedef struct encryption_payload_t encryption_payload_t
;
29 #include <crypto/aead.h>
30 #include <encoding/payloads/payload.h>
33 * The encryption payload as described in RFC section 3.14.
35 struct encryption_payload_t
{
38 * Implements payload_t interface.
40 payload_t payload_interface
;
43 * Get the payload length.
45 * @return (expected) payload length
47 size_t (*get_length
)(encryption_payload_t
*this);
50 * Adds a payload to this encryption payload.
52 * @param payload payload_t object to add
54 void (*add_payload
) (encryption_payload_t
*this, payload_t
*payload
);
57 * Remove the first payload in the list
59 * @param payload removed payload
60 * @return payload, NULL if none left
62 payload_t
* (*remove_payload
)(encryption_payload_t
*this);
65 * Set the AEAD transform to use.
67 * @param aead aead transform to use
69 void (*set_transform
) (encryption_payload_t
*this, aead_t
*aead
);
72 * Generate, encrypt and sign contained payloads.
74 * @param mid message ID
75 * @param assoc associated data
77 * - SUCCESS if encryption successful
78 * - FAILED if encryption failed
79 * - INVALID_STATE if aead not supplied, but needed
81 status_t (*encrypt
) (encryption_payload_t
*this, u_int64_t mid
,
85 * Decrypt, verify and parse contained payloads.
87 * @param assoc associated data
89 * - SUCCESS if parsing successful
90 * - PARSE_ERROR if sub-payload parsing failed
91 * - VERIFY_ERROR if sub-payload verification failed
92 * - FAILED if integrity check failed
93 * - INVALID_STATE if aead not supplied, but needed
95 status_t (*decrypt
) (encryption_payload_t
*this, chunk_t assoc
);
98 * Destroys an encryption_payload_t object.
100 void (*destroy
) (encryption_payload_t
*this);
104 * Creates an empty encryption_payload_t object.
106 * @param type ENCRYPTED or ENCRYPTED_V1
107 * @return encryption_payload_t object
109 encryption_payload_t
*encryption_payload_create(payload_type_t type
);
111 #endif /** ENCRYPTION_PAYLOAD_H_ @}*/