You are here:

C++/vectorized MD5

Advertisement


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

http://www.cerberusgate.com/md5_sse2.cpp
and here:
http://www.cerberusgate.com/md5_sse.h
and here:
http://www.cerberusgate.com/Public.h

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>Linking...
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.

Answer
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 main.cc
*/

#define SSE_SIMULTANEOUS 12
#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 ) ;
}  

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.