2006-08-11 17:13:03 +04:00
/*
Unix SMB / CIFS implementation .
MD4 tests
Copyright ( C ) Stefan Metzmacher 2006
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 17:13:03 +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 17:13:03 +04:00
*/
2010-06-15 14:01:09 +04:00
# include "replace.h"
2011-09-21 01:26:36 +04:00
# include "../lib/util/samba_util.h"
2008-09-24 18:10:53 +04:00
# include "../lib/crypto/crypto.h"
2006-08-11 17:13:03 +04:00
struct torture_context ;
2012-02-05 18:31:05 +04:00
bool torture_local_crypto_md4 ( struct torture_context * torture ) ;
2006-08-11 17:13:03 +04:00
/*
This uses the test values from rfc1320
*/
2011-02-27 22:45:42 +03:00
bool torture_local_crypto_md4 ( struct torture_context * torture )
2006-08-11 17:13:03 +04:00
{
2007-10-05 22:03:01 +04:00
bool ret = true ;
2006-08-11 17:13:03 +04:00
uint32_t i ;
struct {
2006-09-11 04:59:31 +04:00
const char * data ;
const char * md4 ;
2006-08-11 17:13:03 +04:00
} testarray [ ] = {
{
2006-09-11 04:59:31 +04:00
. data = " " ,
. md4 = " 31d6cfe0d16ae931b73c59d7e0c089c0 "
2006-08-11 17:13:03 +04:00
} , {
2006-09-11 04:59:31 +04:00
. data = " a " ,
. md4 = " bde52cb31de33e46245e05fbdbd6fb24 "
2006-08-11 17:13:03 +04:00
} , {
2006-09-11 04:59:31 +04:00
. data = " abc " ,
. md4 = " a448017aaf21d8525fc10ae87aa6729d "
2006-08-11 17:13:03 +04:00
} , {
2006-09-11 04:59:31 +04:00
. data = " message digest " ,
. md4 = " d9130a8164549fe818874806e1c7014b "
2006-08-11 17:13:03 +04:00
} , {
2006-09-11 04:59:31 +04:00
. data = " abcdefghijklmnopqrstuvwxyz " ,
. md4 = " d79e1c308aa5bbcdeea8ed63df412da9 "
2006-08-11 17:13:03 +04:00
} , {
2006-09-11 04:59:31 +04:00
. data = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " ,
. md4 = " 043f8582f241db351ce627e153e7f0e4 "
2006-08-11 17:13:03 +04:00
} , {
2006-09-11 04:59:31 +04:00
. data = " 12345678901234567890123456789012345678901234567890123456789012345678901234567890 " ,
. md4 = " e33b4ddc9c38f2199c3e7b164fcc0536 "
2006-08-11 17:13:03 +04:00
}
} ;
for ( i = 0 ; i < ARRAY_SIZE ( testarray ) ; i + + ) {
uint8_t md4 [ 16 ] ;
int e ;
2006-09-11 04:59:31 +04:00
DATA_BLOB data ;
DATA_BLOB md4blob ;
data = data_blob_string_const ( testarray [ i ] . data ) ;
2008-10-18 23:03:30 +04:00
md4blob = strhex_to_data_blob ( NULL , testarray [ i ] . md4 ) ;
2006-08-11 17:13:03 +04:00
2006-09-11 04:59:31 +04:00
mdfour ( md4 , data . data , data . length ) ;
2006-08-11 17:13:03 +04:00
2006-09-11 04:59:31 +04:00
e = memcmp ( md4blob . data , md4 , MIN ( md4blob . length , sizeof ( md4 ) ) ) ;
2006-08-11 17:13:03 +04:00
if ( e ! = 0 ) {
printf ( " md4 test[%u]: failed \n " , i ) ;
2006-09-11 04:59:31 +04:00
dump_data ( 0 , data . data , data . length ) ;
dump_data ( 0 , md4blob . data , md4blob . length ) ;
2006-08-11 17:13:03 +04:00
dump_data ( 0 , md4 , sizeof ( md4 ) ) ;
2007-10-05 22:03:01 +04:00
ret = false ;
2006-08-11 17:13:03 +04:00
}
2006-09-11 08:18:16 +04:00
talloc_free ( md4blob . data ) ;
2006-08-11 17:13:03 +04:00
}
return ret ;
}