3 #ifndef __ZMQ_CURVE_MECHANISM_BASE_HPP_INCLUDED__
4 #define __ZMQ_CURVE_MECHANISM_BASE_HPP_INCLUDED__
8 #if defined(ZMQ_USE_LIBSODIUM)
12 #if crypto_box_NONCEBYTES != 24 || crypto_box_PUBLICKEYBYTES != 32 \
13 || crypto_box_SECRETKEYBYTES != 32 || crypto_box_ZEROBYTES != 32 \
14 || crypto_box_BOXZEROBYTES != 16 || crypto_secretbox_NONCEBYTES != 24 \
15 || crypto_secretbox_ZEROBYTES != 32 || crypto_secretbox_BOXZEROBYTES != 16
16 #error "CURVE library not built properly"
26 class curve_encoding_t
29 curve_encoding_t (
const char *encode_nonce_prefix_,
30 const char *decode_nonce_prefix_,
31 const bool downgrade_sub_);
33 int encode (msg_t *msg_);
34 int decode (msg_t *msg_,
int *error_event_code_);
36 uint8_t *get_writable_precom_buffer () {
return _cn_precom; }
37 const uint8_t *get_precom_buffer ()
const {
return _cn_precom; }
39 typedef uint64_t nonce_t;
41 nonce_t get_and_inc_nonce () {
return _cn_nonce++; }
42 void set_peer_nonce (nonce_t peer_nonce_) { _cn_peer_nonce = peer_nonce_; };
45 int check_validity (msg_t *msg_,
int *error_event_code_);
47 const char *_encode_nonce_prefix;
48 const char *_decode_nonce_prefix;
51 nonce_t _cn_peer_nonce;
54 uint8_t _cn_precom[crypto_box_BEFORENMBYTES];
56 const bool _downgrade_sub;
61 class curve_mechanism_base_t :
public virtual mechanism_base_t,
62 public curve_encoding_t
65 curve_mechanism_base_t (session_base_t *session_,
67 const char *encode_nonce_prefix_,
68 const char *decode_nonce_prefix_,
69 const bool downgrade_sub_);