Debian Codegraph @

src/crypto/psk.h

raw symbols SCIP
1 /* librist. Copyright © 2020 SipRadius LLC. All right reserved.
2 * Author: Gijs Peskens <[email protected]>
3 * Author: Sergio Ammirata, Ph.D. <[email protected]>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8 #ifndef RIST_CRYPTO_PSK_H
9 #define RIST_CRYPTO_PSK_H
10
11 #include "config.h"
12 #include "common/attributes.h"
13 #include "librist/librist_config.h"
14 #if HAVE_MBEDTLS
15 #include "mbedtls/aes.h"
16 #elif HAVE_NETTLE
17 #include <nettle/aes.h>
18 #else
19 #ifdef LINUX_CRYPTO
20 #include "linux-crypto.h"
21 #endif
22 #include "contrib/aes.h"
23 #endif
24 #include <stdint.h>
25 #include <string.h>
26 #include <stdbool.h>
27
28 #ifndef AES_BLOCK_SIZE
29 #define AES_BLOCK_SIZE 16
30 #endif
31
32 struct rist_key {
33 uint32_t key_size;
34 uint8_t gre_nonce[4];
35 uint8_t iv[AES_BLOCK_SIZE];
36 #if HAVE_MBEDTLS
37 size_t aes_offset;
38 unsigned char strean_block[16];
39 mbedtls_aes_context mbedtls_aes_ctx;
40 #elif HAVE_NETTLE
41 struct aes_ctx nettle_ctx;
42 #elif defined(LINUX_CRYPTO)
43 struct linux_crypto *linux_crypto_ctx;
44 #endif
45 uint32_t aes_key_sched[60];//Do we still need this fallback?
46 uint32_t key_rotation;
47 uint64_t used_times;
48 uint8_t password[128];
49 size_t password_len;
50 bool bad_decryption;
51 int bad_count;
52 bool odd;
53 bool csprng_failed; /* set when nonce generation can't draw randomness; encrypt/decrypt short-circuit */
54 };
55
56 RIST_PRIV int _librist_crypto_psk_rist_key_init(struct rist_key *key, uint32_t key_size, uint32_t rotation, const char *password, bool odd);
57 RIST_PRIV int _librist_crypto_psk_rist_key_destroy(struct rist_key *key);
58 RIST_PRIV int _librist_crypto_psk_rist_key_clone(struct rist_key *key_in, struct rist_key *key_out);
59 RIST_PRIV void _librist_crypto_psk_decrypt(struct rist_key *key, uint8_t nonce[4], uint32_t seq_nbe, uint8_t gre_version, const uint8_t inbuf[], uint8_t outbuf[], size_t payload_len);
60 RIST_PRIV void _librist_crypto_psk_encrypt(struct rist_key *key, uint32_t seq_nbe, uint8_t gre_version, const uint8_t inbuf[], uint8_t outbuf[], size_t payload_len);
61 RIST_PRIV void _librist_crypto_psk_encrypt_continue(struct rist_key *key, const uint8_t inbuf[], uint8_t outbuf[], size_t payload_len);
62 RIST_PRIV int _librist_crypto_psk_set_passphrase(struct rist_key *key, const uint8_t *passsphrase, size_t passphrase_len);
63 RIST_PRIV void _librist_crypto_psk_get_passphrase(struct rist_key *key, const uint8_t **passphrase, size_t *passphrase_len);
64 RIST_PRIV void _librist_crypto_aes_ctr(const uint8_t key[], int key_size, uint8_t iv[], const uint8_t inbuf[], uint8_t outbuf[], size_t payload_len);
65 RIST_PRIV void _librist_crypto_psk_preannounce_nonce(struct rist_key *key, const uint8_t nonce[4], uint32_t key_size_bits);
66 #endif