aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llblowfishcipher.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-03-11 04:31:18 +1000
committerDavid Walter Seikel2012-03-11 04:31:18 +1000
commitf2715ed85d43b7c7fa4f86e3c3b4118c4cd5ce4d (patch)
tree09b03f9c806b034090c5e9bafa96faeee0f936b0 /linden/indra/llmessage/llblowfishcipher.cpp
parentJust adding a TODO. (diff)
downloadmeta-impy-f2715ed85d43b7c7fa4f86e3c3b4118c4cd5ce4d.zip
meta-impy-f2715ed85d43b7c7fa4f86e3c3b4118c4cd5ce4d.tar.gz
meta-impy-f2715ed85d43b7c7fa4f86e3c3b4118c4cd5ce4d.tar.bz2
meta-impy-f2715ed85d43b7c7fa4f86e3c3b4118c4cd5ce4d.tar.xz
Fix http://redmine.kokuaviewer.org/issues/1126 and as a bonus, now using blowfish to encrypt passwords.
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/llblowfishcipher.cpp69
1 files changed, 61 insertions, 8 deletions
diff --git a/linden/indra/llmessage/llblowfishcipher.cpp b/linden/indra/llmessage/llblowfishcipher.cpp
index f24d103..e9d4a7c 100644
--- a/linden/indra/llmessage/llblowfishcipher.cpp
+++ b/linden/indra/llmessage/llblowfishcipher.cpp
@@ -73,13 +73,13 @@ U32 LLBlowfishCipher::encrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len)
73 unsigned char initial_vector[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 73 unsigned char initial_vector[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
74 EVP_EncryptInit_ex(&context, NULL, NULL, mSecret, initial_vector); 74 EVP_EncryptInit_ex(&context, NULL, NULL, mSecret, initial_vector);
75 75
76 int blocksize = EVP_CIPHER_CTX_block_size(&context); 76// int blocksize = EVP_CIPHER_CTX_block_size(&context);
77 int keylen = EVP_CIPHER_CTX_key_length(&context); 77// int keylen = EVP_CIPHER_CTX_key_length(&context);
78 int iv_length = EVP_CIPHER_CTX_iv_length(&context); 78// int iv_length = EVP_CIPHER_CTX_iv_length(&context);
79 lldebugs << "LLBlowfishCipher blocksize " << blocksize 79// lldebugs << "LLBlowfishCipher blocksize " << blocksize
80 << " keylen " << keylen 80// << " keylen " << keylen
81 << " iv_len " << iv_length 81// << " iv_len " << iv_length
82 << llendl; 82// << llendl;
83 83
84 int output_len = 0; 84 int output_len = 0;
85 int temp_len = 0; 85 int temp_len = 0;
@@ -113,7 +113,60 @@ ERROR:
113// virtual 113// virtual
114U32 LLBlowfishCipher::decrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len) 114U32 LLBlowfishCipher::decrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len)
115{ 115{
116 llerrs << "LLBlowfishCipher decrypt unsupported" << llendl; 116 if (!src || !src_len || !dst || !dst_len) return 0;
117 if (src_len > dst_len) return 0;
118
119 // OpenSSL uses "cipher contexts" to hold encryption parameters.
120 EVP_CIPHER_CTX context;
121 EVP_CIPHER_CTX_init(&context);
122
123 // We want a blowfish cyclic block chain cipher, but need to set
124 // the key length before we pass in a key, so call EncryptInit
125 // first with NULLs.
126 EVP_DecryptInit_ex(&context, EVP_bf_cbc(), NULL, NULL, NULL);
127 EVP_CIPHER_CTX_set_key_length(&context, (int)mSecretSize);
128
129 // Complete initialization. Per EVP_EncryptInit man page, the
130 // cipher pointer must be NULL. Apparently initial_vector must
131 // be 8 bytes for blowfish, as this is the block size.
132 unsigned char initial_vector[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
133 EVP_DecryptInit_ex(&context, NULL, NULL, mSecret, initial_vector);
134
135// int blocksize = EVP_CIPHER_CTX_block_size(&context);
136// int keylen = EVP_CIPHER_CTX_key_length(&context);
137// int iv_length = EVP_CIPHER_CTX_iv_length(&context);
138// lldebugs << "LLBlowfishCipher blocksize " << blocksize
139// << " keylen " << keylen
140// << " iv_len " << iv_length
141// << llendl;
142
143 int output_len = 0;
144 int temp_len = 0;
145 if (!EVP_DecryptUpdate(&context,
146 dst,
147 &output_len,
148 src,
149 src_len))
150 {
151 llwarns << "LLBlowfishCipher::decrypt EVP_DecryptUpdate failure" << llendl;
152 goto ERROR;
153 }
154
155 // There may be some final data left to decrypt if the input is
156 // not an exact multiple of the block size.
157 if (!EVP_DecryptFinal_ex(&context, (unsigned char*)(dst + output_len), &temp_len))
158 {
159 llwarns << "LLBlowfishCipher::decrypt EVP_DecryptFinal failure" << llendl;
160 goto ERROR;
161 }
162 output_len += temp_len;
163
164 EVP_CIPHER_CTX_cleanup(&context);
165 return output_len;
166
167ERROR:
168 EVP_CIPHER_CTX_cleanup(&context);
169 return 0;
117 return 0; 170 return 0;
118} 171}
119 172