3232// ======
3333// Used for key exchanges.
3434
35- /**
36- * disco_generateKeyPair can be used to generate a X25519 keypair. This is
37- * useful for creating long-term keypairs for a peer.
38- * @kp an initialized keyPair struct. It is over-written by the function.
39- */
40- inline void disco_generateKeyPair (keyPair * kp ) {
41- crypto_box_keypair (kp -> pub , kp -> priv );
42- kp -> isSet = true; // TODO: is this useful? If it is, should we use a magic
43- // number here in case it's not initialized to false?
44- }
45-
46- inline void DH (keyPair mine , keyPair theirs , uint8_t * output ) {
35+ static inline void DH (keyPair mine , keyPair theirs , uint8_t * output ) {
4736 crypto_scalarmult (output , mine .priv , theirs .pub );
4837}
4938
@@ -53,33 +42,37 @@ inline void DH(keyPair mine, keyPair theirs, uint8_t *output) {
5342// Refer to the Disco specification to understand the meaning of these
5443// functions.
5544
56- inline void initializeSymmetric (symmetricState * ss , const char * protocol_name ,
57- size_t protocol_name_len ) {
45+ static inline void initializeSymmetric (symmetricState * ss ,
46+ const char * protocol_name ,
47+ size_t protocol_name_len ) {
5848 strobe_init (& (ss -> strobe ), protocol_name , protocol_name_len );
5949}
6050
61- inline void mixKey (symmetricState * ss , uint8_t * input_key_material ) {
51+ static inline void mixKey (symmetricState * ss , uint8_t * input_key_material ) {
6252 strobe_operate (& (ss -> strobe ), TYPE_AD , input_key_material , 32 , false);
6353 ss -> isKeyed = true;
6454}
6555
66- inline void mixHash (symmetricState * ss , uint8_t * data , size_t data_len ) {
56+ static inline void mixHash (symmetricState * ss , uint8_t * data , size_t data_len ) {
6757 strobe_operate (& (ss -> strobe ), TYPE_AD , data , data_len , false);
6858}
6959
70- inline void mixKeyAndHash (symmetricState * ss , uint8_t * input_key_material ) {
60+ /*
61+ static inline void mixKeyAndHash(symmetricState *ss,
62+ uint8_t *input_key_material) {
7163 strobe_operate(&(ss->strobe), TYPE_AD, input_key_material, 32, false);
7264}
7365
74- inline void getHandshakeHash (symmetricState * ss , uint8_t * result ) {
66+ static inline void getHandshakeHash(symmetricState *ss, uint8_t *result) {
7567 strobe_operate(&(ss->strobe), TYPE_PRF, result, 32, false);
7668}
69+ */
7770
7871// note that this function modifies the plaintext in place, and requires the
7972// plaintext buffer to have 16 more bytes of capacity for the authentication tag
8073// if the symmetric state is keyed
81- inline void encryptAndHash (symmetricState * ss , uint8_t * plaintext ,
82- size_t plaintext_len ) {
74+ static inline void encryptAndHash (symmetricState * ss , uint8_t * plaintext ,
75+ size_t plaintext_len ) {
8376 if (!ss -> isKeyed ) {
8477 strobe_operate (& (ss -> strobe ), TYPE_CLR , plaintext , plaintext_len , false);
8578 } else {
@@ -91,8 +84,8 @@ inline void encryptAndHash(symmetricState *ss, uint8_t *plaintext,
9184
9285// note that the decryption occurs in place, and the the result is
9386// `ciphertext_len-16` in case the symmetric state is keyed.
94- inline bool decryptAndHash (symmetricState * ss , uint8_t * ciphertext ,
95- size_t ciphertext_len ) {
87+ static inline bool decryptAndHash (symmetricState * ss , uint8_t * ciphertext ,
88+ size_t ciphertext_len ) {
9689 if (!ss -> isKeyed ) {
9790 return strobe_operate (& (ss -> strobe ), TYPE_CLR | FLAG_I , ciphertext ,
9891 ciphertext_len , false);
@@ -200,11 +193,9 @@ void disco_Initialize(handshakeState *hs, const char *handshake_pattern,
200193
201194 // handshake_pattern is of the following form:
202195 // "protocol_name \x00 pre-message patterns \x00 message patterns"
203- printf ("debug1:%s\n" , handshake_pattern );
204196 initializeSymmetric (& (hs -> symmetric_state ), handshake_pattern ,
205197 strlen (handshake_pattern ));
206198 handshake_pattern = handshake_pattern + strlen (handshake_pattern ) + 1 ;
207- printf ("debug2:%s\n" , handshake_pattern );
208199
209200 hs -> symmetric_state .isKeyed = false;
210201
0 commit comments