You are here:

C++/vectorized MD5

Advertisement


Question
I hate to keep bothering you. I am expecting to have more free time over January and was hoping for something to work with by then. Again here is my code:

http://www.cerberusgate.com/test.cpp
http://www.cerberusgate.com/md5_sse.h
http://www.cerberusgate.com/Public.h

although i'm pretty sure Public.h isn't used and can be omitted. I am able to compile successfully, but I seem to get innacurate hashes. Again, here are my primary concerns:

1) is the hash function bugged? or am I doing something wrong? or am I simply expecting something wrong? I was expecting the twelve 32-character hashes concatenated into a 384 character string. Is this wrong? or perhaps I am simply printing it wrong or something?

2) is there any way you could re-write the add_plain_text() function to take char arrays[] rather than strings? And rewrite the function for each array length 5-10? (add_plain_text_len_5(), add_plain_text_len_6(), ... , add_plain_text_len_10()) and optimize each function for that specific length? That would be awesome.

one last thing- I moved the MD5_SSE() function into test.cpp, and I omitted from your code the line

if( line.size() >= MAX_PLAIN_LEN ) line = line.substr( 0, MAX_PLAIN_LEN-1 ) ;

as it seemed to deal with passwords where the length exceeds 16 characters which will never be the case in my code and the check may slow down the hash generation. If I have done something wrong in this, people tell me.

Thanks a lot. It's very helpful for me to see how this code works - once I can see it laid out simply, I can understand it in slight more complexity. So thank you for your time.

Answer
> 1) is the hash function bugged? or am I doing something wrong?

I've not really checked. This had been on the backburner and i hadn't reaaly had the time to look at it.
I'll do so over the week end.

> 2) is there any way you could re-write the add_plain_text() function to take char arrays[] rather than
> strings? And rewrite the function for each array length 5-10? (add_plain_text_len_5(), add_plain_text_len_6(),
> ... , add_plain_text_len_10()) and optimize each function for that specific length? That would be awesome.

That should be quite easy. I suppose you mean some thing like this:

template< int ARRAYSIZE > // ARRAY SIZE could be from 5 .. 10
void add_plain_text( plain_text_t plain_texts, std::size_t index, const char* cstr ) ;

Again, I'll have it ready by Monday or so and add to this answer; I suppose you would get a mail then.


> one last thing- I moved the MD5_SSE() function into test.cpp, and I omitted from your code the line

> if( line.size() >= MAX_PLAIN_LEN ) line = line.substr( 0, MAX_PLAIN_LEN-1 ) ;

> as it seemed to deal with passwords where the length exceeds 16 characters
> which will never be the case in my code

Yes, that is all that it does; you can safely omit it from your code,
if your password length will never exceed MAX_PLAIN_LEN


Note:

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.