Noise-C
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
constants.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef NOISE_CONSTANTS_H
24 #define NOISE_CONSTANTS_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* Build an identifier. Deliberately designed to fit into a 16-bit
31  integer on 8-bit and 16-bit embedded systems */
32 #define NOISE_ID(ch,num) ((((int)(ch)) << 8) | ((int)(num)))
33 
34 /* AEAD cipher algorithms */
35 #define NOISE_CIPHER_NONE 0
36 #define NOISE_CIPHER_CATEGORY NOISE_ID('C', 0)
37 #define NOISE_CIPHER_CHACHAPOLY NOISE_ID('C', 1)
38 #define NOISE_CIPHER_AESGCM NOISE_ID('C', 2)
39 
40 /* Hash algorithms */
41 #define NOISE_HASH_NONE 0
42 #define NOISE_HASH_CATEGORY NOISE_ID('H', 0)
43 #define NOISE_HASH_BLAKE2s NOISE_ID('H', 1)
44 #define NOISE_HASH_BLAKE2b NOISE_ID('H', 2)
45 #define NOISE_HASH_SHA256 NOISE_ID('H', 3)
46 #define NOISE_HASH_SHA512 NOISE_ID('H', 4)
47 
48 /* Diffie-Hellman algorithms */
49 #define NOISE_DH_NONE 0
50 #define NOISE_DH_CATEGORY NOISE_ID('D', 0)
51 #define NOISE_DH_CURVE25519 NOISE_ID('D', 1)
52 #define NOISE_DH_CURVE448 NOISE_ID('D', 2)
53 #define NOISE_DH_NEWHOPE NOISE_ID('D', 3)
54 
55 /* Handshake patterns */
56 #define NOISE_PATTERN_NONE 0
57 #define NOISE_PATTERN_CATEGORY NOISE_ID('P', 0)
58 #define NOISE_PATTERN_N NOISE_ID('P', 1)
59 #define NOISE_PATTERN_X NOISE_ID('P', 2)
60 #define NOISE_PATTERN_K NOISE_ID('P', 3)
61 #define NOISE_PATTERN_NN NOISE_ID('P', 4)
62 #define NOISE_PATTERN_NK NOISE_ID('P', 5)
63 #define NOISE_PATTERN_NX NOISE_ID('P', 6)
64 #define NOISE_PATTERN_XN NOISE_ID('P', 7)
65 #define NOISE_PATTERN_XK NOISE_ID('P', 8)
66 #define NOISE_PATTERN_XX NOISE_ID('P', 9)
67 #define NOISE_PATTERN_KN NOISE_ID('P', 10)
68 #define NOISE_PATTERN_KK NOISE_ID('P', 11)
69 #define NOISE_PATTERN_KX NOISE_ID('P', 12)
70 #define NOISE_PATTERN_IN NOISE_ID('P', 13)
71 #define NOISE_PATTERN_IK NOISE_ID('P', 14)
72 #define NOISE_PATTERN_IX NOISE_ID('P', 15)
73 #define NOISE_PATTERN_XX_FALLBACK NOISE_ID('P', 16)
74 #define NOISE_PATTERN_X_NOIDH NOISE_ID('P', 32)
75 #define NOISE_PATTERN_NX_NOIDH NOISE_ID('P', 33)
76 #define NOISE_PATTERN_XX_NOIDH NOISE_ID('P', 34)
77 #define NOISE_PATTERN_KX_NOIDH NOISE_ID('P', 35)
78 #define NOISE_PATTERN_IK_NOIDH NOISE_ID('P', 36)
79 #define NOISE_PATTERN_IX_NOIDH NOISE_ID('P', 37)
80 #define NOISE_PATTERN_NN_HFS NOISE_ID('P', 48)
81 #define NOISE_PATTERN_NK_HFS NOISE_ID('P', 49)
82 #define NOISE_PATTERN_NX_HFS NOISE_ID('P', 50)
83 #define NOISE_PATTERN_XN_HFS NOISE_ID('P', 51)
84 #define NOISE_PATTERN_XK_HFS NOISE_ID('P', 52)
85 #define NOISE_PATTERN_XX_HFS NOISE_ID('P', 53)
86 #define NOISE_PATTERN_KN_HFS NOISE_ID('P', 54)
87 #define NOISE_PATTERN_KK_HFS NOISE_ID('P', 55)
88 #define NOISE_PATTERN_KX_HFS NOISE_ID('P', 56)
89 #define NOISE_PATTERN_IN_HFS NOISE_ID('P', 57)
90 #define NOISE_PATTERN_IK_HFS NOISE_ID('P', 58)
91 #define NOISE_PATTERN_IX_HFS NOISE_ID('P', 59)
92 #define NOISE_PATTERN_XX_FALLBACK_HFS NOISE_ID('P', 60)
93 #define NOISE_PATTERN_NX_NOIDH_HFS NOISE_ID('P', 80)
94 #define NOISE_PATTERN_XX_NOIDH_HFS NOISE_ID('P', 81)
95 #define NOISE_PATTERN_KX_NOIDH_HFS NOISE_ID('P', 82)
96 #define NOISE_PATTERN_IK_NOIDH_HFS NOISE_ID('P', 83)
97 #define NOISE_PATTERN_IX_NOIDH_HFS NOISE_ID('P', 84)
98 
99 /* Protocol name prefixes */
100 #define NOISE_PREFIX_NONE 0
101 #define NOISE_PREFIX_CATEGORY NOISE_ID('N', 0)
102 #define NOISE_PREFIX_STANDARD NOISE_ID('N', 1)
103 #define NOISE_PREFIX_PSK NOISE_ID('N', 2)
104 
105 /* Signature algorithms */
106 #define NOISE_SIGN_NONE 0
107 #define NOISE_SIGN_CATEGORY NOISE_ID('S', 0)
108 #define NOISE_SIGN_ED25519 NOISE_ID('S', 1)
109 
110 /* Role for this end of the communications */
111 #define NOISE_ROLE_INITIATOR NOISE_ID('R', 1)
112 #define NOISE_ROLE_RESPONDER NOISE_ID('R', 2)
113 
114 /* Actions for the application to take, as directed by the HandshakeState */
115 #define NOISE_ACTION_NONE 0
116 #define NOISE_ACTION_WRITE_MESSAGE NOISE_ID('A', 1)
117 #define NOISE_ACTION_READ_MESSAGE NOISE_ID('A', 2)
118 #define NOISE_ACTION_FAILED NOISE_ID('A', 3)
119 #define NOISE_ACTION_SPLIT NOISE_ID('A', 4)
120 #define NOISE_ACTION_COMPLETE NOISE_ID('A', 5)
121 
122 /* Padding modes for noise_cipherstate_pad() */
123 #define NOISE_PADDING_ZERO NOISE_ID('G', 1)
124 #define NOISE_PADDING_RANDOM NOISE_ID('G', 2)
125 
126 /* Key fingerprint types */
127 #define NOISE_FINGERPRINT_BASIC NOISE_ID('F', 1)
128 #define NOISE_FINGERPRINT_FULL NOISE_ID('F', 2)
129 
130 /* Error codes */
131 #define NOISE_ERROR_NONE 0
132 #define NOISE_ERROR_NO_MEMORY NOISE_ID('E', 1)
133 #define NOISE_ERROR_UNKNOWN_ID NOISE_ID('E', 2)
134 #define NOISE_ERROR_UNKNOWN_NAME NOISE_ID('E', 3)
135 #define NOISE_ERROR_MAC_FAILURE NOISE_ID('E', 4)
136 #define NOISE_ERROR_NOT_APPLICABLE NOISE_ID('E', 5)
137 #define NOISE_ERROR_SYSTEM NOISE_ID('E', 6)
138 #define NOISE_ERROR_REMOTE_KEY_REQUIRED NOISE_ID('E', 7)
139 #define NOISE_ERROR_LOCAL_KEY_REQUIRED NOISE_ID('E', 8)
140 #define NOISE_ERROR_PSK_REQUIRED NOISE_ID('E', 9)
141 #define NOISE_ERROR_INVALID_LENGTH NOISE_ID('E', 10)
142 #define NOISE_ERROR_INVALID_PARAM NOISE_ID('E', 11)
143 #define NOISE_ERROR_INVALID_STATE NOISE_ID('E', 12)
144 #define NOISE_ERROR_INVALID_NONCE NOISE_ID('E', 13)
145 #define NOISE_ERROR_INVALID_PRIVATE_KEY NOISE_ID('E', 14)
146 #define NOISE_ERROR_INVALID_PUBLIC_KEY NOISE_ID('E', 15)
147 #define NOISE_ERROR_INVALID_FORMAT NOISE_ID('E', 16)
148 #define NOISE_ERROR_INVALID_SIGNATURE NOISE_ID('E', 17)
149 
150 /* Maximum length of a packet payload */
151 #define NOISE_MAX_PAYLOAD_LEN 65535
152 
153 /* Maximum length of a protocol name string */
154 #define NOISE_MAX_PROTOCOL_NAME 128
155 
156 /* Recommended maximum length for fingerprint buffers */
157 #define NOISE_MAX_FINGERPRINT_LEN 256
158 
159 #ifdef __cplusplus
160 };
161 #endif
162 
163 #endif