Browse Source

crypto: split crypto classes

v0.11.0-release
Fedor Indutny 12 years ago
parent
commit
a15cc93ae3
  1. 344
      src/node_crypto.cc
  2. 232
      src/node_crypto.h

344
src/node_crypto.cc

@ -2036,9 +2036,7 @@ Handle<Value> Connection::SetSNICallback(const Arguments& args) {
#endif
class Cipher : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target) {
void Cipher::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@ -2055,7 +2053,7 @@ class Cipher : public ObjectWrap {
}
bool CipherInit(char* cipherType, char* key_buf, int key_buf_len) {
bool Cipher:: CipherInit(char* cipherType, char* key_buf, int key_buf_len) {
cipher = EVP_get_cipherbyname(cipherType);
if(!cipher) {
fprintf(stderr, "node-crypto : Unknown cipher %s\n", cipherType);
@ -2081,7 +2079,7 @@ class Cipher : public ObjectWrap {
}
bool CipherInitIv(char* cipherType,
bool Cipher::CipherInitIv(char* cipherType,
char* key,
int key_len,
char* iv,
@ -2112,19 +2110,25 @@ class Cipher : public ObjectWrap {
return true;
}
int CipherUpdate(char* data, int len, unsigned char** out, int* out_len) {
int Cipher::CipherUpdate(char* data,
int len,
unsigned char** out,
int* out_len) {
if (!initialised_) return 0;
*out_len=len+EVP_CIPHER_CTX_block_size(&ctx);
*out= new unsigned char[*out_len];
return EVP_CipherUpdate(&ctx, *out, out_len, (unsigned char*)data, len);
}
int SetAutoPadding(bool auto_padding) {
int Cipher::SetAutoPadding(bool auto_padding) {
if (!initialised_) return 0;
return EVP_CIPHER_CTX_set_padding(&ctx, auto_padding ? 1 : 0);
}
int CipherFinal(unsigned char** out, int *out_len) {
int Cipher::CipherFinal(unsigned char** out, int *out_len) {
if (!initialised_) return 0;
*out = new unsigned char[EVP_CIPHER_CTX_block_size(&ctx)];
int r = EVP_CipherFinal_ex(&ctx,*out, out_len);
@ -2134,9 +2138,7 @@ class Cipher : public ObjectWrap {
}
protected:
static Handle<Value> New(const Arguments& args) {
Handle<Value> Cipher::New(const Arguments& args) {
HandleScope scope;
Cipher *cipher = new Cipher();
@ -2144,7 +2146,7 @@ class Cipher : public ObjectWrap {
return args.This();
}
static Handle<Value> CipherInit(const Arguments& args) {
Handle<Value> Cipher::CipherInit(const Arguments& args) {
HandleScope scope;
Cipher *cipher = ObjectWrap::Unwrap<Cipher>(args.This());
@ -2181,7 +2183,7 @@ class Cipher : public ObjectWrap {
}
static Handle<Value> CipherInitIv(const Arguments& args) {
Handle<Value> Cipher::CipherInitIv(const Arguments& args) {
Cipher *cipher = ObjectWrap::Unwrap<Cipher>(args.This());
HandleScope scope;
@ -2232,7 +2234,8 @@ class Cipher : public ObjectWrap {
return args.This();
}
static Handle<Value> CipherUpdate(const Arguments& args) {
Handle<Value> Cipher::CipherUpdate(const Arguments& args) {
Cipher *cipher = ObjectWrap::Unwrap<Cipher>(args.This());
HandleScope scope;
@ -2259,7 +2262,8 @@ class Cipher : public ObjectWrap {
return scope.Close(outString);
}
static Handle<Value> SetAutoPadding(const Arguments& args) {
Handle<Value> Cipher::SetAutoPadding(const Arguments& args) {
HandleScope scope;
Cipher *cipher = ObjectWrap::Unwrap<Cipher>(args.This());
@ -2268,7 +2272,8 @@ class Cipher : public ObjectWrap {
return Undefined();
}
static Handle<Value> CipherFinal(const Arguments& args) {
Handle<Value> Cipher::CipherFinal(const Arguments& args) {
Cipher *cipher = ObjectWrap::Unwrap<Cipher>(args.This());
HandleScope scope;
@ -2291,31 +2296,8 @@ class Cipher : public ObjectWrap {
return scope.Close(outString);
}
Cipher () : ObjectWrap ()
{
initialised_ = false;
}
~Cipher () {
if (initialised_) {
EVP_CIPHER_CTX_cleanup(&ctx);
}
}
private:
EVP_CIPHER_CTX ctx; /* coverity[member_decl] */
const EVP_CIPHER *cipher; /* coverity[member_decl] */
bool initialised_;
};
class Decipher : public ObjectWrap {
public:
static void
Initialize (v8::Handle<v8::Object> target)
{
void Decipher::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@ -2332,7 +2314,8 @@ class Decipher : public ObjectWrap {
target->Set(String::NewSymbol("Decipher"), t->GetFunction());
}
bool DecipherInit(char* cipherType, char* key_buf, int key_buf_len) {
bool Decipher::DecipherInit(char* cipherType, char* key_buf, int key_buf_len) {
cipher_ = EVP_get_cipherbyname(cipherType);
if(!cipher_) {
@ -2365,7 +2348,7 @@ class Decipher : public ObjectWrap {
}
bool DecipherInitIv(char* cipherType,
bool Decipher::DecipherInitIv(char* cipherType,
char* key,
int key_len,
char* iv,
@ -2396,7 +2379,11 @@ class Decipher : public ObjectWrap {
return true;
}
int DecipherUpdate(char* data, int len, unsigned char** out, int* out_len) {
int Decipher::DecipherUpdate(char* data,
int len,
unsigned char** out,
int* out_len) {
if (!initialised_) {
*out_len = 0;
*out = NULL;
@ -2409,13 +2396,14 @@ class Decipher : public ObjectWrap {
return EVP_CipherUpdate(&ctx, *out, out_len, (unsigned char*)data, len);
}
int SetAutoPadding(bool auto_padding) {
int Decipher::SetAutoPadding(bool auto_padding) {
if (!initialised_) return 0;
return EVP_CIPHER_CTX_set_padding(&ctx, auto_padding ? 1 : 0);
}
// coverity[alloc_arg]
int DecipherFinal(unsigned char** out, int *out_len) {
int Decipher::DecipherFinal(unsigned char** out, int *out_len) {
int r;
if (!initialised_) {
@ -2432,9 +2420,7 @@ class Decipher : public ObjectWrap {
}
protected:
static Handle<Value> New (const Arguments& args) {
Handle<Value> Decipher::New(const Arguments& args) {
HandleScope scope;
Decipher *cipher = new Decipher();
@ -2442,7 +2428,8 @@ class Decipher : public ObjectWrap {
return args.This();
}
static Handle<Value> DecipherInit(const Arguments& args) {
Handle<Value> Decipher::DecipherInit(const Arguments& args) {
Decipher *cipher = ObjectWrap::Unwrap<Decipher>(args.This());
HandleScope scope;
@ -2480,7 +2467,8 @@ class Decipher : public ObjectWrap {
return args.This();
}
static Handle<Value> DecipherInitIv(const Arguments& args) {
Handle<Value> Decipher::DecipherInitIv(const Arguments& args) {
Decipher *cipher = ObjectWrap::Unwrap<Decipher>(args.This());
HandleScope scope;
@ -2532,7 +2520,8 @@ class Decipher : public ObjectWrap {
return args.This();
}
static Handle<Value> DecipherUpdate(const Arguments& args) {
Handle<Value> Decipher::DecipherUpdate(const Arguments& args) {
HandleScope scope;
Decipher *cipher = ObjectWrap::Unwrap<Decipher>(args.This());
@ -2569,7 +2558,8 @@ class Decipher : public ObjectWrap {
}
static Handle<Value> SetAutoPadding(const Arguments& args) {
Handle<Value> Decipher::SetAutoPadding(const Arguments& args) {
HandleScope scope;
Decipher *cipher = ObjectWrap::Unwrap<Decipher>(args.This());
@ -2578,7 +2568,8 @@ class Decipher : public ObjectWrap {
return Undefined();
}
static Handle<Value> DecipherFinal(const Arguments& args) {
Handle<Value> Decipher::DecipherFinal(const Arguments& args) {
HandleScope scope;
Decipher *cipher = ObjectWrap::Unwrap<Decipher>(args.This());
@ -2600,29 +2591,8 @@ class Decipher : public ObjectWrap {
return scope.Close(outString);
}
Decipher () : ObjectWrap () {
initialised_ = false;
}
~Decipher () {
if (initialised_) {
EVP_CIPHER_CTX_cleanup(&ctx);
}
}
private:
EVP_CIPHER_CTX ctx;
const EVP_CIPHER *cipher_;
bool initialised_;
};
class Hmac : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target) {
void Hmac::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@ -2636,7 +2606,8 @@ class Hmac : public ObjectWrap {
target->Set(String::NewSymbol("Hmac"), t->GetFunction());
}
bool HmacInit(char* hashType, char* key, int key_len) {
bool Hmac::HmacInit(char* hashType, char* key, int key_len) {
md = EVP_get_digestbyname(hashType);
if(!md) {
fprintf(stderr, "node-crypto : Unknown message digest %s\n", hashType);
@ -2653,13 +2624,15 @@ class Hmac : public ObjectWrap {
}
int HmacUpdate(char* data, int len) {
int Hmac::HmacUpdate(char* data, int len) {
if (!initialised_) return 0;
HMAC_Update(&ctx, (unsigned char*)data, len);
return 1;
}
int HmacDigest(unsigned char** md_value, unsigned int *md_len) {
int Hmac::HmacDigest(unsigned char** md_value, unsigned int *md_len) {
if (!initialised_) return 0;
*md_value = new unsigned char[EVP_MAX_MD_SIZE];
HMAC_Final(&ctx, *md_value, md_len);
@ -2669,9 +2642,7 @@ class Hmac : public ObjectWrap {
}
protected:
static Handle<Value> New (const Arguments& args) {
Handle<Value> Hmac::New(const Arguments& args) {
HandleScope scope;
Hmac *hmac = new Hmac();
@ -2679,7 +2650,8 @@ class Hmac : public ObjectWrap {
return args.This();
}
static Handle<Value> HmacInit(const Arguments& args) {
Handle<Value> Hmac::HmacInit(const Arguments& args) {
Hmac *hmac = ObjectWrap::Unwrap<Hmac>(args.This());
HandleScope scope;
@ -2723,7 +2695,8 @@ class Hmac : public ObjectWrap {
return args.This();
}
static Handle<Value> HmacUpdate(const Arguments& args) {
Handle<Value> Hmac::HmacUpdate(const Arguments& args) {
Hmac *hmac = ObjectWrap::Unwrap<Hmac>(args.This());
HandleScope scope;
@ -2745,7 +2718,8 @@ class Hmac : public ObjectWrap {
return args.This();
}
static Handle<Value> HmacDigest(const Arguments& args) {
Handle<Value> Hmac::HmacDigest(const Arguments& args) {
Hmac *hmac = ObjectWrap::Unwrap<Hmac>(args.This());
HandleScope scope;
@ -2766,27 +2740,8 @@ class Hmac : public ObjectWrap {
return scope.Close(outString);
}
Hmac () : ObjectWrap () {
initialised_ = false;
}
~Hmac () {
if (initialised_) {
HMAC_CTX_cleanup(&ctx);
}
}
private:
HMAC_CTX ctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class Hash : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target) {
void Hash::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@ -2799,7 +2754,8 @@ class Hash : public ObjectWrap {
target->Set(String::NewSymbol("Hash"), t->GetFunction());
}
bool HashInit (const char* hashType) {
bool Hash::HashInit(const char* hashType) {
md = EVP_get_digestbyname(hashType);
if(!md) return false;
EVP_MD_CTX_init(&mdctx);
@ -2808,16 +2764,15 @@ class Hash : public ObjectWrap {
return true;
}
int HashUpdate(char* data, int len) {
int Hash::HashUpdate(char* data, int len) {
if (!initialised_) return 0;
EVP_DigestUpdate(&mdctx, data, len);
return 1;
}
protected:
static Handle<Value> New (const Arguments& args) {
Handle<Value> Hash::New(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsString()) {
@ -2838,7 +2793,8 @@ class Hash : public ObjectWrap {
return args.This();
}
static Handle<Value> HashUpdate(const Arguments& args) {
Handle<Value> Hash::HashUpdate(const Arguments& args) {
HandleScope scope;
Hash *hash = ObjectWrap::Unwrap<Hash>(args.This());
@ -2859,7 +2815,8 @@ class Hash : public ObjectWrap {
return args.This();
}
static Handle<Value> HashDigest(const Arguments& args) {
Handle<Value> Hash::HashDigest(const Arguments& args) {
HandleScope scope;
Hash *hash = ObjectWrap::Unwrap<Hash>(args.This());
@ -2882,27 +2839,8 @@ class Hash : public ObjectWrap {
return scope.Close(outString);
}
Hash () : ObjectWrap () {
initialised_ = false;
}
~Hash () {
if (initialised_) {
EVP_MD_CTX_cleanup(&mdctx);
}
}
private:
EVP_MD_CTX mdctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class Sign : public ObjectWrap {
public:
static void
Initialize (v8::Handle<v8::Object> target) {
void Sign::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@ -2916,7 +2854,8 @@ class Sign : public ObjectWrap {
target->Set(String::NewSymbol("Sign"), t->GetFunction());
}
bool SignInit (const char* signType) {
bool Sign::SignInit(const char* signType) {
md = EVP_get_digestbyname(signType);
if(!md) {
printf("Unknown message digest %s\n", signType);
@ -2929,13 +2868,15 @@ class Sign : public ObjectWrap {
}
int SignUpdate(char* data, int len) {
int Sign::SignUpdate(char* data, int len) {
if (!initialised_) return 0;
EVP_SignUpdate(&mdctx, data, len);
return 1;
}
int SignFinal(unsigned char** md_value,
int Sign::SignFinal(unsigned char** md_value,
unsigned int *md_len,
char* key_pem,
int key_pemLen) {
@ -2958,9 +2899,7 @@ class Sign : public ObjectWrap {
}
protected:
static Handle<Value> New (const Arguments& args) {
Handle<Value> Sign::New(const Arguments& args) {
HandleScope scope;
Sign *sign = new Sign();
@ -2969,7 +2908,8 @@ class Sign : public ObjectWrap {
return args.This();
}
static Handle<Value> SignInit(const Arguments& args) {
Handle<Value> Sign::SignInit(const Arguments& args) {
HandleScope scope;
Sign *sign = ObjectWrap::Unwrap<Sign>(args.This());
@ -2990,7 +2930,8 @@ class Sign : public ObjectWrap {
return args.This();
}
static Handle<Value> SignUpdate(const Arguments& args) {
Handle<Value> Sign::SignUpdate(const Arguments& args) {
Sign *sign = ObjectWrap::Unwrap<Sign>(args.This());
HandleScope scope;
@ -3012,7 +2953,8 @@ class Sign : public ObjectWrap {
return args.This();
}
static Handle<Value> SignFinal(const Arguments& args) {
Handle<Value> Sign::SignFinal(const Arguments& args) {
Sign *sign = ObjectWrap::Unwrap<Sign>(args.This());
HandleScope scope;
@ -3045,26 +2987,8 @@ class Sign : public ObjectWrap {
return scope.Close(outString);
}
Sign () : ObjectWrap () {
initialised_ = false;
}
~Sign () {
if (initialised_) {
EVP_MD_CTX_cleanup(&mdctx);
}
}
private:
EVP_MD_CTX mdctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class Verify : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target) {
void Verify::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@ -3079,7 +3003,7 @@ class Verify : public ObjectWrap {
}
bool VerifyInit (const char* verifyType) {
bool Verify::VerifyInit(const char* verifyType) {
md = EVP_get_digestbyname(verifyType);
if(!md) {
fprintf(stderr, "node-crypto : Unknown message digest %s\n", verifyType);
@ -3092,14 +3016,17 @@ class Verify : public ObjectWrap {
}
int VerifyUpdate(char* data, int len) {
int Verify::VerifyUpdate(char* data, int len) {
if (!initialised_) return 0;
EVP_VerifyUpdate(&mdctx, data, len);
return 1;
}
int VerifyFinal(char* key_pem, int key_pemLen, unsigned char* sig, int siglen) {
int Verify::VerifyFinal(char* key_pem,
int key_pemLen,
unsigned char* sig,
int siglen) {
if (!initialised_) return 0;
EVP_PKEY* pkey = NULL;
@ -3167,9 +3094,7 @@ class Verify : public ObjectWrap {
}
protected:
static Handle<Value> New (const Arguments& args) {
Handle<Value> Verify::New(const Arguments& args) {
HandleScope scope;
Verify *verify = new Verify();
@ -3179,7 +3104,7 @@ class Verify : public ObjectWrap {
}
static Handle<Value> VerifyInit(const Arguments& args) {
Handle<Value> Verify::VerifyInit(const Arguments& args) {
Verify *verify = ObjectWrap::Unwrap<Verify>(args.This());
HandleScope scope;
@ -3201,7 +3126,7 @@ class Verify : public ObjectWrap {
}
static Handle<Value> VerifyUpdate(const Arguments& args) {
Handle<Value> Verify::VerifyUpdate(const Arguments& args) {
HandleScope scope;
Verify *verify = ObjectWrap::Unwrap<Verify>(args.This());
@ -3224,7 +3149,7 @@ class Verify : public ObjectWrap {
}
static Handle<Value> VerifyFinal(const Arguments& args) {
Handle<Value> Verify::VerifyFinal(const Arguments& args) {
HandleScope scope;
Verify *verify = ObjectWrap::Unwrap<Verify>(args.This());
@ -3264,27 +3189,8 @@ class Verify : public ObjectWrap {
return Boolean::New(r && r != -1);
}
Verify () : ObjectWrap () {
initialised_ = false;
}
~Verify () {
if (initialised_) {
EVP_MD_CTX_cleanup(&mdctx);
}
}
private:
EVP_MD_CTX mdctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class DiffieHellman : public ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target) {
void DiffieHellman::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@ -3315,7 +3221,8 @@ class DiffieHellman : public ObjectWrap {
target->Set(String::NewSymbol("DiffieHellmanGroup"), t2->GetFunction());
}
bool Init(int primeLength) {
bool DiffieHellman::Init(int primeLength) {
dh = DH_new();
DH_generate_parameters_ex(dh, primeLength, DH_GENERATOR_2, 0);
bool result = VerifyContext();
@ -3324,7 +3231,8 @@ class DiffieHellman : public ObjectWrap {
return true;
}
bool Init(unsigned char* p, int p_len) {
bool DiffieHellman::Init(unsigned char* p, int p_len) {
dh = DH_new();
dh->p = BN_bin2bn(p, p_len, 0);
dh->g = BN_new();
@ -3335,7 +3243,11 @@ class DiffieHellman : public ObjectWrap {
return true;
}
bool Init(unsigned char* p, int p_len, unsigned char* g, int g_len) {
bool DiffieHellman::Init(unsigned char* p,
int p_len,
unsigned char* g,
int g_len) {
dh = DH_new();
dh->p = BN_bin2bn(p, p_len, 0);
dh->g = BN_bin2bn(g, g_len, 0);
@ -3343,8 +3255,8 @@ class DiffieHellman : public ObjectWrap {
return true;
}
protected:
static Handle<Value> DiffieHellmanGroup(const Arguments& args) {
Handle<Value> DiffieHellman::DiffieHellmanGroup(const Arguments& args) {
HandleScope scope;
DiffieHellman* diffieHellman = new DiffieHellman();
@ -3377,7 +3289,8 @@ class DiffieHellman : public ObjectWrap {
return args.This();
}
static Handle<Value> New(const Arguments& args) {
Handle<Value> DiffieHellman::New(const Arguments& args) {
HandleScope scope;
DiffieHellman* diffieHellman = new DiffieHellman();
@ -3403,7 +3316,8 @@ class DiffieHellman : public ObjectWrap {
return args.This();
}
static Handle<Value> GenerateKeys(const Arguments& args) {
Handle<Value> DiffieHellman::GenerateKeys(const Arguments& args) {
DiffieHellman* diffieHellman =
ObjectWrap::Unwrap<DiffieHellman>(args.This());
@ -3432,7 +3346,8 @@ class DiffieHellman : public ObjectWrap {
return scope.Close(outString);
}
static Handle<Value> GetPrime(const Arguments& args) {
Handle<Value> DiffieHellman::GetPrime(const Arguments& args) {
DiffieHellman* diffieHellman =
ObjectWrap::Unwrap<DiffieHellman>(args.This());
@ -3455,7 +3370,8 @@ class DiffieHellman : public ObjectWrap {
return scope.Close(outString);
}
static Handle<Value> GetGenerator(const Arguments& args) {
Handle<Value> DiffieHellman::GetGenerator(const Arguments& args) {
DiffieHellman* diffieHellman =
ObjectWrap::Unwrap<DiffieHellman>(args.This());
@ -3478,7 +3394,8 @@ class DiffieHellman : public ObjectWrap {
return scope.Close(outString);
}
static Handle<Value> GetPublicKey(const Arguments& args) {
Handle<Value> DiffieHellman::GetPublicKey(const Arguments& args) {
DiffieHellman* diffieHellman =
ObjectWrap::Unwrap<DiffieHellman>(args.This());
@ -3507,7 +3424,8 @@ class DiffieHellman : public ObjectWrap {
return scope.Close(outString);
}
static Handle<Value> GetPrivateKey(const Arguments& args) {
Handle<Value> DiffieHellman::GetPrivateKey(const Arguments& args) {
DiffieHellman* diffieHellman =
ObjectWrap::Unwrap<DiffieHellman>(args.This());
@ -3536,7 +3454,8 @@ class DiffieHellman : public ObjectWrap {
return scope.Close(outString);
}
static Handle<Value> ComputeSecret(const Arguments& args) {
Handle<Value> DiffieHellman::ComputeSecret(const Arguments& args) {
HandleScope scope;
DiffieHellman* diffieHellman =
@ -3609,7 +3528,8 @@ class DiffieHellman : public ObjectWrap {
return scope.Close(outString);
}
static Handle<Value> SetPublicKey(const Arguments& args) {
Handle<Value> DiffieHellman::SetPublicKey(const Arguments& args) {
HandleScope scope;
DiffieHellman* diffieHellman =
@ -3633,7 +3553,8 @@ class DiffieHellman : public ObjectWrap {
return args.This();
}
static Handle<Value> SetPrivateKey(const Arguments& args) {
Handle<Value> DiffieHellman::SetPrivateKey(const Arguments& args) {
HandleScope scope;
DiffieHellman* diffieHellman =
@ -3658,19 +3579,8 @@ class DiffieHellman : public ObjectWrap {
return args.This();
}
DiffieHellman() : ObjectWrap() {
initialised_ = false;
dh = NULL;
}
~DiffieHellman() {
if (dh != NULL) {
DH_free(dh);
}
}
private:
bool VerifyContext() {
bool DiffieHellman::VerifyContext() {
int codes;
if (!DH_check(dh, &codes)) return false;
if (codes & DH_CHECK_P_NOT_SAFE_PRIME) return false;
@ -3680,10 +3590,6 @@ class DiffieHellman : public ObjectWrap {
return true;
}
bool initialised_;
DH* dh;
};
struct pbkdf2_req {
uv_work_t work_req;

232
src/node_crypto.h

@ -276,6 +276,238 @@ class Connection : ObjectWrap {
friend class SecureContext;
};
class Cipher : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target);
bool CipherInit(char* cipherType, char* key_buf, int key_buf_len);
bool CipherInitIv(char* cipherType,
char* key,
int key_len,
char* iv,
int iv_len);
int CipherUpdate(char* data, int len, unsigned char** out, int* out_len);
int SetAutoPadding(bool auto_padding);
int CipherFinal(unsigned char** out, int *out_len);
protected:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> CipherInit(const v8::Arguments& args);
static v8::Handle<v8::Value> CipherInitIv(const v8::Arguments& args);
static v8::Handle<v8::Value> CipherUpdate(const v8::Arguments& args);
static v8::Handle<v8::Value> SetAutoPadding(const v8::Arguments& args);
static v8::Handle<v8::Value> CipherFinal(const v8::Arguments& args);
Cipher() : ObjectWrap(), initialised_(false) {
}
~Cipher() {
if (initialised_) {
EVP_CIPHER_CTX_cleanup(&ctx);
}
}
private:
EVP_CIPHER_CTX ctx; /* coverity[member_decl] */
const EVP_CIPHER *cipher; /* coverity[member_decl] */
bool initialised_;
};
class Decipher : public ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
bool DecipherInit(char* cipherType, char* key_buf, int key_buf_len);
bool DecipherInitIv(char* cipherType,
char* key,
int key_len,
char* iv,
int iv_len);
int DecipherUpdate(char* data, int len, unsigned char** out, int* out_len);
int SetAutoPadding(bool auto_padding);
int DecipherFinal(unsigned char** out, int *out_len);
protected:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> DecipherInit(const v8::Arguments& args);
static v8::Handle<v8::Value> DecipherInitIv(const v8::Arguments& args);
static v8::Handle<v8::Value> DecipherUpdate(const v8::Arguments& args);
static v8::Handle<v8::Value> SetAutoPadding(const v8::Arguments& args);
static v8::Handle<v8::Value> DecipherFinal(const v8::Arguments& args);
Decipher() : ObjectWrap(), initialised_(false) {
}
~Decipher() {
if (initialised_) {
EVP_CIPHER_CTX_cleanup(&ctx);
}
}
private:
EVP_CIPHER_CTX ctx;
const EVP_CIPHER *cipher_;
bool initialised_;
};
class Hmac : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target);
bool HmacInit(char* hashType, char* key, int key_len);
int HmacUpdate(char* data, int len);
int HmacDigest(unsigned char** md_value, unsigned int *md_len);
protected:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> HmacInit(const v8::Arguments& args);
static v8::Handle<v8::Value> HmacUpdate(const v8::Arguments& args);
static v8::Handle<v8::Value> HmacDigest(const v8::Arguments& args);
Hmac() : ObjectWrap(), initialised_(false) {
}
~Hmac() {
if (initialised_) {
HMAC_CTX_cleanup(&ctx);
}
}
private:
HMAC_CTX ctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class Hash : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target);
bool HashInit (const char* hashType);
int HashUpdate(char* data, int len);
protected:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> HashUpdate(const v8::Arguments& args);
static v8::Handle<v8::Value> HashDigest(const v8::Arguments& args);
Hash() : ObjectWrap(), initialised_(false) {
}
~Hash() {
if (initialised_) {
EVP_MD_CTX_cleanup(&mdctx);
}
}
private:
EVP_MD_CTX mdctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class Sign : public ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
bool SignInit (const char* signType);
int SignUpdate(char* data, int len);
int SignFinal(unsigned char** md_value,
unsigned int *md_len,
char* key_pem,
int key_pemLen);
protected:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> SignInit(const v8::Arguments& args);
static v8::Handle<v8::Value> SignUpdate(const v8::Arguments& args);
static v8::Handle<v8::Value> SignFinal(const v8::Arguments& args);
Sign() : ObjectWrap(), initialised_(false) {
}
~Sign () {
if (initialised_) {
EVP_MD_CTX_cleanup(&mdctx);
}
}
private:
EVP_MD_CTX mdctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class Verify : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target);
bool VerifyInit (const char* verifyType);
int VerifyUpdate(char* data, int len);
int VerifyFinal(char* key_pem,
int key_pemLen,
unsigned char* sig,
int siglen);
protected:
static v8::Handle<v8::Value> New (const v8::Arguments& args);
static v8::Handle<v8::Value> VerifyInit(const v8::Arguments& args);
static v8::Handle<v8::Value> VerifyUpdate(const v8::Arguments& args);
static v8::Handle<v8::Value> VerifyFinal(const v8::Arguments& args);
Verify() : ObjectWrap(), initialised_(false) {
}
~Verify() {
if (initialised_) {
EVP_MD_CTX_cleanup(&mdctx);
}
}
private:
EVP_MD_CTX mdctx; /* coverity[member_decl] */
const EVP_MD *md; /* coverity[member_decl] */
bool initialised_;
};
class DiffieHellman : public ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
bool Init(int primeLength);
bool Init(unsigned char* p, int p_len);
bool Init(unsigned char* p, int p_len, unsigned char* g, int g_len);
protected:
static v8::Handle<v8::Value> DiffieHellmanGroup(const v8::Arguments& args);
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> GenerateKeys(const v8::Arguments& args);
static v8::Handle<v8::Value> GetPrime(const v8::Arguments& args);
static v8::Handle<v8::Value> GetGenerator(const v8::Arguments& args);
static v8::Handle<v8::Value> GetPublicKey(const v8::Arguments& args);
static v8::Handle<v8::Value> GetPrivateKey(const v8::Arguments& args);
static v8::Handle<v8::Value> ComputeSecret(const v8::Arguments& args);
static v8::Handle<v8::Value> SetPublicKey(const v8::Arguments& args);
static v8::Handle<v8::Value> SetPrivateKey(const v8::Arguments& args);
DiffieHellman() : ObjectWrap(), initialised_(false), dh(NULL) {
}
~DiffieHellman() {
if (dh != NULL) {
DH_free(dh);
}
}
private:
bool VerifyContext();
bool initialised_;
DH* dh;
};
void InitCrypto(v8::Handle<v8::Object> target);
} // namespace crypto

Loading…
Cancel
Save