aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Rokos <m.rokos@sh.cvut.cz>2002-03-11 21:35:28 +0000
committerMichal Rokos <m.rokos@sh.cvut.cz>2002-03-11 21:35:28 +0000
commitfcb0234e46e8fc656748f364148754a1cc80ea4b (patch)
tree75c6dc33e04a77a7b503fd767db1dc365338eb79
parent7ed17afc8c327bc88d1510255d284487d06f226c (diff)
downloadruby-openssl-history-fcb0234e46e8fc656748f364148754a1cc80ea4b.tar.gz
* Cipher IV fixup
-rw-r--r--ChangeLog3
-rw-r--r--ossl_cipher.c16
-rwxr-xr-xtest/ossl_cipher.rb8
3 files changed, 18 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 1c2f38a..e9f3389 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@ Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
All rights reserved.
$Log$
+Revision 1.36 2002/03/11 21:35:39 majkl
+ * Cipher IV fixup
+
Revision 1.35 2002/03/11 17:20:22 majkl
* Big internal cleanup (all structs with only 1 member rearranged)
* improved getting time_t from cTime
diff --git a/ossl_cipher.c b/ossl_cipher.c
index e3bb9ff..48053fc 100644
--- a/ossl_cipher.c
+++ b/ossl_cipher.c
@@ -124,7 +124,7 @@ ossl_cipher_encrypt(int argc, VALUE *argv, VALUE self)
* TODO:
* random IV generation!
*/
- memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
+ memcpy(iv, "OpenSSL for Ruby rulez!", EVP_MAX_IV_LENGTH);
/*
RAND_add(data,i,0); where from take data?
if (RAND_pseudo_bytes(iv, 8) < 0) {
@@ -133,7 +133,11 @@ ossl_cipher_encrypt(int argc, VALUE *argv, VALUE self)
*/
} else {
init_v = rb_obj_as_string(init_v);
- memcpy(iv, RSTRING(init_v)->ptr, sizeof(iv));
+ if (EVP_MAX_IV_LENGTH > RSTRING(init_v)->len) {
+ memset(iv, 0, EVP_MAX_IV_LENGTH);
+ memcpy(iv, RSTRING(init_v)->ptr, RSTRING(init_v)->len);
+ } else
+ memcpy(iv, RSTRING(init_v)->ptr, EVP_MAX_IV_LENGTH);
}
EVP_CIPHER_CTX_init(ciphp->ctx);
@@ -165,10 +169,14 @@ ossl_cipher_decrypt(int argc, VALUE *argv, VALUE self)
* TODO:
* random IV generation!
*/
- memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
+ memcpy(iv, "OpenSSL for Ruby rulez!", EVP_MAX_IV_LENGTH);
} else {
init_v = rb_obj_as_string(init_v);
- memcpy(iv, RSTRING(init_v)->ptr, sizeof(iv));
+ if (EVP_MAX_IV_LENGTH > RSTRING(init_v)->len) {
+ memset(iv, 0, EVP_MAX_IV_LENGTH);
+ memcpy(iv, RSTRING(init_v)->ptr, RSTRING(init_v)->len);
+ } else
+ memcpy(iv, RSTRING(init_v)->ptr, EVP_MAX_IV_LENGTH);
}
EVP_CIPHER_CTX_init(ciphp->ctx);
diff --git a/test/ossl_cipher.rb b/test/ossl_cipher.rb
index ce21342..6a54dce 100755
--- a/test/ossl_cipher.rb
+++ b/test/ossl_cipher.rb
@@ -6,12 +6,10 @@ include Cipher
p des = DES.new(EDE3, CBC) #Des3 CBC mode
p "ENCRYPT"
-p des.encrypt("key") #, "initial_vector")
-p cipher = des.update("data1")
-#p cipher = des.encrypt("key", "initial_vector", "data")
+p des.encrypt("key")#, "iv12345678")
+p cipher = des.update("abcdefghijklmnopqrstuvwxyz")
p cipher += des.cipher
p "DECRYPT"
-p des.decrypt("key")
-#p des.decrypt("key", "initial_vector")
+p des.decrypt("key") #, "iv12345678")
p des.update(cipher) + des.cipher