2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
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 esp_context esp_context
20 * @{ @ingroup libipsec
23 #ifndef ESP_CONTEXT_H_
24 #define ESP_CONTEXT_H_
27 #include <crypto/aead.h>
29 typedef struct esp_context_t esp_context_t
;
32 * ESP context, handles sequence numbers and maintains cryptographic primitives
34 struct esp_context_t
{
37 * Get AEAD wrapper or method to encrypt/decrypt/authenticate ESP packets.
39 * @return AEAD wrapper of method
41 aead_t
*(*get_aead
)(esp_context_t
*this);
44 * Get the current outbound ESP sequence number or the highest authenticated
45 * inbound sequence number.
47 * @return current sequence number, in host byte order
49 u_int32_t (*get_seqno
)(esp_context_t
*this);
52 * Allocate the next outbound ESP sequence number.
54 * @param seqno the sequence number, in host byte order
55 * @return FALSE if the sequence number cycled or inbound context
57 bool (*next_seqno
)(esp_context_t
*this, u_int32_t
*seqno
);
60 * Verify an ESP sequence number. Checks whether a packet with this
61 * sequence number was already received, using the anti-replay window.
62 * This operation does not modify the internal state. After the sequence
63 * number is successfully verified and the ESP packet is authenticated,
64 * set_authenticated_seqno() should be called.
66 * @param seqno the sequence number to verify, in host byte order
67 * @return TRUE when sequence number is valid
69 bool (*verify_seqno
)(esp_context_t
*this, u_int32_t seqno
);
72 * Adds a sequence number that was successfully verified and
73 * authenticated. A user MUST call verify_seqno() immediately before
74 * calling this method.
76 * @param seqno verified and authenticated seq number in host byte order
78 void (*set_authenticated_seqno
)(esp_context_t
*this,
82 * Destroy an esp_context_t
84 void (*destroy
)(esp_context_t
*this);
89 * Create an esp_context_t instance
91 * @param enc_alg encryption algorithm
92 * @param enc_key encryption key
93 * @param int_alg integrity protection algorithm
94 * @param int_key integrity protection key
95 * @param inbound TRUE to create an inbound ESP context
96 * @return ESP context instance, or NULL if creation fails
98 esp_context_t
*esp_context_create(int enc_alg
, chunk_t enc_key
, int int_alg
,
99 chunk_t int_key
, bool inbound
);
101 #endif /** ESP_CONTEXT_H_ @}*/