Annotation of embedaddon/strongswan/src/libstrongswan/plugins/chapoly/chapoly_drv.h, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2015 Martin Willi
3: * Copyright (C) 2015 revosec AG
4: *
5: * This program is free software; you can redistribute it and/or modify it
6: * under the terms of the GNU General Public License as published by the
7: * Free Software Foundation; either version 2 of the License, or (at your
8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9: *
10: * This program is distributed in the hope that it will be useful, but
11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: * for more details.
14: */
15:
16: /**
17: * @defgroup chapoly_drv chapoly_drv
18: * @{ @ingroup chapoly
19: */
20:
21: #ifndef CHAPOLY_DRV_H_
22: #define CHAPOLY_DRV_H_
23:
24: #include <library.h>
25:
26: #define CHACHA_BLOCK_SIZE 64
27: #define CHACHA_IV_SIZE 8
28: #define CHACHA_SALT_SIZE 4
29: #define CHACHA_KEY_SIZE 32
30: #define POLY_BLOCK_SIZE 16
31: #define POLY_ICV_SIZE 16
32:
33: typedef struct chapoly_drv_t chapoly_drv_t;
34:
35: /**
36: * ChaCha20/Poly1305 backend implementation.
37: */
38: struct chapoly_drv_t {
39:
40: /**
41: * Set the ChaCha20 encryption key.
42: *
43: * @param constant 16 byte key constant to use
44: * @param key 32 byte encryption key
45: * @param salt 4 byte nonce salt
46: * @return TRUE if key set
47: */
48: bool (*set_key)(chapoly_drv_t *this, u_char *constant, u_char *key,
49: u_char *salt);
50:
51: /**
52: * Start an AEAD en/decryption session, reset state.
53: *
54: * @param iv 8 byte initialization vector for nonce
55: * @return TRUE if initialized
56: */
57: bool (*init)(chapoly_drv_t *this, u_char *iv);
58:
59: /**
60: * Poly1305 update multiple blocks.
61: *
62: * @param data data to update Poly1305 for
63: * @param blocks number of 16-byte blocks to process
64: * @return TRUE if updated
65: */
66: bool (*poly)(chapoly_drv_t *this, u_char *data, u_int blocks);
67:
68: /**
69: * Create a single ChaCha20 keystream block.
70: *
71: * @param stream 64-byte block to write key stream data to
72: * @return TRUE if keystream returned
73: */
74: bool (*chacha)(chapoly_drv_t *this, u_char *stream);
75:
76: /**
77: * Encrypt multiple blocks of data inline, update Poly1305.
78: *
79: * @param data data to process
80: * @param blocks number of 64-byte blocks to process
81: * @return TRUE if encrypted
82: */
83: bool (*encrypt)(chapoly_drv_t *this, u_char *data, u_int blocks);
84:
85: /**
86: * Decrypt multiple blocks of data inline, update Poly1305.
87: *
88: * @param data data to process
89: * @param blocks number of 64-byte blocks to process
90: * @return TRUE if decrypted
91: */
92: bool (*decrypt)(chapoly_drv_t *this, u_char *data, u_int blocks);
93:
94: /**
95: * End a AEAD encryption session, return MAC.
96: *
97: * @param mac 16-byte block to write MAC to
98: * @return TRUE if MAC returned
99: */
100: bool (*finish)(chapoly_drv_t *this, u_char *mac);
101:
102: /**
103: * Destroy a chapoly_drv_t.
104: */
105: void (*destroy)(chapoly_drv_t *this);
106: };
107:
108: /**
109: * Create a chapoly_drv instance.
110: */
111: chapoly_drv_t *chapoly_drv_probe();
112:
113: #endif /** CHAPOLY_DRV_H_ @}*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>