Use different return values in payload decryption to distinguish between integrity...
[strongswan.git] / src / libcharon / encoding / payloads / encryption_payload.h
1 /*
2 * Copyright (C) 2005-2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
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>.
11 *
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
15 * for more details.
16 */
17
18 /**
19 * @defgroup encryption_payload encryption_payload
20 * @{ @ingroup payloads
21 */
22
23 #ifndef ENCRYPTION_PAYLOAD_H_
24 #define ENCRYPTION_PAYLOAD_H_
25
26 typedef struct encryption_payload_t encryption_payload_t;
27
28 #include <library.h>
29 #include <crypto/aead.h>
30 #include <encoding/payloads/payload.h>
31
32 /**
33 * Encrpytion payload length in bytes without IV and following data.
34 */
35 #define ENCRYPTION_PAYLOAD_HEADER_LENGTH 4
36
37 /**
38 * The encryption payload as described in RFC section 3.14.
39 */
40 struct encryption_payload_t {
41
42 /**
43 * Implements payload_t interface.
44 */
45 payload_t payload_interface;
46
47 /**
48 * Get the payload length.
49 *
50 * @return (expected) payload length
51 */
52 size_t (*get_length)(encryption_payload_t *this);
53
54 /**
55 * Adds a payload to this encryption payload.
56 *
57 * @param payload payload_t object to add
58 */
59 void (*add_payload) (encryption_payload_t *this, payload_t *payload);
60
61 /**
62 * Remove the first payload in the list
63 *
64 * @param payload removed payload
65 * @return payload, NULL if none left
66 */
67 payload_t* (*remove_payload)(encryption_payload_t *this);
68
69 /**
70 * Set the AEAD transform to use.
71 *
72 * @param aead aead transform to use
73 */
74 void (*set_transform) (encryption_payload_t *this, aead_t *aead);
75
76 /**
77 * Generate, encrypt and sign contained payloads.
78 *
79 * @param assoc associated data
80 * @return TRUE if encrypted
81 */
82 bool (*encrypt) (encryption_payload_t *this, chunk_t assoc);
83
84 /**
85 * Decrypt, verify and parse contained payloads.
86 *
87 * @param assoc associated data
88 * - SUCCESS if parsing successful
89 * - PARSE_ERROR if sub-payload parsing failed
90 * - VERIFY_ERROR if sub-payload verification failed
91 * - FAILED if integrity check failed
92 * - INVALID_STATE if aead not supplied, but needed
93 */
94 status_t (*decrypt) (encryption_payload_t *this, chunk_t assoc);
95
96 /**
97 * Destroys an encryption_payload_t object.
98 */
99 void (*destroy) (encryption_payload_t *this);
100 };
101
102 /**
103 * Creates an empty encryption_payload_t object.
104 *
105 * @return encryption_payload_t object
106 */
107 encryption_payload_t *encryption_payload_create(void);
108
109 #endif /** ENCRYPTION_PAYLOAD_H_ @}*/