Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
crypt.c File Reference
#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.nosp@m.l@sc.nosp@m.herba.nosp@m..ru More...
 
#define kev   ((ksnetEvMgrClass*)ke)
 

Functions

ksnCryptClassksnCryptInit (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
 

Macro Definition Documentation

#define kev   ((ksnetEvMgrClass*)ke)

Referenced by ksnCryptInit().

#define MODULE   _ANSI_BROWN "net_crypt" _ANSI_NONE

File: crypt.h Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Created on July 14, 2015, 4:04 PM

Referenced by _decrypt(), ksnDecryptPackage(), and ksnEncryptPackage().

Function Documentation

int _decrypt ( ksnCryptClass kcr,
unsigned char *  ciphertext,
int  ciphertext_len,
unsigned char *  key,
unsigned char *  iv,
unsigned char *  plaintext 
)

Decrypt buffer.

Parameters
kcrPointer to ksnCryptClass
ciphertextEncrypted data
ciphertext_lenEncrypted data length
keyKey
ivIV
plaintextDecrypted data
Returns
Decrypted data length

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.

Parameters
packagePointer to package
package_lenPackage length
Returns

References BLOCK_SIZE.

Referenced by ksnCoreProcessPacket(), and trudp_send_event_ack_to_app().

void ksnCryptDestroy ( ksnCryptClass kcr)

Module destroy.

Parameters
kcr

References free(), ksnCryptClass::key, and num_crypt_module.

Referenced by ksnCoreDestroy(), test_1_1(), and test_1_2().

ksnCryptClass* ksnCryptInit ( void *  ke)
void* ksnDecryptPackage ( ksnCryptClass kcr,
void *  package,
size_t  package_len,
size_t *  decrypt_len 
)

Decrypt received package.

Parameters
kcrPointer to ksnetCryptClass object
packagePointer to received package data
package_lenPackage data length
[out]decrypt_lenDecrypted length of package data
Returns
Pointer to decrypted 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.

Parameters
kcrPointer to ksnetCryptClass object
packagePackage to send
package_lenPackage length
bufferBuffer to encrypt, enough to hold encrypted data (package_len + 16)
[out]encrypt_lenLength of encrypted data
Returns
If buffer = NULL this function return allocated pointer to encrypted buffer with data. Should be free after use. Other way it return pointer to input buffer.

References _encrypt(), ksnCryptClass::blocksize, DEBUG_VV, ksnCryptClass::iv, ksnCryptClass::ke, ksnCryptClass::key, ksn_printf, malloc(), and MODULE.

Referenced by test_1_2().

Variable Documentation

int num_crypt_module = 0