29 #ifndef _SNMP_AUTH_PRIV_H_ 30 #define _SNMP_AUTH_PRIV_H_ 39 #ifdef SNMP_PP_NAMESPACE 43 #define SNMPv3_USM_MAX_KEY_LEN 64 46 #define SNMPv3_AP_MAXLENGTH_AUTHPARAM 128 47 #define SNMPv3_AP_MAXLENGTH_PRIVPARAM 128 50 #define SNMPv3_AP_OUTPUT_LENGTH_MD5 16 51 #define SNMPv3_AP_OUTPUT_LENGTH_SHA 20 53 #define SNMPv3_AP_OUTPUT_LENGTH_SHA224 28 54 #define SNMPv3_AP_OUTPUT_LENGTH_SHA256 32 55 #define SNMPv3_AP_OUTPUT_LENGTH_SHA384 48 56 #define SNMPv3_AP_OUTPUT_LENGTH_SHA512 64 88 virtual int password_to_key(
const unsigned char *password,
89 const unsigned int password_len,
90 const unsigned char *engine_id,
91 const unsigned int engine_id_len,
93 unsigned int *key_len) = 0;
104 virtual int hash(
const unsigned char *data,
105 const unsigned int data_len,
106 unsigned char *digest)
const = 0;
124 virtual int auth_out_msg(
const unsigned char *key,
127 unsigned char *auth_par_ptr) = 0;
153 virtual int auth_inc_msg(
const unsigned char *key,
156 unsigned char *auth_par_ptr,
157 const int auth_par_len) = 0;
162 virtual int get_id()
const = 0;
168 virtual const char *get_id_string()
const = 0;
179 virtual int get_auth_params_len()
const = 0;
184 virtual int get_hash_len()
const = 0;
224 virtual int encrypt(
const unsigned char *key,
225 const unsigned int key_len,
226 const unsigned char *buffer,
227 const unsigned int buffer_len,
228 unsigned char *out_buffer,
229 unsigned int *out_buffer_len,
230 unsigned char *privacy_params,
231 unsigned int *privacy_params_len,
232 const unsigned long engine_boots,
233 const unsigned long engine_time) = 0;
257 virtual int decrypt(
const unsigned char *key,
258 const unsigned int key_len,
259 const unsigned char *buffer,
260 const unsigned int buffer_len,
261 unsigned char *out_buffer,
262 unsigned int *out_buffer_len,
263 const unsigned char *privacy_params,
264 const unsigned int privacy_params_len,
265 const unsigned long engine_boots,
266 const unsigned long engine_time) = 0;
290 virtual int extend_short_key(
const unsigned char *password,
291 const unsigned int password_len,
292 const unsigned char *engine_id,
293 const unsigned int engine_id_len,
295 unsigned int *key_len,
296 const unsigned int max_key_len,
302 virtual int get_id()
const = 0;
307 virtual const char *get_id_string()
const = 0;
318 virtual int get_priv_params_len()
const = 0;
323 virtual int get_min_key_len()
const = 0;
328 virtual void fix_key_len(
unsigned int &key_len)
const = 0;
371 int add_default_modules();
382 int add_auth(
Auth *auth);
391 int del_auth(
const int auth_id);
402 int add_priv(
Priv *priv);
411 int del_priv(
const int priv_id);
417 int password_to_key_auth(
const int auth_prot,
418 const unsigned char *password,
419 const unsigned int password_len,
420 const unsigned char *engine_id,
421 const unsigned int engine_id_len,
423 unsigned int *key_len);
429 int password_to_key_priv(
const int auth_prot,
431 const unsigned char *password,
432 const unsigned int password_len,
433 const unsigned char *engine_id,
434 const unsigned int engine_id_len,
436 unsigned int *key_len);
442 int get_keychange_value(
const int auth_prot,
450 Priv *get_priv(
const int priv_prot);
455 Auth *get_auth(
const int auth_prot);
464 int get_auth_id(
const char *string_id)
const;
473 int get_priv_id(
const char *string_id)
const;
478 int encrypt_msg(
const int priv_prot,
479 const unsigned char *key,
480 const unsigned int key_len,
481 const unsigned char *buffer,
482 const unsigned int buffer_len,
483 unsigned char *out_buffer,
484 unsigned int *out_buffer_len,
485 unsigned char *privacy_params,
486 unsigned int *privacy_params_len,
487 const unsigned long engine_boots,
488 const unsigned long engine_time);
493 int decrypt_msg(
const int priv_prot,
494 const unsigned char *key,
495 const unsigned int key_len,
496 const unsigned char *buffer,
497 const unsigned int buffer_len,
498 unsigned char *out_buffer,
499 unsigned int *out_buffer_len,
500 const unsigned char *privacy_params,
501 const unsigned int privacy_params_len,
502 const unsigned long engine_boots,
503 const unsigned long engine_time);
509 int get_auth_params_len(
const int auth_prot);
515 int get_priv_params_len(
const int priv_prot);
520 int auth_out_msg(
const int auth_prot,
521 const unsigned char *key,
524 unsigned char *auth_par_ptr);
529 int auth_inc_msg(
const int auth_prot,
530 const unsigned char *key,
533 unsigned char *auth_par_ptr,
534 const int auth_par_len);
553 int password_to_key(
const unsigned char *password,
554 const unsigned int password_len,
555 const unsigned char *engine_id,
556 const unsigned int engine_id_len,
558 unsigned int *key_len);
560 int hash(
const unsigned char *data,
561 const unsigned int data_len,
562 unsigned char *digest)
const;
564 int auth_out_msg(
const unsigned char *key,
567 unsigned char *auth_par_ptr);
570 int auth_inc_msg(
const unsigned char *key,
573 unsigned char *auth_par_ptr,
574 const int auth_par_len);
593 #if defined(_USE_LIBTOMCRYPT) && !defined(_USE_OPENSSL) 599 int encrypt(
const unsigned char *key,
600 const unsigned int key_len,
601 const unsigned char *buffer,
602 const unsigned int buffer_len,
603 unsigned char *out_buffer,
604 unsigned int *out_buffer_len,
605 unsigned char *privacy_params,
606 unsigned int *privacy_params_len,
607 const unsigned long engine_boots,
608 const unsigned long engine_time);
610 int decrypt(
const unsigned char *key,
611 const unsigned int key_len,
612 const unsigned char *buffer,
613 const unsigned int buffer_len,
614 unsigned char *out_buffer,
615 unsigned int *out_buffer_len,
616 const unsigned char *privacy_params,
617 const unsigned int privacy_params_len,
618 const unsigned long engine_boots,
619 const unsigned long engine_time);
622 const unsigned int password_len,
623 const unsigned char *engine_id,
624 const unsigned int engine_id_len,
626 unsigned int *key_len,
627 const unsigned int max_key_len,
646 { key_len = (key_len >= 16 ? 16 : 0); };
659 int encrypt(
const unsigned char *key,
660 const unsigned int key_len,
661 const unsigned char *buffer,
662 const unsigned int buffer_len,
663 unsigned char *out_buffer,
664 unsigned int *out_buffer_len,
665 unsigned char *privacy_params,
666 unsigned int *privacy_params_len,
667 const unsigned long engine_boots,
668 const unsigned long engine_time);
670 int decrypt(
const unsigned char *key,
671 const unsigned int key_len,
672 const unsigned char *buffer,
673 const unsigned int buffer_len,
674 unsigned char *out_buffer,
675 unsigned int *out_buffer_len,
676 const unsigned char *privacy_params,
677 const unsigned int privacy_params_len,
678 const unsigned long engine_boots,
679 const unsigned long engine_time);
682 const unsigned int password_len,
683 const unsigned char *engine_id,
684 const unsigned int engine_id_len,
686 unsigned int *key_len,
687 const unsigned int max_key_len,
696 { key_len = (key_len >= 16 ? 16 : 0); };
702 #if defined(_USE_LIBTOMCRYPT) || defined(_USE_OPENSSL) 715 int encrypt(
const unsigned char *key,
716 const unsigned int key_len,
717 const unsigned char *buffer,
718 const unsigned int buffer_len,
719 unsigned char *out_buffer,
720 unsigned int *out_buffer_len,
721 unsigned char *privacy_params,
722 unsigned int *privacy_params_len,
723 const unsigned long engine_boots,
724 const unsigned long engine_time);
726 int decrypt(
const unsigned char *key,
727 const unsigned int key_len,
728 const unsigned char *buffer,
729 const unsigned int buffer_len,
730 unsigned char *out_buffer,
731 unsigned int *out_buffer_len,
732 const unsigned char *privacy_params,
733 const unsigned int privacy_params_len,
734 const unsigned long engine_boots,
735 const unsigned long engine_time);
737 int extend_short_key(
const unsigned char *password,
738 const unsigned int password_len,
739 const unsigned char *engine_id,
740 const unsigned int engine_id_len,
742 unsigned int *key_len,
743 const unsigned int max_key_len,
747 const char *get_id_string()
const;
751 { key_len = (key_len >= (unsigned)key_bytes ? key_bytes : 0); };
757 #if defined(_USE_LIBTOMCRYPT) && !defined(_USE_OPENSSL) 777 int extend_short_key(
const unsigned char *password,
778 const unsigned int password_len,
779 const unsigned char *engine_id,
780 const unsigned int engine_id_len,
782 unsigned int *key_len,
783 const unsigned int max_key_len,
786 const char *get_id_string()
const;
787 int get_id()
const {
return own_aes_type; }
789 static int map_aes_type(
const int t);
795 #endif // _USE_LIBTOMCRYPT or _USE_OPENSSL 804 #define TRIPLEDES_EDE_KEY_LEN 32 810 #if defined(_USE_LIBTOMCRYPT) && !defined(_USE_OPENSSL) 817 int encrypt(
const unsigned char *key,
818 const unsigned int key_len,
819 const unsigned char *buffer,
820 const unsigned int buffer_len,
821 unsigned char *out_buffer,
822 unsigned int *out_buffer_len,
823 unsigned char *privacy_params,
824 unsigned int *privacy_params_len,
825 const unsigned long engine_boots,
826 const unsigned long engine_time);
828 int decrypt(
const unsigned char *key,
829 const unsigned int key_len,
830 const unsigned char *buffer,
831 const unsigned int buffer_len,
832 unsigned char *out_buffer,
833 unsigned int *out_buffer_len,
834 const unsigned char *privacy_params,
835 const unsigned int privacy_params_len,
836 const unsigned long engine_boots,
837 const unsigned long engine_time);
839 int extend_short_key(
const unsigned char *password,
840 const unsigned int password_len,
841 const unsigned char *engine_id,
842 const unsigned int engine_id_len,
844 unsigned int *key_len,
845 const unsigned int max_key_len,
860 #endif // _USE_3DES_EDE 873 int password_to_key(
const unsigned char *password,
874 const unsigned int password_len,
875 const unsigned char *engine_id,
876 const unsigned int engine_id_len,
878 unsigned int *key_len);
880 int hash(
const unsigned char *data,
881 const unsigned int data_len,
882 unsigned char *digest)
const;
884 int auth_out_msg(
const unsigned char *key,
887 unsigned char *auth_par_ptr);
889 int auth_inc_msg(
const unsigned char *key,
892 unsigned char *auth_par_ptr,
893 const int auth_par_len);
902 virtual int init() = 0;
903 virtual int update(
const unsigned char *data,
904 const unsigned int data_len) = 0;
905 virtual int final(
unsigned char *digest) = 0;
907 virtual int get_key_length()
const = 0;
909 virtual int get_block_size()
const = 0;
912 virtual Hasher *get_hasher()
const = 0;
938 Hasher *get_hasher()
const;
941 #if defined(_USE_OPENSSL) 965 Hasher *get_hasher()
const;
987 Hasher *get_hasher()
const;
1009 Hasher *get_hasher()
const;
1030 Hasher *get_hasher()
const;
1033 #endif // defined(_USE_OPENSSL) 1035 #ifdef SNMP_PP_NAMESPACE 1041 #endif // _SNMP_AUTH_PRIV_H_ Class that holds all authentication and privacy protocols for a snmp entity.
Authentication module using SHA1 (usmHMACSHAAuthProtocol).
const char * get_id_string() const
Get the unique identifier string of the authentication protocol.
int get_id() const
Get the unique id of the authentication protocol.
int get_id() const
Get the unique id of the authentication protocol.
#define SNMP_PRIVPROTOCOL_IDEA
IDEA (non standard)
int get_id() const
Get the uniqhe id of the privacy protocol.
int get_hash_len() const
Get length of a hash output.
int get_min_key_len() const
Get the minimum key length needed for encryption and decryption.
#define SNMPv3_AP_OUTPUT_LENGTH_MD5
int priv_size
current size of the priv array
Authentication module using SHA2 (usmHMAC128SHA224AuthProtocol).
int get_priv_params_len() const
Get the maximum length that is needed for the msgPrivacyParameters field.
#define SNMP_AUTHPROTOCOL_HMACMD5
HMAC-MD5.
void fix_key_len(unsigned int &key_len) const
Decrease a too long length to the right value.
Authentication module using SHA2 (usmHMAC192SHA256AuthProtocol).
Base class for SHA authentication modules.
int get_hash_len() const
Get length of a hash output.
#define SNMP_AUTHPROTOCOL_HMAC128SHA224
HMAC-128-SHA-224.
Encryption module using AES but using non standard key extension.
int get_hash_len() const
Get length of a hash output.
int get_min_key_len() const
Get the minimum key length needed for encryption and decryption.
void fix_key_len(unsigned int &key_len) const
Decrease a too long length to the right value.
int extend_short_key(const unsigned char *password, const unsigned int password_len, const unsigned char *engine_id, const unsigned int engine_id_len, unsigned char *key, unsigned int *key_len, const unsigned int max_key_len, Auth *auth)
Extend a localized key that is too short.
const char * get_id_string() const
Get the unique identifier string of the authentication protocol.
Authentication module using SHA2 (usmHMAC256SHA384AuthProtocol).
#define SNMPv3_AP_OUTPUT_LENGTH_SHA512
int get_id() const
Get the unique id of the authentication protocol.
int get_id() const
Get the uniqhe id of the privacy protocol.
pp_uint64 salt
current salt value (64 bits)
AuthPtr * auth
Array of pointers to Auth-objects.
int get_hash_len() const
Get length of a hash output.
int get_auth_params_len() const
Get the maximum length that is needed for the msgAuthenticationParameters field.
int get_priv_params_len() const
Get the maximum length that is needed for the msgPrivacyParameters field.
PrivPtr * priv
Array of pointers to Priv-objects.
const char * get_id_string() const
Get the unique identifier string of the privacy protocol.
int get_id() const
Get the uniqhe id of the privacy protocol.
int get_id() const
Get the unique id of the authentication protocol.
int get_min_key_len() const
Get the minimum key length needed for encryption and decryption.
const char * get_id_string() const
Get the unique identifier string of the privacy protocol.
int get_id() const
Get the unique id of the authentication protocol.
#define TRIPLEDES_EDE_KEY_LEN
Encryption module using TripleDES-EDE KEY.
Encryption module using IDEA.
Abstract class for priv modules.
int get_priv_params_len() const
Get the maximum length that is needed for the msgPrivacyParameters field.
#define SNMP_AUTHPROTOCOL_HMAC384SHA512
HMAC-384-SHA-512.
#define SNMPv3_AP_OUTPUT_LENGTH_SHA224
unsigned long long pp_uint64
#define SNMPv3_AP_OUTPUT_LENGTH_SHA256
void fix_key_len(unsigned int &key_len) const
Decrease a too long length to the right value.
const char * get_id_string() const
Get the unique identifier string of the authentication protocol.
int get_id() const
Get the uniqhe id of the privacy protocol.
Authentication module using SHA2 (usmHMAC384SHA512AuthProtocol).
Abstract class for auth modules.
int get_hash_len() const
Get length of a hash output.
#define SNMP_AUTHPROTOCOL_HMAC192SHA256
HMAC-192-SHA-256.
virtual void set_salt(pp_uint64 *new_salt)
Set the pointer to the salt that should be used.
int get_id() const
Get the unique id of the authentication protocol.
Encryption module using DES.
int get_priv_params_len() const
Get the maximum length that is needed for the msgPrivacyParameters field.
Encryption module using AES.
void fix_key_len(unsigned int &key_len) const
Decrease a too long length to the right value.
virtual void set_salt(pp_uint64 *new_salt)
Set the pointer to the salt that should be used.
#define SNMPv3_AP_OUTPUT_LENGTH_SHA384
#define SNMP_PRIVPROTOCOL_3DESEDE
3DES (expired draft standard)
int get_hash_len() const
Get length of a hash output.
#define SNMP_AUTHPROTOCOL_HMACSHA
HMAC-SHA.
int get_id() const
Get the uniqhe id of the privacy protocol.
#define SNMPv3_AP_OUTPUT_LENGTH_SHA
Authentication module using MD5.
const char * get_id_string() const
Get the unique identifier string of the authentication protocol.
int get_auth_params_len() const
Get the maximum length that is needed for the msgAuthenticationParameters field.
int get_auth_params_len() const
Get the maximum length that is needed for the msgAuthenticationParameters field.
const char * get_id_string() const
Get the unique identifier string of the authentication protocol.
#define SNMP_AUTHPROTOCOL_HMAC256SHA384
HMAC-256-SHA-384.
int auth_size
current size of the auth array
const char * get_id_string() const
Get the unique identifier string of the privacy protocol.
int get_auth_params_len() const
Get the maximum length that is needed for the msgAuthenticationParameters field.
int get_auth_params_len() const
Get the maximum length that is needed for the msgAuthenticationParameters field.
int get_auth_params_len() const
Get the maximum length that is needed for the msgAuthenticationParameters field.
int extend_short_key(const unsigned char *password, const unsigned int password_len, const unsigned char *engine_id, const unsigned int engine_id_len, unsigned char *key, unsigned int *key_len, const unsigned int max_key_len, Auth *auth)
Extend a localized key that is too short.
int get_min_key_len() const
Get the minimum key length needed for encryption and decryption.
const char * get_id_string() const
Get the unique identifier string of the authentication protocol.
#define SNMP_PRIVPROTOCOL_DES
DES.