summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2014-08-23 17:38:32 +0400
committerFedor Indutny <fedor@indutny.com>2014-08-27 00:24:57 +0400
commit6adf3ecebb42c05662f7c6a792953589ffdfd4dc (patch)
treeaeee42cb757d6a5e13959dc11c8e225c269e685b /src
parent8a7d7f8b2b40f670d2fceb14d7d16cda1bea6bcf (diff)
downloadnode-new-6adf3ecebb42c05662f7c6a792953589ffdfd4dc.tar.gz
crypto: allow padding in RSA methods
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_constants.cc24
-rw-r--r--src/node_crypto.cc9
-rw-r--r--src/node_crypto.h1
3 files changed, 32 insertions, 2 deletions
diff --git a/src/node_constants.cc b/src/node_constants.cc
index dc7dc80670..430a09c685 100644
--- a/src/node_constants.cc
+++ b/src/node_constants.cc
@@ -950,6 +950,30 @@ void DefineOpenSSLConstants(Handle<Object> target) {
#define NPN_ENABLED 1
NODE_DEFINE_CONSTANT(target, NPN_ENABLED);
#endif
+
+#ifdef RSA_PKCS1_PADDING
+ NODE_DEFINE_CONSTANT(target, RSA_PKCS1_PADDING);
+#endif
+
+#ifdef RSA_SSLV23_PADDING
+ NODE_DEFINE_CONSTANT(target, RSA_SSLV23_PADDING);
+#endif
+
+#ifdef RSA_NO_PADDING
+ NODE_DEFINE_CONSTANT(target, RSA_NO_PADDING);
+#endif
+
+#ifdef RSA_PKCS1_OAEP_PADDING
+ NODE_DEFINE_CONSTANT(target, RSA_PKCS1_OAEP_PADDING);
+#endif
+
+#ifdef RSA_X931_PADDING
+ NODE_DEFINE_CONSTANT(target, RSA_X931_PADDING);
+#endif
+
+#ifdef RSA_PKCS1_PSS_PADDING
+ NODE_DEFINE_CONSTANT(target, RSA_PKCS1_PSS_PADDING);
+#endif
}
void DefineSystemConstants(Handle<Object> target) {
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 9fa1e2cfc4..6085a18a4d 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3552,6 +3552,7 @@ template <PublicKeyCipher::Operation operation,
bool PublicKeyCipher::Cipher(const char* key_pem,
int key_pem_len,
const char* passphrase,
+ int padding,
const unsigned char* data,
int len,
unsigned char** out,
@@ -3610,8 +3611,9 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
goto exit;
if (EVP_PKEY_cipher_init(ctx) <= 0)
goto exit;
- if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, padding) <= 0)
goto exit;
+
if (EVP_PKEY_cipher(ctx, NULL, out_len, data, len) <= 0)
goto exit;
@@ -3649,7 +3651,9 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
char* buf = Buffer::Data(args[1]);
ssize_t len = Buffer::Length(args[1]);
- String::Utf8Value passphrase(args[2]);
+ int padding = args[2]->Uint32Value();
+
+ String::Utf8Value passphrase(args[3]);
unsigned char* out_value = NULL;
size_t out_len = -1;
@@ -3658,6 +3662,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
kbuf,
klen,
args.Length() >= 3 && !args[2]->IsNull() ? *passphrase : NULL,
+ padding,
reinterpret_cast<const unsigned char*>(buf),
len,
&out_value,
diff --git a/src/node_crypto.h b/src/node_crypto.h
index 9531df0cad..2a02c89bc2 100644
--- a/src/node_crypto.h
+++ b/src/node_crypto.h
@@ -577,6 +577,7 @@ class PublicKeyCipher {
static bool Cipher(const char* key_pem,
int key_pem_len,
const char* passphrase,
+ int padding,
const unsigned char* data,
int len,
unsigned char** out,