From c89a87a2b43fcee7c4682cc4f1bbff7498690c7c Mon Sep 17 00:00:00 2001 From: Technorama team Date: Sat, 26 Jun 2004 21:09:08 +0000 Subject: fix .dup --- ossl_cipher.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ossl_cipher.c b/ossl_cipher.c index b2323fc..a52de1c 100644 --- a/ossl_cipher.c +++ b/ossl_cipher.c @@ -62,6 +62,7 @@ ossl_cipher_alloc(VALUE klass) VALUE obj; MakeCipher(obj, klass, ctx); + EVP_CIPHER_CTX_init(ctx); return obj; } @@ -81,9 +82,8 @@ ossl_cipher_initialize(VALUE self, VALUE str) if (!(cipher = EVP_get_cipherbyname(name))) { ossl_raise(rb_eRuntimeError, "Unsupported cipher algorithm (%s).", name); } - EVP_CIPHER_CTX_init(ctx); - if (EVP_CipherInit(ctx, cipher, NULL, NULL, -1) != 1) - ossl_raise(eCipherError, NULL); + if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, -1) != 1) + ossl_raise(eCipherError, NULL); return self; } @@ -98,7 +98,12 @@ ossl_cipher_copy(VALUE self, VALUE other) GetCipher(self, ctx1); SafeGetCipher(other, ctx2); + if (EVP_CIPHER_CTX_copy(ctx1, ctx2) != 1) + ossl_raise(eCipherError, NULL); + +/* EVP_CIPHER_CTX can not be copied directly. memcpy(ctx1, ctx2, sizeof(EVP_CIPHER_CTX)); +*/ return self; } @@ -110,7 +115,7 @@ ossl_cipher_reset(VALUE self) EVP_CIPHER_CTX *ctx; GetCipher(self, ctx); - if (EVP_CipherInit(ctx, NULL, NULL, NULL, -1) != 1) + if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, -1) != 1) ossl_raise(eCipherError, NULL); return self; @@ -151,7 +156,7 @@ ossl_cipher_encrypt(int argc, VALUE *argv, VALUE self) } } - if (EVP_CipherInit(ctx, NULL, NULL, NULL, 1) != 1) { + if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 1) != 1) { ossl_raise(eCipherError, NULL); } @@ -160,7 +165,7 @@ ossl_cipher_encrypt(int argc, VALUE *argv, VALUE self) EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), EVP_md5(), iv, RSTRING(pass)->ptr, RSTRING(pass)->len, 1, key, NULL); - if (EVP_CipherInit(ctx, NULL, key, iv, -1) != 1) { + if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1) { ossl_raise(eCipherError, NULL); } } @@ -196,7 +201,7 @@ ossl_cipher_decrypt(int argc, VALUE *argv, VALUE self) } } - if (EVP_CipherInit(ctx, NULL, NULL, NULL, 0) != 1) { + if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 0) != 1) { ossl_raise(eCipherError, NULL); } @@ -205,7 +210,7 @@ ossl_cipher_decrypt(int argc, VALUE *argv, VALUE self) EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), EVP_md5(), iv, RSTRING(pass)->ptr, RSTRING(pass)->len, 1, key, NULL); - if (EVP_CipherInit(ctx, NULL, key, iv, -1) != 1) { + if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1) { ossl_raise(eCipherError, NULL); } } @@ -237,7 +242,7 @@ ossl_cipher_pkcs5_v15_password(int argc, VALUE *argv, VALUE self) } EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), md, NIL_P(salt) ? NULL : RSTRING(salt)->ptr, RSTRING(pass)->ptr, RSTRING(pass)->len, NUM2INT(rounds), key, iv); - if (EVP_CipherInit(ctx, NULL, key, iv, -1) != 1) + if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1) ossl_raise(eCipherError, ""); return self; @@ -283,7 +288,7 @@ ossl_cipher_final(VALUE self) if (!(out = OPENSSL_malloc(EVP_CIPHER_CTX_block_size(ctx)))) { ossl_raise(eCipherError, NULL); } - if (!EVP_CipherFinal(ctx, out, &out_len)) { + if (!EVP_CipherFinal_ex(ctx, out, &out_len)) { OPENSSL_free(out); ossl_raise(eCipherError, NULL); } @@ -315,7 +320,7 @@ ossl_cipher_set_key(VALUE self, VALUE key) if (RSTRING(key)->len < EVP_CIPHER_CTX_key_length(ctx)) ossl_raise(eCipherError, "key length too short"); - if (EVP_CipherInit(ctx, NULL, RSTRING(key)->ptr, NULL, -1) != 1) + if (EVP_CipherInit_ex(ctx, NULL, NULL, RSTRING(key)->ptr, NULL, -1) != 1) ossl_raise(eCipherError, NULL); return key; @@ -332,7 +337,7 @@ ossl_cipher_set_iv(VALUE self, VALUE iv) if (RSTRING(iv)->len < EVP_CIPHER_CTX_iv_length(ctx)) ossl_raise(eCipherError, "iv length too short"); - if (EVP_CipherInit(ctx, NULL, NULL, RSTRING(iv)->ptr, -1) != 1) + if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, RSTRING(iv)->ptr, -1) != 1) ossl_raise(eCipherError, NULL); return iv; -- cgit v1.2.3