Debian Codegraph @

src/security.h

raw symbols SCIP
1 /* SPDX-License-Identifier: BSD-2-Clause */cxx . . $ `<file>/src/security.h`/
2 /*
3 * Copyright (C) 2023 Linutronix GmbH
4 * Author Kurt Kanzenbach <[email protected]>
5 */
6
7 #ifndef _SECURITY_H_
8 #define _SECURITY_H_cxx . . $ `src/security.h:8:9`!
9
10 #include <openssl/conf.h>
11 #include <openssl/err.h>
12 #include <openssl/evp.h>
13
14 #include <stddef.h>
15 #include <stdint.h>
16
17 enum security_modecxx . . $ security_mode# {
18 SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE., /* No authentification or enryption */
19 SECURITY_MODE_AOcxx . . $ SECURITY_MODE_AO., /* Authentification only */
20 SECURITY_MODE_AEcxx . . $ SECURITY_MODE_AE., /* Authentification and encryption */
21 };
22
23 enum security_algorithmcxx . . $ security_algorithm# {
24 SECURITY_ALGORITHM_AES256_GCMcxx . . $ SECURITY_ALGORITHM_AES256_GCM.,
25 SECURITY_ALGORITHM_AES128_GCMcxx . . $ SECURITY_ALGORITHM_AES128_GCM.,
26 SECURITY_ALGORITHM_CHACHA20_POLY1305cxx . . $ SECURITY_ALGORITHM_CHACHA20_POLY1305.,
27 };
28
29 static inline const char *security_mode_to_stringcxx . . $ security_mode_to_string(e77cca8122f94190).(enum security_modecxx . . $ security_mode# mode)
30 {
31 switch (mode) {
32 case SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE.:
33 return "None";
34 case SECURITY_MODE_AOcxx . . $ SECURITY_MODE_AO.:
35 return "Authentication";
36 case SECURITY_MODE_AEcxx . . $ SECURITY_MODE_AE.:
37 return "Authentication and Encryption";
38 default:
39 return "Unknown";
40 }
41 }
42
43 static inline const char *security_algorithm_to_stringcxx . . $ security_algorithm_to_string(82541b8b9ae66d0b).(enum security_algorithmcxx . . $ security_algorithm# algorithm)
44 {
45 switch (algorithm) {
46 case SECURITY_ALGORITHM_AES256_GCMcxx . . $ SECURITY_ALGORITHM_AES256_GCM.:
47 return "AES-256-GCM";
48 case SECURITY_ALGORITHM_AES128_GCMcxx . . $ SECURITY_ALGORITHM_AES128_GCM.:
49 return "AES-128-GCM";
50 case SECURITY_ALGORITHM_CHACHA20_POLY1305cxx . . $ SECURITY_ALGORITHM_CHACHA20_POLY1305.:
51 return "CHACHA20-POLY1305";
52 default:
53 return "Unknown";
54 }
55 }
56
57 #define SECURITY_IV_LENcxx . . $ `src/security.h:57:9`! 12
58 #define SECURITY_IV_PREFIX_LENcxx . . $ `src/security.h:58:9`! 6
59 #define SECURITY_IV_COUNTER_LENcxx . . $ `src/security.h:59:9`! 6
60
61 struct security_ivcxx . . $ security_iv# {
62 unsigned char iv_prefixcxx . . $ security_iv#iv_prefix.[SECURITY_IV_PREFIX_LENcxx . . $ `src/security.h:58:9`!];
63 uint64_tcxx . . $ uint64_t# countercxx . . $ security_iv#counter.;
64 } __attribute__((packed));
65
66 struct security_contextcxx . . $ security_context# {
67 enum security_algorithmcxx . . $ security_algorithm# algorithmcxx . . $ security_context#algorithm.;
68 EVP_CIPHER_CTXcxx . . $ EVP_CIPHER_CTX# *ctxcxx . . $ security_context#ctx.;
69 EVP_CIPHERcxx . . $ EVP_CIPHER# *ciphercxx . . $ security_context#cipher.;
70 };
71
72 struct security_contextcxx . . $ security_context# *security_initcxx . . $ security_init(5357658aae651c5a).(enum security_algorithmcxx . . $ security_algorithm# algorithm, const unsigned char *key);
73 void security_exitcxx . . $ security_exit(180fdc1b6a791d79).(struct security_contextcxx . . $ security_context# *context);
74
75 int security_encryptcxx . . $ security_encrypt(9b35fdd6c8552c6f).(struct security_contextcxx . . $ security_context# *context, const unsigned char *plaintext,
76 size_t plaintext_length, const unsigned char *associated_data,
77 size_t associated_data_length, const unsigned char *iv,
78 unsigned char *ciphertext, unsigned char *tag);
79
80 int security_decryptcxx . . $ security_decrypt(7be7b758f68f59b2).(struct security_contextcxx . . $ security_context# *context, const unsigned char *ciphertext,
81 size_t ciphertext_length, const unsigned char *associated_data,
82 size_t associated_data_length, unsigned char *tag, const unsigned char *iv,
83 unsigned char *plaintext);
84
85 #endif /* _SECURITY_H_ */