|
@ -762,50 +762,51 @@ int local_EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, |
|
|
|
|
|
|
|
|
*outl=0; |
|
|
*outl=0; |
|
|
b=ctx->cipher->block_size; |
|
|
b=ctx->cipher->block_size; |
|
|
if (ctx->flags & EVP_CIPH_NO_PADDING) |
|
|
|
|
|
{ |
|
|
if (ctx->flags & EVP_CIPH_NO_PADDING) { |
|
|
if(ctx->buf_len) |
|
|
if(ctx->buf_len) { |
|
|
{ |
|
|
|
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); |
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
*outl = 0; |
|
|
*outl = 0; |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
if (b > 1) |
|
|
|
|
|
{ |
|
|
if (b > 1) { |
|
|
if (ctx->buf_len || !ctx->final_used) |
|
|
if (ctx->buf_len || !ctx->final_used) { |
|
|
{ |
|
|
|
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); |
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); |
|
|
return(0); |
|
|
return(0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
OPENSSL_assert(b <= sizeof ctx->final); |
|
|
OPENSSL_assert(b <= sizeof ctx->final); |
|
|
n=ctx->final[b-1]; |
|
|
n=ctx->final[b-1]; |
|
|
if (n > b) |
|
|
|
|
|
{ |
|
|
if (n > b) { |
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); |
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); |
|
|
return(0); |
|
|
return(0); |
|
|
} |
|
|
} |
|
|
for (i=0; i<n; i++) |
|
|
|
|
|
{ |
|
|
for (i=0; i<n; i++) { |
|
|
if (ctx->final[--b] != n) |
|
|
if (ctx->final[--b] != n) { |
|
|
{ |
|
|
|
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); |
|
|
EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); |
|
|
return(0); |
|
|
return(0); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
n=ctx->cipher->block_size-n; |
|
|
n=ctx->cipher->block_size-n; |
|
|
for (i=0; i<n; i++) |
|
|
|
|
|
|
|
|
for (i=0; i<n; i++) { |
|
|
out[i]=ctx->final[i]; |
|
|
out[i]=ctx->final[i]; |
|
|
*outl=n; |
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
*outl=n; |
|
|
|
|
|
} else { |
|
|
*outl=0; |
|
|
*outl=0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return(1); |
|
|
return(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Cipher : public ObjectWrap { |
|
|
class Cipher : public ObjectWrap { |
|
|
public: |
|
|
public: |
|
|
static void Initialize (v8::Handle<v8::Object> target) { |
|
|
static void Initialize (v8::Handle<v8::Object> target) { |
|
@ -1000,8 +1001,9 @@ class Cipher : public ObjectWrap { |
|
|
delete [] buf; |
|
|
delete [] buf; |
|
|
|
|
|
|
|
|
Local<Value> outString; |
|
|
Local<Value> outString; |
|
|
if (out_len==0) outString=String::New(""); |
|
|
if (out_len==0) { |
|
|
else { |
|
|
outString=String::New(""); |
|
|
|
|
|
} else { |
|
|
if (args.Length() <= 2 || !args[2]->IsString()) { |
|
|
if (args.Length() <= 2 || !args[2]->IsString()) { |
|
|
// Binary
|
|
|
// Binary
|
|
|
outString = Encode(out, out_len, BINARY); |
|
|
outString = Encode(out, out_len, BINARY); |
|
@ -1034,7 +1036,9 @@ class Cipher : public ObjectWrap { |
|
|
if (out_len%3!=0){ |
|
|
if (out_len%3!=0){ |
|
|
cipher->incomplete_base64_len = out_len%3; |
|
|
cipher->incomplete_base64_len = out_len%3; |
|
|
cipher->incomplete_base64 = new char[cipher->incomplete_base64_len+1]; |
|
|
cipher->incomplete_base64 = new char[cipher->incomplete_base64_len+1]; |
|
|
memcpy(cipher->incomplete_base64, &out[out_len-cipher->incomplete_base64_len], cipher->incomplete_base64_len); |
|
|
memcpy(cipher->incomplete_base64, |
|
|
|
|
|
&out[out_len-cipher->incomplete_base64_len], |
|
|
|
|
|
cipher->incomplete_base64_len); |
|
|
out_len -= cipher->incomplete_base64_len; |
|
|
out_len -= cipher->incomplete_base64_len; |
|
|
out[out_len]=0; |
|
|
out[out_len]=0; |
|
|
} |
|
|
} |
|
@ -1050,7 +1054,9 @@ class Cipher : public ObjectWrap { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (out) delete [] out; |
|
|
if (out) delete [] out; |
|
|
|
|
|
|
|
|
return scope.Close(outString); |
|
|
return scope.Close(outString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|