2006-08-11 15:26:58 +04:00
/*
Unix SMB / CIFS implementation .
MD5 tests
Copyright ( C ) Stefan Metzmacher
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-08-11 15:26:58 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-08-11 15:26:58 +04:00
*/
# include "includes.h"
# include "lib/crypto/crypto.h"
struct torture_context ;
/*
This uses the test values from rfc1321
*/
2007-10-05 22:03:01 +04:00
bool torture_local_crypto_md5 ( struct torture_context * torture )
2006-08-11 15:26:58 +04:00
{
2007-10-05 22:03:01 +04:00
bool ret = true ;
2006-08-11 15:26:58 +04:00
uint32_t i ;
struct {
2006-09-11 08:18:16 +04:00
const char * data ;
const char * md5 ;
2006-08-11 15:26:58 +04:00
} testarray [ ] = {
{
2006-09-11 08:18:16 +04:00
. data = " " ,
. md5 = " d41d8cd98f00b204e9800998ecf8427e "
2006-08-11 15:26:58 +04:00
} , {
2006-09-11 08:18:16 +04:00
. data = " a " ,
. md5 = " 0cc175b9c0f1b6a831c399e269772661 "
2006-08-11 15:26:58 +04:00
} , {
2006-09-11 08:18:16 +04:00
. data = " abc " ,
. md5 = " 900150983cd24fb0d6963f7d28e17f72 "
2006-08-11 15:26:58 +04:00
} , {
2006-09-11 08:18:16 +04:00
. data = " message digest " ,
. md5 = " f96b697d7cb7938d525a2f31aaf161d0 "
2006-08-11 15:26:58 +04:00
} , {
2006-09-11 08:18:16 +04:00
. data = " abcdefghijklmnopqrstuvwxyz " ,
. md5 = " c3fcd3d76192e4007dfb496cca67e13b "
2006-08-11 15:26:58 +04:00
} , {
2006-09-11 08:18:16 +04:00
. data = " ABCDEFGHIJKLMNOPQRSTUVWXYZ "
2006-08-11 15:26:58 +04:00
" abcdefghijklmnopqrstuvwxyz "
2006-09-11 08:18:16 +04:00
" 0123456789 " ,
. md5 = " d174ab98d277d9f5a5611c2c9f419d9f "
2006-08-11 15:26:58 +04:00
} , {
2006-09-11 08:18:16 +04:00
. data = " 123456789012345678901234567890 "
2006-08-11 15:26:58 +04:00
" 123456789012345678901234567890 "
2006-09-11 08:18:16 +04:00
" 12345678901234567890 " ,
. md5 = " 57edf4a22be3c955ac49da2e2107b67a "
2006-08-11 15:26:58 +04:00
}
} ;
for ( i = 0 ; i < ARRAY_SIZE ( testarray ) ; i + + ) {
struct MD5Context ctx ;
uint8_t md5 [ 16 ] ;
int e ;
2006-09-11 08:18:16 +04:00
DATA_BLOB data ;
DATA_BLOB md5blob ;
data = data_blob_string_const ( testarray [ i ] . data ) ;
md5blob = strhex_to_data_blob ( testarray [ i ] . md5 ) ;
2006-08-11 15:26:58 +04:00
MD5Init ( & ctx ) ;
2006-09-11 08:18:16 +04:00
MD5Update ( & ctx , data . data , data . length ) ;
2006-08-11 15:26:58 +04:00
MD5Final ( md5 , & ctx ) ;
2006-09-11 08:18:16 +04:00
e = memcmp ( md5blob . data ,
2006-08-11 15:26:58 +04:00
md5 ,
2006-09-11 08:18:16 +04:00
MIN ( md5blob . length , sizeof ( md5 ) ) ) ;
2006-08-11 15:26:58 +04:00
if ( e ! = 0 ) {
2006-08-11 15:47:11 +04:00
printf ( " md5 test[%u]: failed \n " , i ) ;
2006-09-11 08:18:16 +04:00
dump_data ( 0 , data . data , data . length ) ;
dump_data ( 0 , md5blob . data , md5blob . length ) ;
2006-08-11 15:26:58 +04:00
dump_data ( 0 , md5 , sizeof ( md5 ) ) ;
2007-10-05 22:03:01 +04:00
ret = false ;
2006-08-11 15:26:58 +04:00
}
2006-09-11 08:18:16 +04:00
talloc_free ( md5blob . data ) ;
2006-08-11 15:26:58 +04:00
}
return ret ;
}