www.pudn.com > TomCrypt.rar > goozo_crypt.cpp
//---------------------------------------------------------------------------
#include "goozo_crypt.h"
//---------------------------------------------------------------------------
ecc_key ltc_ecc_mykey;
void ltc_eax_encrypt(const struct ltc_cipher_descriptor *cipher,
AnsiString key,AnsiString nonce,
const unsigned char *pt,
unsigned char *ct, unsigned length){
int cn=register_cipher(cipher);
if(cn==-1)throw Exception("wrong cipher");
unsigned char tkey[32]={0};
unsigned char tnonce[32]={0};
memcpy(tkey,key.c_str(),key.Length());
memcpy(tnonce,nonce.c_str(),nonce.Length());
eax_state eax;
eax_init( &eax,cn,tkey,32,tnonce,32,NULL,0);
eax_encrypt(&eax, pt, ct, length);
}
//---------------------------------------------------------------------------
void ltc_eax_decrypt(const struct ltc_cipher_descriptor *cipher,
AnsiString key,AnsiString nonce,
const unsigned char *ct,
unsigned char *pt, unsigned length){
int cn=register_cipher(cipher);
if(cn==-1)throw Exception("wrong cipher");
unsigned char tkey[32]={0};
unsigned char tnonce[32]={0};
memcpy(tkey,key.c_str(),key.Length());
memcpy(tnonce,nonce.c_str(),nonce.Length());
eax_state eax;
eax_init( &eax,cn,tkey,32,tnonce,32,NULL,0);
eax_decrypt(&eax, ct, pt, length);
}
//---------------------------------------------------------------------------
AnsiString ltc_hash_mem(const struct ltc_hash_descriptor *hash,
const unsigned char *in, unsigned long length){
int hn=register_hash(hash);
if(hn==-1)throw Exception("wrong hash");
unsigned char out[64];
unsigned long outlen;
hash_memory(hn,in,length,out,&outlen);
AnsiString returnstr;
for(int i=0;i