You are here:

C++/vectorized MD5


Sorry. That was a stupid oversight on my part. The code is here:
and here:
and here:

and you already have the exchange.

The compilation errors I am getting are this:

1>------ Build started: Project: md5_sse2_neinbrucke, Configuration: Debug Win32 ------
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Jim\Documents\Visual Studio 2008\Projects\md5_sse2_neinbrucke\Debug\md5_sse2_neinbrucke.exe : fatal error LNK1120: 1 unresolved externals

in both Visual Studio Express Edition and Professional Edition. I just recently installed both of them on the same machine at the same time. Hopefully that is not causing the problem. I have successfully compiled other projects since the installation.

You need to write a main() function, and the linker error will go away - something like this.

Not: md5_sse.c does not compile on the gnu compiler, it seems to be microsoft specific. So, I've not tested it at all.

#include <string>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <fstream>

* from md5_sse.h
* I call the function like this:

* MD5_SSE(pPlain, nPlainLen, pHash);

* with:
* unsigned char* pPlain :
*      contains 12 plaintexts, 16 bytes per plaintext, actual max length is 15
* int nPlainLen[12]:
*      contains the lenghts per plaintext
* unsigned char* pHash:
*      will contains the resulting hashes, MAX_HASH_LEN bytes per hash,
*      i defined MAX_HASH_LEN as 32, but for md5 you can just set it to 16.
* note: in this example, I have set MAX_HASH_LEN to 16
*       either move the three typedefs to public.h
*       or make sure that they are identical in md5_sse.c and

#define MAX_HASH_LEN  16
#define MAX_PLAIN_LEN 16

#include "md5_sse.h"

typedef unsigned char plain_text_t[ MAX_PLAIN_LEN * SSE_SIMULTANEOUS ] ;
typedef unsigned char digest_t[ MAX_HASH_LEN * SSE_SIMULTANEOUS ] ;
typedef int text_lengths_t[ SSE_SIMULTANEOUS ] ;

// adds one plain text string at position index to 12 the plaintexts sequence
// padding up unused bytes with null
void add_plain_text( plain_text_t plain_texts, std::size_t index, const std::string& str )
   assert( index < SSE_SIMULTANEOUS ) ;
   assert( str.size() < MAX_PLAIN_LEN ) ;
   std::fill_n( plain_texts + MAX_PLAIN_LEN * (index-1), MAX_PLAIN_LEN, 0 ) ;
   std::copy( str.begin(), str.end(), plain_texts + MAX_PLAIN_LEN * (index-1) ) ;

int main()
    plain_text_t plain_texts ;
    text_lengths_t text_lengths ;
    digest_t digests ;

    // just an example, fill up the 12 plaintexts with the first 12
    // non-empty lines  in this file (max 15 chars, so truncate if line is longer).
    std::ifstream file( __FILE__ ) ;
    for( std::size_t i=0 ; i < SSE_SIMULTANEOUS ; ++i )
         std::string line ;
         do std::getline( file, line ) ; while( !line.empty() ) ;

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

         add_plain_text( plain_texts, i, line ) ;
         text_lengths[i] = line.size() ;

    MD5_SSE( plain_texts, text_lengths, digests ) ;


All Answers

Answers by Expert:

Ask Experts




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.


about 15 years or so

post graduate engineer

©2016 All rights reserved.