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