Teonet library
0.4.7
|
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include "crypt.h"
#include "ev_mgr.h"
#include "utils/rlutil.h"
Macros | |
#define | MODULE _ANSI_BROWN "net_crypt" _ANSI_NONE |
File: crypt.h Author: Kirill Scherba kiril l@sc herba .ruMore... | |
#define | kev ((ksnetEvMgrClass*)ke) |
Functions | |
ksnCryptClass * | ksnCryptInit (void *ke) |
Module initialize. More... | |
void | ksnCryptDestroy (ksnCryptClass *kcr) |
Module destroy. More... | |
void | handleErrors (void) |
size_t | _encrypt (unsigned char *plaintext, size_t plaintext_len, unsigned char *key, unsigned char *iv, void *ciphertext) |
int | _decrypt (ksnCryptClass *kcr, unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext) |
Decrypt buffer. More... | |
void * | ksnEncryptPackage (ksnCryptClass *kcr, void *package, size_t package_len, void *buffer, size_t *encrypt_len) |
Encrypt KSNet package. More... | |
void * | ksnDecryptPackage (ksnCryptClass *kcr, void *package, size_t package_len, size_t *decrypt_len) |
Decrypt received package. More... | |
int | ksnCheckEncrypted (void *package, size_t package_len) |
Simple check if the packet is encrypted. More... | |
Variables | |
int | num_crypt_module = 0 |
#define kev ((ksnetEvMgrClass*)ke) |
Referenced by ksnCryptInit().
#define MODULE _ANSI_BROWN "net_crypt" _ANSI_NONE |
File: crypt.h Author: Kirill Scherba kiril l@sc herba .ru
Created on July 14, 2015, 4:04 PM
Referenced by _decrypt(), ksnDecryptPackage(), and ksnEncryptPackage().
int _decrypt | ( | ksnCryptClass * | kcr, |
unsigned char * | ciphertext, | ||
int | ciphertext_len, | ||
unsigned char * | key, | ||
unsigned char * | iv, | ||
unsigned char * | plaintext | ||
) |
Decrypt buffer.
kcr | Pointer to ksnCryptClass |
ciphertext | Encrypted data |
ciphertext_len | Encrypted data length |
key | Key |
iv | IV |
plaintext | Decrypted data |
References DEBUG, handleErrors(), ksnCryptClass::ke, ksn_printf, and MODULE.
Referenced by ksnDecryptPackage().
size_t _encrypt | ( | unsigned char * | plaintext, |
size_t | plaintext_len, | ||
unsigned char * | key, | ||
unsigned char * | iv, | ||
void * | ciphertext | ||
) |
References handleErrors().
Referenced by ksnEncryptPackage().
void handleErrors | ( | void | ) |
Referenced by _decrypt(), and _encrypt().
int ksnCheckEncrypted | ( | void * | package, |
size_t | package_len | ||
) |
Simple check if the packet is encrypted.
package | Pointer to package |
package_len | Package length |
References BLOCK_SIZE.
Referenced by ksnCoreProcessPacket(), and trudp_send_event_ack_to_app().
void ksnCryptDestroy | ( | ksnCryptClass * | kcr | ) |
Module destroy.
kcr |
References free(), ksnCryptClass::key, and num_crypt_module.
Referenced by ksnCoreDestroy(), test_1_1(), and test_1_2().
ksnCryptClass* ksnCryptInit | ( | void * | ke | ) |
Module initialize.
References BLOCK_SIZE, ksnCryptClass::blocksize, ksnCryptClass::iv, ksnCryptClass::ke, ke, kev, ksnCryptClass::key, ksnCryptClass::key_len, KEY_SIZE, malloc(), and num_crypt_module.
Referenced by ksnCoreInit(), test_1_1(), and test_1_2().
void* ksnDecryptPackage | ( | ksnCryptClass * | kcr, |
void * | package, | ||
size_t | package_len, | ||
size_t * | decrypt_len | ||
) |
Decrypt received package.
kcr | Pointer to ksnetCryptClass object | |
package | Pointer to received package data | |
package_len | Package data length | |
[out] | decrypt_len | Decrypted length of package data |
References _decrypt(), DEBUG_VV, free(), ksnCryptClass::iv, ksnCryptClass::ke, ksnCryptClass::key, ksn_printf, malloc(), and MODULE.
Referenced by ksnCoreProcessPacket(), and trudp_send_event_ack_to_app().
void* ksnEncryptPackage | ( | ksnCryptClass * | kcr, |
void * | package, | ||
size_t | package_len, | ||
void * | buffer, | ||
size_t * | encrypt_len | ||
) |
Encrypt KSNet package.
kcr | Pointer to ksnetCryptClass object | |
package | Package to send | |
package_len | Package length | |
buffer | Buffer to encrypt, enough to hold encrypted data (package_len + 16) | |
[out] | encrypt_len | Length of encrypted data |
References _encrypt(), ksnCryptClass::blocksize, DEBUG_VV, ksnCryptClass::iv, ksnCryptClass::ke, ksnCryptClass::key, ksn_printf, malloc(), and MODULE.
Referenced by test_1_2().
int num_crypt_module = 0 |
Referenced by ksnCryptDestroy(), ksnCryptInit(), test_1_1(), and test_1_2().